diff --git a/.github/workflows/claude-code-review.yml b/.github/workflows/claude-code-review.yml new file mode 100644 index 000000000..a4c8f6a89 --- /dev/null +++ b/.github/workflows/claude-code-review.yml @@ -0,0 +1,57 @@ +name: Claude Code Review + +on: + pull_request: + types: [opened, synchronize] + # Optional: Only run on specific file changes + # paths: + # - "src/**/*.ts" + # - "src/**/*.tsx" + # - "src/**/*.js" + # - "src/**/*.jsx" + +jobs: + claude-review: + # Optional: Filter by PR author + # if: | + # github.event.pull_request.user.login == 'external-contributor' || + # github.event.pull_request.user.login == 'new-developer' || + # github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' + + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: read + issues: read + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Run Claude Code Review + id: claude-review + uses: anthropics/claude-code-action@v1 + with: + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} + prompt: | + REPO: ${{ github.repository }} + PR NUMBER: ${{ github.event.pull_request.number }} + + Please review this pull request and provide feedback on: + - Code quality and best practices + - Potential bugs or issues + - Performance considerations + - Security concerns + - Test coverage + + Use the repository's CLAUDE.md for guidance on style and conventions. Be constructive and helpful in your feedback. + + Use `gh pr comment` with your Bash tool to leave your review as a comment on the PR. + + # See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md + # or https://code.claude.com/docs/en/cli-reference for available options + claude_args: '--allowed-tools "Bash(gh issue view:*),Bash(gh search:*),Bash(gh issue list:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*)"' + diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml new file mode 100644 index 000000000..79fe05647 --- /dev/null +++ b/.github/workflows/claude.yml @@ -0,0 +1,50 @@ +name: Claude Code + +on: + issue_comment: + types: [created] + pull_request_review_comment: + types: [created] + issues: + types: [opened, assigned] + pull_request_review: + types: [submitted] + +jobs: + claude: + if: | + (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) || + (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) || + (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) || + (github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude'))) + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: read + issues: read + id-token: write + actions: read # Required for Claude to read CI results on PRs + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Run Claude Code + id: claude + uses: anthropics/claude-code-action@v1 + with: + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} + + # This is an optional setting that allows Claude to read CI results on PRs + additional_permissions: | + actions: read + + # Optional: Give a custom prompt to Claude. If this is not specified, Claude will perform the instructions specified in the comment that tagged it. + # prompt: 'Update the pull request description to include a summary of changes.' + + # Optional: Add claude_args to customize behavior and configuration + # See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md + # or https://code.claude.com/docs/en/cli-reference for available options + # claude_args: '--allowed-tools Bash(gh pr:*)' + diff --git a/.release-please-manifest.json b/.release-please-manifest.json index c9ba66432..0746cbe20 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "2.11.1" + ".": "2.12.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index d60086d1e..a1e1ddf57 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 34 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic%2Fanthropic-2f35b2ff9174d526a6d35796d2703490bfa5692312af67cbdfa4500283dabe31.yml -openapi_spec_hash: dc52b25c487e97d355ef645644aa13e7 -config_hash: d23c4d678fcf7ff829a2891b3196edb6 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic%2Fanthropic-a49e89deec4e00d1da490808099d66e2001531b12d8666a7f5d0b496f760440d.yml +openapi_spec_hash: c93ef3808c58e233b01966ff154f31ce +config_hash: f7dc1cdbacd8d780699a470dbc7ff8f4 diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f1f86894..8be32a325 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,36 @@ # Changelog +## 2.12.0 (2026-01-09) + +Full Changelog: [v2.11.1...v2.12.0](https://github.com/anthropics/anthropic-sdk-java/compare/v2.11.1...v2.12.0) + +### Features + +* **api:** adds support for Claude Opus 4.5, Effort, Advance Tool Use Features, Autocompaction, and Computer Use v5 ([4689271](https://github.com/anthropics/anthropic-sdk-java/commit/4689271c4dba2de056356d314429af36b7ad7205)) +* **client:** add `HttpRequest#url()` method ([49afe52](https://github.com/anthropics/anthropic-sdk-java/commit/49afe52d1f478b167d343a94e703d75abc5e09ba)) +* **client:** allow configuring dispatcher executor service ([60554ea](https://github.com/anthropics/anthropic-sdk-java/commit/60554eafb104057399672deefe0bbdb9b82c64bb)) + + +### Bug Fixes + +* **client:** BetaMessageAccumulator crash on empty tool input ([e0fe678](https://github.com/anthropics/anthropic-sdk-java/commit/e0fe6788bd8a5529fdc493e73cbc532497622bc3)) +* **client:** cancel okhttp call when future cancelled ([b52f783](https://github.com/anthropics/anthropic-sdk-java/commit/b52f7831db730af1e398df4362b84002f82d025e)) +* **client:** implement visitToolSearchToolResult for Beta Accumulator ([41191ed](https://github.com/anthropics/anthropic-sdk-java/commit/41191edae162caaf9572c5d1d786160413bdc39c)) +* **client:** run linter ([73e141d](https://github.com/anthropics/anthropic-sdk-java/commit/73e141d1df0cd094f6544b2bd51d5fccf989f28a)) + + +### Chores + +* **ci:** add Claude Code GitHub Workflow ([4eec6e8](https://github.com/anthropics/anthropic-sdk-java/commit/4eec6e844e9914150462ccbe017be1f2acfcd34a)) +* fix merge conflict ([e307fa0](https://github.com/anthropics/anthropic-sdk-java/commit/e307fa0b01207b77210cfc1c6957ca8f4ffbfb5b)) +* fix test ([b612010](https://github.com/anthropics/anthropic-sdk-java/commit/b612010dd341f8f7ebcdf2cd719db9f45ef36841)) +* **internal:** use different example values for some enums ([5d45a2f](https://github.com/anthropics/anthropic-sdk-java/commit/5d45a2fbd45aa2fb6561063f80bc2ca984a76150)) + + +### Documentation + +* remove `$` for better copy-pasteabality ([b2315f9](https://github.com/anthropics/anthropic-sdk-java/commit/b2315f9d756ad473cd52c4daf52590341e9d3bce)) + ## 2.11.1 (2025-11-19) Full Changelog: [v2.11.0...v2.11.1](https://github.com/anthropics/anthropic-sdk-java/compare/v2.11.0...v2.11.1) diff --git a/README.md b/README.md index aefcd052b..13786ec83 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ -[![Maven Central](https://img.shields.io/maven-central/v/com.anthropic/anthropic-java)](https://central.sonatype.com/artifact/com.anthropic/anthropic-java/2.11.1) -[![javadoc](https://javadoc.io/badge2/com.anthropic/anthropic-java/2.11.1/javadoc.svg)](https://javadoc.io/doc/com.anthropic/anthropic-java/2.11.1) +[![Maven Central](https://img.shields.io/maven-central/v/com.anthropic/anthropic-java)](https://central.sonatype.com/artifact/com.anthropic/anthropic-java/2.12.0) +[![javadoc](https://javadoc.io/badge2/com.anthropic/anthropic-java/2.12.0/javadoc.svg)](https://javadoc.io/doc/com.anthropic/anthropic-java/2.12.0) @@ -11,7 +11,7 @@ The Anthropic Java SDK provides convenient access to the [Anthropic REST API](ht -The REST API documentation can be found on [docs.anthropic.com](https://docs.anthropic.com/claude/reference/). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.anthropic/anthropic-java/2.11.1). +The REST API documentation can be found on [docs.anthropic.com](https://docs.anthropic.com/claude/reference/). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.anthropic/anthropic-java/2.12.0). @@ -22,7 +22,7 @@ The REST API documentation can be found on [docs.anthropic.com](https://docs.ant ### Gradle ```kotlin -implementation("com.anthropic:anthropic-java:2.11.1") +implementation("com.anthropic:anthropic-java:2.12.0") ``` ### Maven @@ -31,7 +31,7 @@ implementation("com.anthropic:anthropic-java:2.11.1") com.anthropic anthropic-java - 2.11.1 + 2.12.0 ``` @@ -59,7 +59,7 @@ AnthropicClient client = AnthropicOkHttpClient.fromEnv(); MessageCreateParams params = MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, Claude") - .model(Model.CLAUDE_SONNET_4_20250514) + .model(Model.CLAUDE_SONNET_4_5_20250929) .build(); Message message = client.messages().create(params); ``` @@ -173,7 +173,7 @@ AnthropicClient client = AnthropicOkHttpClient.fromEnv(); MessageCreateParams params = MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, Claude") - .model(Model.CLAUDE_SONNET_4_20250514) + .model(Model.CLAUDE_SONNET_4_5_20250929) .build(); CompletableFuture message = client.async().messages().create(params); ``` @@ -195,7 +195,7 @@ AnthropicClientAsync client = AnthropicOkHttpClientAsync.fromEnv(); MessageCreateParams params = MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, Claude") - .model(Model.CLAUDE_SONNET_4_20250514) + .model(Model.CLAUDE_SONNET_4_5_20250929) .build(); CompletableFuture message = client.messages().create(params); ``` @@ -975,7 +975,7 @@ import com.anthropic.models.messages.Model; MessageCreateParams params = MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, Claude") - .model(Model.CLAUDE_SONNET_4_20250514) + .model(Model.CLAUDE_SONNET_4_5_20250929) .build(); HttpResponseFor message = client.messages().withRawResponse().create(params); @@ -1146,7 +1146,7 @@ requires the `anthropic-java-bedrock` library dependency. ### Gradle ```kotlin -implementation("com.anthropic:anthropic-java-bedrock:2.11.1") +implementation("com.anthropic:anthropic-java-bedrock:2.12.0") ``` ### Maven @@ -1155,7 +1155,7 @@ implementation("com.anthropic:anthropic-java-bedrock:2.11.1") com.anthropic anthropic-java-bedrock - 2.11.1 + 2.12.0 ``` @@ -1279,7 +1279,7 @@ This support requires the `anthropic-java-vertex` library dependency. ### Gradle ```kotlin -implementation("com.anthropic:anthropic-java-vertex:2.11.1") +implementation("com.anthropic:anthropic-java-vertex:2.12.0") ``` ### Maven @@ -1288,7 +1288,7 @@ implementation("com.anthropic:anthropic-java-vertex:2.11.1") com.anthropic anthropic-java-vertex - 2.11.1 + 2.12.0 ``` @@ -1360,13 +1360,13 @@ The SDK uses the standard [OkHttp logging interceptor](https://github.com/square Enable logging by setting the `ANTHROPIC_LOG` environment variable to `info`: ```sh -$ export ANTHROPIC_LOG=info +export ANTHROPIC_LOG=info ``` Or to `debug` for more verbose logging: ```sh -$ export ANTHROPIC_LOG=debug +export ANTHROPIC_LOG=debug ``` ## ProGuard and R8 @@ -1586,7 +1586,7 @@ import com.anthropic.models.messages.Model; MessageCreateParams params = MessageCreateParams.builder() .maxTokens(JsonValue.from(3.14)) .addUserMessage("Hello, Claude") - .model(Model.CLAUDE_SONNET_4_20250514) + .model(Model.CLAUDE_SONNET_4_5_20250929) .build(); ``` @@ -1640,7 +1640,7 @@ import com.anthropic.models.messages.Model; MessageCreateParams params = MessageCreateParams.builder() .addUserMessage("Hello, world") - .model(Model.CLAUDE_SONNET_4_20250514) + .model(Model.CLAUDE_SONNET_4_5_20250929) .maxTokens(JsonMissing.of()) .build(); ``` diff --git a/anthropic-java-client-okhttp/build.gradle.kts b/anthropic-java-client-okhttp/build.gradle.kts index b43c2e6e7..e5ba5c32a 100644 --- a/anthropic-java-client-okhttp/build.gradle.kts +++ b/anthropic-java-client-okhttp/build.gradle.kts @@ -11,4 +11,5 @@ dependencies { testImplementation(kotlin("test")) testImplementation("org.assertj:assertj-core:3.25.3") + testImplementation("com.github.tomakehurst:wiremock-jre8:2.35.2") } 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 74e5edd2e..1a1d903dc 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 @@ -20,6 +20,7 @@ import java.time.Clock import java.time.Duration import java.util.Optional import java.util.concurrent.Executor +import java.util.concurrent.ExecutorService import javax.net.ssl.HostnameVerifier import javax.net.ssl.SSLSocketFactory import javax.net.ssl.X509TrustManager @@ -48,6 +49,7 @@ class AnthropicOkHttpClient private constructor() { class Builder internal constructor() { private var clientOptions: ClientOptions.Builder = ClientOptions.builder() + private var dispatcherExecutorService: ExecutorService? = null private var proxy: Proxy? = null private var sslSocketFactory: SSLSocketFactory? = null private var trustManager: X509TrustManager? = null @@ -55,6 +57,25 @@ class AnthropicOkHttpClient private constructor() { private var backend: Backend? = null private var defaultBackendBuilder: AnthropicBackend.Builder? = null + /** + * The executor service to use for running HTTP requests. + * + * Defaults to OkHttp's + * [default executor service](https://github.com/square/okhttp/blob/ace792f443b2ffb17974f5c0d1cecdf589309f26/okhttp/src/commonJvmAndroid/kotlin/okhttp3/Dispatcher.kt#L98-L104). + * + * This class takes ownership of the executor service and shuts it down when closed. + */ + fun dispatcherExecutorService(dispatcherExecutorService: ExecutorService?) = apply { + this.dispatcherExecutorService = dispatcherExecutorService + } + + /** + * Alias for calling [Builder.dispatcherExecutorService] with + * `dispatcherExecutorService.orElse(null)`. + */ + fun dispatcherExecutorService(dispatcherExecutorService: Optional) = + dispatcherExecutorService(dispatcherExecutorService.getOrNull()) + fun proxy(proxy: Proxy?) = apply { this.proxy = proxy } /** Alias for calling [Builder.proxy] with `proxy.orElse(null)`. */ @@ -356,6 +377,7 @@ class AnthropicOkHttpClient private constructor() { OkHttpClient.builder() .timeout(clientOptions.timeout()) .proxy(proxy) + .dispatcherExecutorService(dispatcherExecutorService) .sslSocketFactory(sslSocketFactory) .trustManager(trustManager) .hostnameVerifier(hostnameVerifier) 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 2004460ff..cd9fd73d0 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 @@ -20,6 +20,7 @@ import java.time.Clock import java.time.Duration import java.util.Optional import java.util.concurrent.Executor +import java.util.concurrent.ExecutorService import javax.net.ssl.HostnameVerifier import javax.net.ssl.SSLSocketFactory import javax.net.ssl.X509TrustManager @@ -48,6 +49,7 @@ class AnthropicOkHttpClientAsync private constructor() { class Builder internal constructor() { private var clientOptions: ClientOptions.Builder = ClientOptions.builder() + private var dispatcherExecutorService: ExecutorService? = null private var proxy: Proxy? = null private var sslSocketFactory: SSLSocketFactory? = null private var trustManager: X509TrustManager? = null @@ -55,6 +57,25 @@ class AnthropicOkHttpClientAsync private constructor() { private var backend: Backend? = null private var defaultBackendBuilder: AnthropicBackend.Builder? = null + /** + * The executor service to use for running HTTP requests. + * + * Defaults to OkHttp's + * [default executor service](https://github.com/square/okhttp/blob/ace792f443b2ffb17974f5c0d1cecdf589309f26/okhttp/src/commonJvmAndroid/kotlin/okhttp3/Dispatcher.kt#L98-L104). + * + * This class takes ownership of the executor service and shuts it down when closed. + */ + fun dispatcherExecutorService(dispatcherExecutorService: ExecutorService?) = apply { + this.dispatcherExecutorService = dispatcherExecutorService + } + + /** + * Alias for calling [Builder.dispatcherExecutorService] with + * `dispatcherExecutorService.orElse(null)`. + */ + fun dispatcherExecutorService(dispatcherExecutorService: Optional) = + dispatcherExecutorService(dispatcherExecutorService.getOrNull()) + fun proxy(proxy: Proxy?) = apply { this.proxy = proxy } /** Alias for calling [Builder.proxy] with `proxy.orElse(null)`. */ @@ -356,6 +377,7 @@ class AnthropicOkHttpClientAsync private constructor() { OkHttpClient.builder() .timeout(clientOptions.timeout()) .proxy(proxy) + .dispatcherExecutorService(dispatcherExecutorService) .sslSocketFactory(sslSocketFactory) .trustManager(trustManager) .hostnameVerifier(hostnameVerifier) 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 691d367de..b2592f84d 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 @@ -15,12 +15,15 @@ import java.io.IOException import java.io.InputStream import java.net.Proxy import java.time.Duration +import java.util.concurrent.CancellationException import java.util.concurrent.CompletableFuture +import java.util.concurrent.ExecutorService import javax.net.ssl.HostnameVerifier import javax.net.ssl.SSLSocketFactory import javax.net.ssl.X509TrustManager import okhttp3.Call import okhttp3.Callback +import okhttp3.Dispatcher import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.MediaType import okhttp3.MediaType.Companion.toMediaType @@ -32,8 +35,10 @@ import okhttp3.logging.HttpLoggingInterceptor import okio.BufferedSink class OkHttpClient -private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val backend: Backend) : - HttpClient { +private constructor( + @JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClient, + private val backend: Backend, +) : HttpClient { override fun execute(request: HttpRequest, requestOptions: RequestOptions): HttpResponse { val preparedRequest = prepareRequest(request) @@ -55,20 +60,25 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val val preparedRequest = prepareRequest(request) val future = CompletableFuture() - preparedRequest.body?.run { future.whenComplete { _, _ -> close() } } - - newCall(preparedRequest, requestOptions) - .enqueue( - object : Callback { - override fun onResponse(call: Call, response: Response) { - future.complete(backend.prepareResponse(response.toResponse())) - } + val call = newCall(preparedRequest, requestOptions) + call.enqueue( + object : Callback { + override fun onResponse(call: Call, response: Response) { + future.complete(backend.prepareResponse(response.toResponse())) + } - override fun onFailure(call: Call, e: IOException) { - future.completeExceptionally(AnthropicIoException("Request failed", e)) - } + override fun onFailure(call: Call, e: IOException) { + future.completeExceptionally(AnthropicIoException("Request failed", e)) } - ) + } + ) + + future.whenComplete { _, e -> + if (e is CancellationException) { + call.cancel() + } + preparedRequest.body?.close() + } return future } @@ -214,6 +224,8 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val private var timeout: Timeout = Timeout.default() private var proxy: Proxy? = null private var backend: Backend? = null + + private var dispatcherExecutorService: ExecutorService? = null private var sslSocketFactory: SSLSocketFactory? = null private var trustManager: X509TrustManager? = null private var hostnameVerifier: HostnameVerifier? = null @@ -226,6 +238,10 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val fun backend(backend: Backend) = apply { this.backend = backend } + fun dispatcherExecutorService(dispatcherExecutorService: ExecutorService?) = apply { + this.dispatcherExecutorService = dispatcherExecutorService + } + fun sslSocketFactory(sslSocketFactory: SSLSocketFactory?) = apply { this.sslSocketFactory = sslSocketFactory } @@ -248,6 +264,8 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val .callTimeout(timeout.request()) .proxy(proxy) .apply { + dispatcherExecutorService?.let { dispatcher(Dispatcher(it)) } + val sslSocketFactory = sslSocketFactory val trustManager = trustManager if (sslSocketFactory != null && trustManager != null) { diff --git a/anthropic-java-client-okhttp/src/test/kotlin/com/anthropic/client/okhttp/OkHttpClientTest.kt b/anthropic-java-client-okhttp/src/test/kotlin/com/anthropic/client/okhttp/OkHttpClientTest.kt new file mode 100644 index 000000000..9ec156c2c --- /dev/null +++ b/anthropic-java-client-okhttp/src/test/kotlin/com/anthropic/client/okhttp/OkHttpClientTest.kt @@ -0,0 +1,51 @@ +package com.anthropic.client.okhttp + +import com.anthropic.backends.Backend +import com.anthropic.core.http.HttpMethod +import com.anthropic.core.http.HttpRequest +import com.github.tomakehurst.wiremock.client.WireMock.* +import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo +import com.github.tomakehurst.wiremock.junit5.WireMockTest +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.parallel.ResourceLock + +@WireMockTest +@ResourceLock("https://github.com/wiremock/wiremock/issues/169") +internal class OkHttpClientTest { + + private class TestBackend(private val baseUrl: String) : Backend { + override fun baseUrl(): String = baseUrl + + override fun close() {} + } + + private lateinit var baseUrl: String + private lateinit var httpClient: OkHttpClient + + @BeforeEach + fun beforeEach(wmRuntimeInfo: WireMockRuntimeInfo) { + baseUrl = wmRuntimeInfo.httpBaseUrl + httpClient = OkHttpClient.builder().backend(TestBackend(baseUrl)).build() + } + + @Test + fun executeAsync_whenFutureCancelled_cancelsUnderlyingCall() { + stubFor(post(urlPathEqualTo("/something")).willReturn(ok())) + val responseFuture = + httpClient.executeAsync( + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(baseUrl) + .addPathSegment("something") + .build() + ) + val call = httpClient.okHttpClient.dispatcher.runningCalls().single() + + responseFuture.cancel(false) + + // Should have cancelled the underlying call + assertThat(call.isCanceled()).isTrue() + } +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/core/http/HttpRequest.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/core/http/HttpRequest.kt index 9f983a4a1..8f9b61130 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/core/http/HttpRequest.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/core/http/HttpRequest.kt @@ -2,6 +2,7 @@ package com.anthropic.core.http import com.anthropic.core.checkRequired import com.anthropic.core.toImmutable +import java.net.URLEncoder import java.util.Optional import kotlin.jvm.optionals.getOrNull @@ -15,6 +16,35 @@ private constructor( @get:JvmName("body") val body: HttpRequestBody?, ) { + fun url(): String = buildString { + append(baseUrl) + + pathSegments.forEach { segment -> + if (!endsWith("/")) { + append("/") + } + append(URLEncoder.encode(segment, "UTF-8")) + } + + if (queryParams.isEmpty()) { + return@buildString + } + + append("?") + var isFirst = true + queryParams.keys().forEach { key -> + queryParams.values(key).forEach { value -> + if (!isFirst) { + append("&") + } + append(URLEncoder.encode(key, "UTF-8")) + append("=") + append(URLEncoder.encode(value, "UTF-8")) + isFirst = false + } + } + } + fun toBuilder(): Builder = Builder().from(this) override fun toString(): String = diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/helpers/BetaMessageAccumulator.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/helpers/BetaMessageAccumulator.kt index bcbfbfc80..b5d05cd10 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/helpers/BetaMessageAccumulator.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/helpers/BetaMessageAccumulator.kt @@ -1,5 +1,6 @@ package com.anthropic.helpers +import com.anthropic.core.JsonMissing import com.anthropic.core.JsonObject import com.anthropic.core.jsonMapper import com.anthropic.errors.AnthropicInvalidDataException @@ -329,6 +330,13 @@ class BetaMessageAccumulator private constructor() { ): BetaContentBlock = BetaContentBlock.ofWebFetchToolResult(webFetchToolResult) + override fun visitToolSearchToolResult( + toolSearchToolResult: BetaToolSearchToolResultBlock + ): BetaContentBlock = + BetaContentBlock.ofToolSearchToolResult( + toolSearchToolResult + ) + override fun visitCodeExecutionToolResult( codeExecutionToolResult: BetaCodeExecutionToolResultBlock ): BetaContentBlock = @@ -448,14 +456,20 @@ class BetaMessageAccumulator private constructor() { "Missing input JSON for index $index." ) + // Anthropic Streaming Messages API: "the final `tool_use.input` + // is always an _object_." However, if a tool function has no + // arguments, the concatenated `inputJson` can be an empty + // string. In that case, interpret it as a missing field. val parsedInput = - try { - JSON_MAPPER.readValue(inputJson, JsonObject::class.java) - } catch (e: Exception) { - throw AnthropicInvalidDataException( - "Unable to parse tool parameter JSON from model. Please retry your request or adjust your prompt. Error: ${e}. JSON: $inputJson" - ) - } + if (inputJson.trim() == "") JsonMissing.of() + else + try { + JSON_MAPPER.readValue(inputJson, JsonObject::class.java) + } catch (e: Exception) { + throw AnthropicInvalidDataException( + "Unable to parse tool parameter JSON from model. Please retry your request or adjust your prompt. Error: ${e}. JSON: $inputJson" + ) + } messageContent[index] = when { 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 d3b7eaad4..88fc191aa 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 @@ -40,6 +40,8 @@ class AnthropicBeta @JsonCreator private constructor(private val value: JsonFiel @JvmField val MCP_CLIENT_2025_04_04 = of("mcp-client-2025-04-04") + @JvmField val MCP_CLIENT_2025_11_20 = of("mcp-client-2025-11-20") + @JvmField val DEV_FULL_THINKING_2025_05_14 = of("dev-full-thinking-2025-05-14") @JvmField val INTERLEAVED_THINKING_2025_05_14 = of("interleaved-thinking-2025-05-14") @@ -73,6 +75,7 @@ class AnthropicBeta @JsonCreator private constructor(private val value: JsonFiel OUTPUT_128K_2025_02_19, FILES_API_2025_04_14, MCP_CLIENT_2025_04_04, + MCP_CLIENT_2025_11_20, DEV_FULL_THINKING_2025_05_14, INTERLEAVED_THINKING_2025_05_14, CODE_EXECUTION_2025_05_22, @@ -103,6 +106,7 @@ class AnthropicBeta @JsonCreator private constructor(private val value: JsonFiel OUTPUT_128K_2025_02_19, FILES_API_2025_04_14, MCP_CLIENT_2025_04_04, + MCP_CLIENT_2025_11_20, DEV_FULL_THINKING_2025_05_14, INTERLEAVED_THINKING_2025_05_14, CODE_EXECUTION_2025_05_22, @@ -136,6 +140,7 @@ class AnthropicBeta @JsonCreator private constructor(private val value: JsonFiel OUTPUT_128K_2025_02_19 -> Value.OUTPUT_128K_2025_02_19 FILES_API_2025_04_14 -> Value.FILES_API_2025_04_14 MCP_CLIENT_2025_04_04 -> Value.MCP_CLIENT_2025_04_04 + MCP_CLIENT_2025_11_20 -> Value.MCP_CLIENT_2025_11_20 DEV_FULL_THINKING_2025_05_14 -> Value.DEV_FULL_THINKING_2025_05_14 INTERLEAVED_THINKING_2025_05_14 -> Value.INTERLEAVED_THINKING_2025_05_14 CODE_EXECUTION_2025_05_22 -> Value.CODE_EXECUTION_2025_05_22 @@ -168,6 +173,7 @@ class AnthropicBeta @JsonCreator private constructor(private val value: JsonFiel OUTPUT_128K_2025_02_19 -> Known.OUTPUT_128K_2025_02_19 FILES_API_2025_04_14 -> Known.FILES_API_2025_04_14 MCP_CLIENT_2025_04_04 -> Known.MCP_CLIENT_2025_04_04 + MCP_CLIENT_2025_11_20 -> Known.MCP_CLIENT_2025_11_20 DEV_FULL_THINKING_2025_05_14 -> Known.DEV_FULL_THINKING_2025_05_14 INTERLEAVED_THINKING_2025_05_14 -> Known.INTERLEAVED_THINKING_2025_05_14 CODE_EXECUTION_2025_05_22 -> Known.CODE_EXECUTION_2025_05_22 diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaCodeExecutionTool20250522.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaCodeExecutionTool20250522.kt index 2f9d4ed2a..e77a51bac 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaCodeExecutionTool20250522.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaCodeExecutionTool20250522.kt @@ -2,10 +2,13 @@ package com.anthropic.models.beta.messages +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.toImmutable import com.anthropic.errors.AnthropicInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -21,7 +24,9 @@ class BetaCodeExecutionTool20250522 private constructor( private val name: JsonValue, private val type: JsonValue, + private val allowedCallers: JsonField>, private val cacheControl: JsonField, + private val deferLoading: JsonField, private val strict: JsonField, private val additionalProperties: MutableMap, ) { @@ -30,11 +35,17 @@ private constructor( private constructor( @JsonProperty("name") @ExcludeMissing name: JsonValue = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("allowed_callers") + @ExcludeMissing + allowedCallers: JsonField> = JsonMissing.of(), @JsonProperty("cache_control") @ExcludeMissing cacheControl: JsonField = JsonMissing.of(), + @JsonProperty("defer_loading") + @ExcludeMissing + deferLoading: JsonField = JsonMissing.of(), @JsonProperty("strict") @ExcludeMissing strict: JsonField = JsonMissing.of(), - ) : this(name, type, cacheControl, strict, mutableMapOf()) + ) : this(name, type, allowedCallers, cacheControl, deferLoading, strict, mutableMapOf()) /** * Name of the tool. @@ -62,6 +73,13 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun allowedCallers(): Optional> = + allowedCallers.getOptional("allowed_callers") + /** * Create a cache control breakpoint at this content block. * @@ -71,12 +89,30 @@ private constructor( fun cacheControl(): Optional = cacheControl.getOptional("cache_control") + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned via + * tool_reference from tool search. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun deferLoading(): Optional = deferLoading.getOptional("defer_loading") + /** * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ fun strict(): Optional = strict.getOptional("strict") + /** + * Returns the raw JSON value of [allowedCallers]. + * + * Unlike [allowedCallers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("allowed_callers") + @ExcludeMissing + fun _allowedCallers(): JsonField> = allowedCallers + /** * Returns the raw JSON value of [cacheControl]. * @@ -86,6 +122,15 @@ private constructor( @ExcludeMissing fun _cacheControl(): JsonField = cacheControl + /** + * Returns the raw JSON value of [deferLoading]. + * + * Unlike [deferLoading], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("defer_loading") + @ExcludeMissing + fun _deferLoading(): JsonField = deferLoading + /** * Returns the raw JSON value of [strict]. * @@ -119,7 +164,9 @@ private constructor( private var name: JsonValue = JsonValue.from("code_execution") private var type: JsonValue = JsonValue.from("code_execution_20250522") + private var allowedCallers: JsonField>? = null private var cacheControl: JsonField = JsonMissing.of() + private var deferLoading: JsonField = JsonMissing.of() private var strict: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -127,7 +174,9 @@ private constructor( internal fun from(betaCodeExecutionTool20250522: BetaCodeExecutionTool20250522) = apply { name = betaCodeExecutionTool20250522.name type = betaCodeExecutionTool20250522.type + allowedCallers = betaCodeExecutionTool20250522.allowedCallers.map { it.toMutableList() } cacheControl = betaCodeExecutionTool20250522.cacheControl + deferLoading = betaCodeExecutionTool20250522.deferLoading strict = betaCodeExecutionTool20250522.strict additionalProperties = betaCodeExecutionTool20250522.additionalProperties.toMutableMap() } @@ -160,6 +209,32 @@ private constructor( */ fun type(type: JsonValue) = apply { this.type = type } + fun allowedCallers(allowedCallers: List) = + allowedCallers(JsonField.of(allowedCallers)) + + /** + * Sets [Builder.allowedCallers] to an arbitrary JSON value. + * + * You should usually call [Builder.allowedCallers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun allowedCallers(allowedCallers: JsonField>) = apply { + this.allowedCallers = allowedCallers.map { it.toMutableList() } + } + + /** + * Adds a single [AllowedCaller] to [allowedCallers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAllowedCaller(allowedCaller: AllowedCaller) = apply { + allowedCallers = + (allowedCallers ?: JsonField.of(mutableListOf())).also { + checkKnown("allowedCallers", it).add(allowedCaller) + } + } + /** Create a cache control breakpoint at this content block. */ fun cacheControl(cacheControl: BetaCacheControlEphemeral?) = cacheControl(JsonField.ofNullable(cacheControl)) @@ -179,6 +254,23 @@ private constructor( this.cacheControl = cacheControl } + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned + * via tool_reference from tool search. + */ + fun deferLoading(deferLoading: Boolean) = deferLoading(JsonField.of(deferLoading)) + + /** + * Sets [Builder.deferLoading] to an arbitrary JSON value. + * + * You should usually call [Builder.deferLoading] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun deferLoading(deferLoading: JsonField) = apply { + this.deferLoading = deferLoading + } + fun strict(strict: Boolean) = strict(JsonField.of(strict)) /** @@ -217,7 +309,9 @@ private constructor( BetaCodeExecutionTool20250522( name, type, + (allowedCallers ?: JsonMissing.of()).map { it.toImmutable() }, cacheControl, + deferLoading, strict, additionalProperties.toMutableMap(), ) @@ -240,7 +334,9 @@ private constructor( throw AnthropicInvalidDataException("'type' is invalid, received $it") } } + allowedCallers().ifPresent { it.forEach { it.validate() } } cacheControl().ifPresent { it.validate() } + deferLoading() strict() validated = true } @@ -262,9 +358,142 @@ private constructor( internal fun validity(): Int = name.let { if (it == JsonValue.from("code_execution")) 1 else 0 } + type.let { if (it == JsonValue.from("code_execution_20250522")) 1 else 0 } + + (allowedCallers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (cacheControl.asKnown().getOrNull()?.validity() ?: 0) + + (if (deferLoading.asKnown().isPresent) 1 else 0) + (if (strict.asKnown().isPresent) 1 else 0) + class AllowedCaller @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 DIRECT = of("direct") + + @JvmField val CODE_EXECUTION_20250825 = of("code_execution_20250825") + + @JvmStatic fun of(value: String) = AllowedCaller(JsonField.of(value)) + } + + /** An enum containing [AllowedCaller]'s known values. */ + enum class Known { + DIRECT, + CODE_EXECUTION_20250825, + } + + /** + * An enum containing [AllowedCaller]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [AllowedCaller] 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 { + DIRECT, + CODE_EXECUTION_20250825, + /** + * An enum member indicating that [AllowedCaller] 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) { + DIRECT -> Value.DIRECT + CODE_EXECUTION_20250825 -> Value.CODE_EXECUTION_20250825 + 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) { + DIRECT -> Known.DIRECT + CODE_EXECUTION_20250825 -> Known.CODE_EXECUTION_20250825 + else -> throw AnthropicInvalidDataException("Unknown AllowedCaller: $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 + + fun validate(): AllowedCaller = 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 AllowedCaller && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -273,17 +502,27 @@ private constructor( return other is BetaCodeExecutionTool20250522 && name == other.name && type == other.type && + allowedCallers == other.allowedCallers && cacheControl == other.cacheControl && + deferLoading == other.deferLoading && strict == other.strict && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(name, type, cacheControl, strict, additionalProperties) + Objects.hash( + name, + type, + allowedCallers, + cacheControl, + deferLoading, + strict, + additionalProperties, + ) } override fun hashCode(): Int = hashCode override fun toString() = - "BetaCodeExecutionTool20250522{name=$name, type=$type, cacheControl=$cacheControl, strict=$strict, additionalProperties=$additionalProperties}" + "BetaCodeExecutionTool20250522{name=$name, type=$type, allowedCallers=$allowedCallers, cacheControl=$cacheControl, deferLoading=$deferLoading, strict=$strict, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaCodeExecutionTool20250825.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaCodeExecutionTool20250825.kt index d662caceb..ff9ab46b7 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaCodeExecutionTool20250825.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaCodeExecutionTool20250825.kt @@ -2,10 +2,13 @@ package com.anthropic.models.beta.messages +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.toImmutable import com.anthropic.errors.AnthropicInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -21,7 +24,9 @@ class BetaCodeExecutionTool20250825 private constructor( private val name: JsonValue, private val type: JsonValue, + private val allowedCallers: JsonField>, private val cacheControl: JsonField, + private val deferLoading: JsonField, private val strict: JsonField, private val additionalProperties: MutableMap, ) { @@ -30,11 +35,17 @@ private constructor( private constructor( @JsonProperty("name") @ExcludeMissing name: JsonValue = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("allowed_callers") + @ExcludeMissing + allowedCallers: JsonField> = JsonMissing.of(), @JsonProperty("cache_control") @ExcludeMissing cacheControl: JsonField = JsonMissing.of(), + @JsonProperty("defer_loading") + @ExcludeMissing + deferLoading: JsonField = JsonMissing.of(), @JsonProperty("strict") @ExcludeMissing strict: JsonField = JsonMissing.of(), - ) : this(name, type, cacheControl, strict, mutableMapOf()) + ) : this(name, type, allowedCallers, cacheControl, deferLoading, strict, mutableMapOf()) /** * Name of the tool. @@ -62,6 +73,13 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun allowedCallers(): Optional> = + allowedCallers.getOptional("allowed_callers") + /** * Create a cache control breakpoint at this content block. * @@ -71,12 +89,30 @@ private constructor( fun cacheControl(): Optional = cacheControl.getOptional("cache_control") + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned via + * tool_reference from tool search. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun deferLoading(): Optional = deferLoading.getOptional("defer_loading") + /** * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ fun strict(): Optional = strict.getOptional("strict") + /** + * Returns the raw JSON value of [allowedCallers]. + * + * Unlike [allowedCallers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("allowed_callers") + @ExcludeMissing + fun _allowedCallers(): JsonField> = allowedCallers + /** * Returns the raw JSON value of [cacheControl]. * @@ -86,6 +122,15 @@ private constructor( @ExcludeMissing fun _cacheControl(): JsonField = cacheControl + /** + * Returns the raw JSON value of [deferLoading]. + * + * Unlike [deferLoading], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("defer_loading") + @ExcludeMissing + fun _deferLoading(): JsonField = deferLoading + /** * Returns the raw JSON value of [strict]. * @@ -119,7 +164,9 @@ private constructor( private var name: JsonValue = JsonValue.from("code_execution") private var type: JsonValue = JsonValue.from("code_execution_20250825") + private var allowedCallers: JsonField>? = null private var cacheControl: JsonField = JsonMissing.of() + private var deferLoading: JsonField = JsonMissing.of() private var strict: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -127,7 +174,9 @@ private constructor( internal fun from(betaCodeExecutionTool20250825: BetaCodeExecutionTool20250825) = apply { name = betaCodeExecutionTool20250825.name type = betaCodeExecutionTool20250825.type + allowedCallers = betaCodeExecutionTool20250825.allowedCallers.map { it.toMutableList() } cacheControl = betaCodeExecutionTool20250825.cacheControl + deferLoading = betaCodeExecutionTool20250825.deferLoading strict = betaCodeExecutionTool20250825.strict additionalProperties = betaCodeExecutionTool20250825.additionalProperties.toMutableMap() } @@ -160,6 +209,32 @@ private constructor( */ fun type(type: JsonValue) = apply { this.type = type } + fun allowedCallers(allowedCallers: List) = + allowedCallers(JsonField.of(allowedCallers)) + + /** + * Sets [Builder.allowedCallers] to an arbitrary JSON value. + * + * You should usually call [Builder.allowedCallers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun allowedCallers(allowedCallers: JsonField>) = apply { + this.allowedCallers = allowedCallers.map { it.toMutableList() } + } + + /** + * Adds a single [AllowedCaller] to [allowedCallers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAllowedCaller(allowedCaller: AllowedCaller) = apply { + allowedCallers = + (allowedCallers ?: JsonField.of(mutableListOf())).also { + checkKnown("allowedCallers", it).add(allowedCaller) + } + } + /** Create a cache control breakpoint at this content block. */ fun cacheControl(cacheControl: BetaCacheControlEphemeral?) = cacheControl(JsonField.ofNullable(cacheControl)) @@ -179,6 +254,23 @@ private constructor( this.cacheControl = cacheControl } + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned + * via tool_reference from tool search. + */ + fun deferLoading(deferLoading: Boolean) = deferLoading(JsonField.of(deferLoading)) + + /** + * Sets [Builder.deferLoading] to an arbitrary JSON value. + * + * You should usually call [Builder.deferLoading] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun deferLoading(deferLoading: JsonField) = apply { + this.deferLoading = deferLoading + } + fun strict(strict: Boolean) = strict(JsonField.of(strict)) /** @@ -217,7 +309,9 @@ private constructor( BetaCodeExecutionTool20250825( name, type, + (allowedCallers ?: JsonMissing.of()).map { it.toImmutable() }, cacheControl, + deferLoading, strict, additionalProperties.toMutableMap(), ) @@ -240,7 +334,9 @@ private constructor( throw AnthropicInvalidDataException("'type' is invalid, received $it") } } + allowedCallers().ifPresent { it.forEach { it.validate() } } cacheControl().ifPresent { it.validate() } + deferLoading() strict() validated = true } @@ -262,9 +358,142 @@ private constructor( internal fun validity(): Int = name.let { if (it == JsonValue.from("code_execution")) 1 else 0 } + type.let { if (it == JsonValue.from("code_execution_20250825")) 1 else 0 } + + (allowedCallers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (cacheControl.asKnown().getOrNull()?.validity() ?: 0) + + (if (deferLoading.asKnown().isPresent) 1 else 0) + (if (strict.asKnown().isPresent) 1 else 0) + class AllowedCaller @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 DIRECT = of("direct") + + @JvmField val CODE_EXECUTION_20250825 = of("code_execution_20250825") + + @JvmStatic fun of(value: String) = AllowedCaller(JsonField.of(value)) + } + + /** An enum containing [AllowedCaller]'s known values. */ + enum class Known { + DIRECT, + CODE_EXECUTION_20250825, + } + + /** + * An enum containing [AllowedCaller]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [AllowedCaller] 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 { + DIRECT, + CODE_EXECUTION_20250825, + /** + * An enum member indicating that [AllowedCaller] 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) { + DIRECT -> Value.DIRECT + CODE_EXECUTION_20250825 -> Value.CODE_EXECUTION_20250825 + 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) { + DIRECT -> Known.DIRECT + CODE_EXECUTION_20250825 -> Known.CODE_EXECUTION_20250825 + else -> throw AnthropicInvalidDataException("Unknown AllowedCaller: $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 + + fun validate(): AllowedCaller = 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 AllowedCaller && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -273,17 +502,27 @@ private constructor( return other is BetaCodeExecutionTool20250825 && name == other.name && type == other.type && + allowedCallers == other.allowedCallers && cacheControl == other.cacheControl && + deferLoading == other.deferLoading && strict == other.strict && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(name, type, cacheControl, strict, additionalProperties) + Objects.hash( + name, + type, + allowedCallers, + cacheControl, + deferLoading, + strict, + additionalProperties, + ) } override fun hashCode(): Int = hashCode override fun toString() = - "BetaCodeExecutionTool20250825{name=$name, type=$type, cacheControl=$cacheControl, strict=$strict, additionalProperties=$additionalProperties}" + "BetaCodeExecutionTool20250825{name=$name, type=$type, allowedCallers=$allowedCallers, cacheControl=$cacheControl, deferLoading=$deferLoading, strict=$strict, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaContentBlock.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaContentBlock.kt index f14c8f5c0..dff951d15 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaContentBlock.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaContentBlock.kt @@ -34,6 +34,7 @@ private constructor( private val bashCodeExecutionToolResult: BetaBashCodeExecutionToolResultBlock? = null, private val textEditorCodeExecutionToolResult: BetaTextEditorCodeExecutionToolResultBlock? = null, + private val toolSearchToolResult: BetaToolSearchToolResultBlock? = null, private val mcpToolUse: BetaMcpToolUseBlock? = null, private val mcpToolResult: BetaMcpToolResultBlock? = null, private val containerUpload: BetaContainerUploadBlock? = null, @@ -93,6 +94,11 @@ private constructor( textEditorCodeExecutionToolResult.toParam() ) + override fun visitToolSearchToolResult( + toolSearchToolResult: BetaToolSearchToolResultBlock + ): BetaContentBlockParam = + BetaContentBlockParam.ofToolSearchToolResult(toolSearchToolResult.toParam()) + override fun visitMcpToolUse( mcpToolUse: BetaMcpToolUseBlock ): BetaContentBlockParam = BetaContentBlockParam.ofMcpToolUse(mcpToolUse.toParam()) @@ -135,6 +141,9 @@ private constructor( fun textEditorCodeExecutionToolResult(): Optional = Optional.ofNullable(textEditorCodeExecutionToolResult) + fun toolSearchToolResult(): Optional = + Optional.ofNullable(toolSearchToolResult) + fun mcpToolUse(): Optional = Optional.ofNullable(mcpToolUse) fun mcpToolResult(): Optional = Optional.ofNullable(mcpToolResult) @@ -162,6 +171,8 @@ private constructor( fun isTextEditorCodeExecutionToolResult(): Boolean = textEditorCodeExecutionToolResult != null + fun isToolSearchToolResult(): Boolean = toolSearchToolResult != null + fun isMcpToolUse(): Boolean = mcpToolUse != null fun isMcpToolResult(): Boolean = mcpToolResult != null @@ -194,6 +205,9 @@ private constructor( fun asTextEditorCodeExecutionToolResult(): BetaTextEditorCodeExecutionToolResultBlock = textEditorCodeExecutionToolResult.getOrThrow("textEditorCodeExecutionToolResult") + fun asToolSearchToolResult(): BetaToolSearchToolResultBlock = + toolSearchToolResult.getOrThrow("toolSearchToolResult") + fun asMcpToolUse(): BetaMcpToolUseBlock = mcpToolUse.getOrThrow("mcpToolUse") fun asMcpToolResult(): BetaMcpToolResultBlock = mcpToolResult.getOrThrow("mcpToolResult") @@ -219,6 +233,7 @@ private constructor( visitor.visitBashCodeExecutionToolResult(bashCodeExecutionToolResult) textEditorCodeExecutionToolResult != null -> visitor.visitTextEditorCodeExecutionToolResult(textEditorCodeExecutionToolResult) + toolSearchToolResult != null -> visitor.visitToolSearchToolResult(toolSearchToolResult) mcpToolUse != null -> visitor.visitMcpToolUse(mcpToolUse) mcpToolResult != null -> visitor.visitMcpToolResult(mcpToolResult) containerUpload != null -> visitor.visitContainerUpload(containerUpload) @@ -284,6 +299,12 @@ private constructor( textEditorCodeExecutionToolResult.validate() } + override fun visitToolSearchToolResult( + toolSearchToolResult: BetaToolSearchToolResultBlock + ) { + toolSearchToolResult.validate() + } + override fun visitMcpToolUse(mcpToolUse: BetaMcpToolUseBlock) { mcpToolUse.validate() } @@ -349,6 +370,10 @@ private constructor( textEditorCodeExecutionToolResult: BetaTextEditorCodeExecutionToolResultBlock ) = textEditorCodeExecutionToolResult.validity() + override fun visitToolSearchToolResult( + toolSearchToolResult: BetaToolSearchToolResultBlock + ) = toolSearchToolResult.validity() + override fun visitMcpToolUse(mcpToolUse: BetaMcpToolUseBlock) = mcpToolUse.validity() @@ -378,6 +403,7 @@ private constructor( codeExecutionToolResult == other.codeExecutionToolResult && bashCodeExecutionToolResult == other.bashCodeExecutionToolResult && textEditorCodeExecutionToolResult == other.textEditorCodeExecutionToolResult && + toolSearchToolResult == other.toolSearchToolResult && mcpToolUse == other.mcpToolUse && mcpToolResult == other.mcpToolResult && containerUpload == other.containerUpload @@ -395,6 +421,7 @@ private constructor( codeExecutionToolResult, bashCodeExecutionToolResult, textEditorCodeExecutionToolResult, + toolSearchToolResult, mcpToolUse, mcpToolResult, containerUpload, @@ -416,6 +443,8 @@ private constructor( "BetaContentBlock{bashCodeExecutionToolResult=$bashCodeExecutionToolResult}" textEditorCodeExecutionToolResult != null -> "BetaContentBlock{textEditorCodeExecutionToolResult=$textEditorCodeExecutionToolResult}" + toolSearchToolResult != null -> + "BetaContentBlock{toolSearchToolResult=$toolSearchToolResult}" mcpToolUse != null -> "BetaContentBlock{mcpToolUse=$mcpToolUse}" mcpToolResult != null -> "BetaContentBlock{mcpToolResult=$mcpToolResult}" containerUpload != null -> "BetaContentBlock{containerUpload=$containerUpload}" @@ -462,6 +491,10 @@ private constructor( textEditorCodeExecutionToolResult: BetaTextEditorCodeExecutionToolResultBlock ) = BetaContentBlock(textEditorCodeExecutionToolResult = textEditorCodeExecutionToolResult) + @JvmStatic + fun ofToolSearchToolResult(toolSearchToolResult: BetaToolSearchToolResultBlock) = + BetaContentBlock(toolSearchToolResult = toolSearchToolResult) + @JvmStatic fun ofMcpToolUse(mcpToolUse: BetaMcpToolUseBlock) = BetaContentBlock(mcpToolUse = mcpToolUse) @@ -508,6 +541,8 @@ private constructor( textEditorCodeExecutionToolResult: BetaTextEditorCodeExecutionToolResultBlock ): T + fun visitToolSearchToolResult(toolSearchToolResult: BetaToolSearchToolResultBlock): T + fun visitMcpToolUse(mcpToolUse: BetaMcpToolUseBlock): T fun visitMcpToolResult(mcpToolResult: BetaMcpToolResultBlock): T @@ -594,6 +629,11 @@ private constructor( BetaContentBlock(textEditorCodeExecutionToolResult = it, _json = json) } ?: BetaContentBlock(_json = json) } + "tool_search_tool_result" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { BetaContentBlock(toolSearchToolResult = it, _json = json) } + ?: BetaContentBlock(_json = json) + } "mcp_tool_use" -> { return tryDeserialize(node, jacksonTypeRef())?.let { BetaContentBlock(mcpToolUse = it, _json = json) @@ -637,6 +677,8 @@ private constructor( generator.writeObject(value.bashCodeExecutionToolResult) value.textEditorCodeExecutionToolResult != null -> generator.writeObject(value.textEditorCodeExecutionToolResult) + value.toolSearchToolResult != null -> + generator.writeObject(value.toolSearchToolResult) value.mcpToolUse != null -> generator.writeObject(value.mcpToolUse) value.mcpToolResult != null -> generator.writeObject(value.mcpToolResult) value.containerUpload != null -> generator.writeObject(value.containerUpload) diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaContentBlockParam.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaContentBlockParam.kt index 300e97a54..451b6e60a 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaContentBlockParam.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaContentBlockParam.kt @@ -39,6 +39,7 @@ private constructor( private val textEditorCodeExecutionToolResult: BetaTextEditorCodeExecutionToolResultBlockParam? = null, + private val toolSearchToolResult: BetaToolSearchToolResultBlockParam? = null, private val mcpToolUse: BetaMcpToolUseBlockParam? = null, private val mcpToolResult: BetaRequestMcpToolResultBlockParam? = null, private val containerUpload: BetaContainerUploadBlockParam? = null, @@ -91,6 +92,9 @@ private constructor( Optional = Optional.ofNullable(textEditorCodeExecutionToolResult) + fun toolSearchToolResult(): Optional = + Optional.ofNullable(toolSearchToolResult) + fun mcpToolUse(): Optional = Optional.ofNullable(mcpToolUse) fun mcpToolResult(): Optional = @@ -131,6 +135,8 @@ private constructor( fun isTextEditorCodeExecutionToolResult(): Boolean = textEditorCodeExecutionToolResult != null + fun isToolSearchToolResult(): Boolean = toolSearchToolResult != null + fun isMcpToolUse(): Boolean = mcpToolUse != null fun isMcpToolResult(): Boolean = mcpToolResult != null @@ -182,6 +188,9 @@ private constructor( fun asTextEditorCodeExecutionToolResult(): BetaTextEditorCodeExecutionToolResultBlockParam = textEditorCodeExecutionToolResult.getOrThrow("textEditorCodeExecutionToolResult") + fun asToolSearchToolResult(): BetaToolSearchToolResultBlockParam = + toolSearchToolResult.getOrThrow("toolSearchToolResult") + fun asMcpToolUse(): BetaMcpToolUseBlockParam = mcpToolUse.getOrThrow("mcpToolUse") fun asMcpToolResult(): BetaRequestMcpToolResultBlockParam = @@ -215,6 +224,7 @@ private constructor( visitor.visitBashCodeExecutionToolResult(bashCodeExecutionToolResult) textEditorCodeExecutionToolResult != null -> visitor.visitTextEditorCodeExecutionToolResult(textEditorCodeExecutionToolResult) + toolSearchToolResult != null -> visitor.visitToolSearchToolResult(toolSearchToolResult) mcpToolUse != null -> visitor.visitMcpToolUse(mcpToolUse) mcpToolResult != null -> visitor.visitMcpToolResult(mcpToolResult) containerUpload != null -> visitor.visitContainerUpload(containerUpload) @@ -299,6 +309,12 @@ private constructor( textEditorCodeExecutionToolResult.validate() } + override fun visitToolSearchToolResult( + toolSearchToolResult: BetaToolSearchToolResultBlockParam + ) { + toolSearchToolResult.validate() + } + override fun visitMcpToolUse(mcpToolUse: BetaMcpToolUseBlockParam) { mcpToolUse.validate() } @@ -376,6 +392,10 @@ private constructor( BetaTextEditorCodeExecutionToolResultBlockParam ) = textEditorCodeExecutionToolResult.validity() + override fun visitToolSearchToolResult( + toolSearchToolResult: BetaToolSearchToolResultBlockParam + ) = toolSearchToolResult.validity() + override fun visitMcpToolUse(mcpToolUse: BetaMcpToolUseBlockParam) = mcpToolUse.validity() @@ -409,6 +429,7 @@ private constructor( codeExecutionToolResult == other.codeExecutionToolResult && bashCodeExecutionToolResult == other.bashCodeExecutionToolResult && textEditorCodeExecutionToolResult == other.textEditorCodeExecutionToolResult && + toolSearchToolResult == other.toolSearchToolResult && mcpToolUse == other.mcpToolUse && mcpToolResult == other.mcpToolResult && containerUpload == other.containerUpload @@ -430,6 +451,7 @@ private constructor( codeExecutionToolResult, bashCodeExecutionToolResult, textEditorCodeExecutionToolResult, + toolSearchToolResult, mcpToolUse, mcpToolResult, containerUpload, @@ -456,6 +478,8 @@ private constructor( "BetaContentBlockParam{bashCodeExecutionToolResult=$bashCodeExecutionToolResult}" textEditorCodeExecutionToolResult != null -> "BetaContentBlockParam{textEditorCodeExecutionToolResult=$textEditorCodeExecutionToolResult}" + toolSearchToolResult != null -> + "BetaContentBlockParam{toolSearchToolResult=$toolSearchToolResult}" mcpToolUse != null -> "BetaContentBlockParam{mcpToolUse=$mcpToolUse}" mcpToolResult != null -> "BetaContentBlockParam{mcpToolResult=$mcpToolResult}" containerUpload != null -> "BetaContentBlockParam{containerUpload=$containerUpload}" @@ -533,6 +557,10 @@ private constructor( textEditorCodeExecutionToolResult = textEditorCodeExecutionToolResult ) + @JvmStatic + fun ofToolSearchToolResult(toolSearchToolResult: BetaToolSearchToolResultBlockParam) = + BetaContentBlockParam(toolSearchToolResult = toolSearchToolResult) + @JvmStatic fun ofMcpToolUse(mcpToolUse: BetaMcpToolUseBlockParam) = BetaContentBlockParam(mcpToolUse = mcpToolUse) @@ -601,6 +629,8 @@ private constructor( textEditorCodeExecutionToolResult: BetaTextEditorCodeExecutionToolResultBlockParam ): T + fun visitToolSearchToolResult(toolSearchToolResult: BetaToolSearchToolResultBlockParam): T + fun visitMcpToolUse(mcpToolUse: BetaMcpToolUseBlockParam): T fun visitMcpToolResult(mcpToolResult: BetaRequestMcpToolResultBlockParam): T @@ -718,6 +748,14 @@ private constructor( ) } ?: BetaContentBlockParam(_json = json) } + "tool_search_tool_result" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { BetaContentBlockParam(toolSearchToolResult = it, _json = json) } + ?: BetaContentBlockParam(_json = json) + } "mcp_tool_use" -> { return tryDeserialize(node, jacksonTypeRef())?.let { BetaContentBlockParam(mcpToolUse = it, _json = json) @@ -769,6 +807,8 @@ private constructor( generator.writeObject(value.bashCodeExecutionToolResult) value.textEditorCodeExecutionToolResult != null -> generator.writeObject(value.textEditorCodeExecutionToolResult) + value.toolSearchToolResult != null -> + generator.writeObject(value.toolSearchToolResult) value.mcpToolUse != null -> generator.writeObject(value.mcpToolUse) value.mcpToolResult != null -> generator.writeObject(value.mcpToolResult) value.containerUpload != null -> generator.writeObject(value.containerUpload) diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaDirectCaller.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaDirectCaller.kt new file mode 100644 index 000000000..b7e14a681 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaDirectCaller.kt @@ -0,0 +1,158 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +import com.anthropic.core.ExcludeMissing +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 + +/** Tool invocation directly from the model. */ +class BetaDirectCaller +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val type: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of() + ) : this(type, mutableMapOf()) + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("direct") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [BetaDirectCaller]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaDirectCaller]. */ + class Builder internal constructor() { + + private var type: JsonValue = JsonValue.from("direct") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaDirectCaller: BetaDirectCaller) = apply { + type = betaDirectCaller.type + additionalProperties = betaDirectCaller.additionalProperties.toMutableMap() + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("direct") + * ``` + * + * 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 [BetaDirectCaller]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): BetaDirectCaller = BetaDirectCaller(type, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): BetaDirectCaller = apply { + if (validated) { + return@apply + } + + _type().let { + if (it != JsonValue.from("direct")) { + 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 = type.let { if (it == JsonValue.from("direct")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaDirectCaller && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaDirectCaller{type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaMcpToolConfig.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaMcpToolConfig.kt new file mode 100644 index 000000000..7bf14a5c3 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaMcpToolConfig.kt @@ -0,0 +1,193 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 + +/** Configuration for a specific tool in an MCP toolset. */ +class BetaMcpToolConfig +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val deferLoading: JsonField, + private val enabled: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("defer_loading") + @ExcludeMissing + deferLoading: JsonField = JsonMissing.of(), + @JsonProperty("enabled") @ExcludeMissing enabled: JsonField = JsonMissing.of(), + ) : this(deferLoading, enabled, mutableMapOf()) + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun deferLoading(): Optional = deferLoading.getOptional("defer_loading") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun enabled(): Optional = enabled.getOptional("enabled") + + /** + * Returns the raw JSON value of [deferLoading]. + * + * Unlike [deferLoading], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("defer_loading") + @ExcludeMissing + fun _deferLoading(): JsonField = deferLoading + + /** + * Returns the raw JSON value of [enabled]. + * + * Unlike [enabled], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("enabled") @ExcludeMissing fun _enabled(): JsonField = enabled + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [BetaMcpToolConfig]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaMcpToolConfig]. */ + class Builder internal constructor() { + + private var deferLoading: JsonField = JsonMissing.of() + private var enabled: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaMcpToolConfig: BetaMcpToolConfig) = apply { + deferLoading = betaMcpToolConfig.deferLoading + enabled = betaMcpToolConfig.enabled + additionalProperties = betaMcpToolConfig.additionalProperties.toMutableMap() + } + + fun deferLoading(deferLoading: Boolean) = deferLoading(JsonField.of(deferLoading)) + + /** + * Sets [Builder.deferLoading] to an arbitrary JSON value. + * + * You should usually call [Builder.deferLoading] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun deferLoading(deferLoading: JsonField) = apply { + this.deferLoading = deferLoading + } + + fun enabled(enabled: Boolean) = enabled(JsonField.of(enabled)) + + /** + * Sets [Builder.enabled] to an arbitrary JSON value. + * + * You should usually call [Builder.enabled] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun enabled(enabled: JsonField) = apply { this.enabled = enabled } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [BetaMcpToolConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): BetaMcpToolConfig = + BetaMcpToolConfig(deferLoading, enabled, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): BetaMcpToolConfig = apply { + if (validated) { + return@apply + } + + deferLoading() + enabled() + 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 (deferLoading.asKnown().isPresent) 1 else 0) + + (if (enabled.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaMcpToolConfig && + deferLoading == other.deferLoading && + enabled == other.enabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(deferLoading, enabled, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaMcpToolConfig{deferLoading=$deferLoading, enabled=$enabled, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaMcpToolDefaultConfig.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaMcpToolDefaultConfig.kt new file mode 100644 index 000000000..1157f8808 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaMcpToolDefaultConfig.kt @@ -0,0 +1,193 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 + +/** Default configuration for tools in an MCP toolset. */ +class BetaMcpToolDefaultConfig +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val deferLoading: JsonField, + private val enabled: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("defer_loading") + @ExcludeMissing + deferLoading: JsonField = JsonMissing.of(), + @JsonProperty("enabled") @ExcludeMissing enabled: JsonField = JsonMissing.of(), + ) : this(deferLoading, enabled, mutableMapOf()) + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun deferLoading(): Optional = deferLoading.getOptional("defer_loading") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun enabled(): Optional = enabled.getOptional("enabled") + + /** + * Returns the raw JSON value of [deferLoading]. + * + * Unlike [deferLoading], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("defer_loading") + @ExcludeMissing + fun _deferLoading(): JsonField = deferLoading + + /** + * Returns the raw JSON value of [enabled]. + * + * Unlike [enabled], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("enabled") @ExcludeMissing fun _enabled(): JsonField = enabled + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [BetaMcpToolDefaultConfig]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaMcpToolDefaultConfig]. */ + class Builder internal constructor() { + + private var deferLoading: JsonField = JsonMissing.of() + private var enabled: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaMcpToolDefaultConfig: BetaMcpToolDefaultConfig) = apply { + deferLoading = betaMcpToolDefaultConfig.deferLoading + enabled = betaMcpToolDefaultConfig.enabled + additionalProperties = betaMcpToolDefaultConfig.additionalProperties.toMutableMap() + } + + fun deferLoading(deferLoading: Boolean) = deferLoading(JsonField.of(deferLoading)) + + /** + * Sets [Builder.deferLoading] to an arbitrary JSON value. + * + * You should usually call [Builder.deferLoading] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun deferLoading(deferLoading: JsonField) = apply { + this.deferLoading = deferLoading + } + + fun enabled(enabled: Boolean) = enabled(JsonField.of(enabled)) + + /** + * Sets [Builder.enabled] to an arbitrary JSON value. + * + * You should usually call [Builder.enabled] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun enabled(enabled: JsonField) = apply { this.enabled = enabled } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [BetaMcpToolDefaultConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): BetaMcpToolDefaultConfig = + BetaMcpToolDefaultConfig(deferLoading, enabled, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): BetaMcpToolDefaultConfig = apply { + if (validated) { + return@apply + } + + deferLoading() + enabled() + 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 (deferLoading.asKnown().isPresent) 1 else 0) + + (if (enabled.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaMcpToolDefaultConfig && + deferLoading == other.deferLoading && + enabled == other.enabled && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(deferLoading, enabled, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaMcpToolDefaultConfig{deferLoading=$deferLoading, enabled=$enabled, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaMcpToolset.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaMcpToolset.kt new file mode 100644 index 000000000..725aef43d --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaMcpToolset.kt @@ -0,0 +1,464 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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.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 + +/** + * Configuration for a group of tools from an MCP server. + * + * Allows configuring enabled status and defer_loading for all tools from an MCP server, with + * optional per-tool overrides. + */ +class BetaMcpToolset +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val mcpServerName: JsonField, + private val type: JsonValue, + private val cacheControl: JsonField, + private val configs: JsonField, + private val defaultConfig: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("mcp_server_name") + @ExcludeMissing + mcpServerName: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("cache_control") + @ExcludeMissing + cacheControl: JsonField = JsonMissing.of(), + @JsonProperty("configs") @ExcludeMissing configs: JsonField = JsonMissing.of(), + @JsonProperty("default_config") + @ExcludeMissing + defaultConfig: JsonField = JsonMissing.of(), + ) : this(mcpServerName, type, cacheControl, configs, defaultConfig, mutableMapOf()) + + /** + * Name of the MCP server to configure tools for + * + * @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 mcpServerName(): String = mcpServerName.getRequired("mcp_server_name") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("mcp_toolset") + * ``` + * + * 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 + + /** + * Create a cache control breakpoint at this content block. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun cacheControl(): Optional = + cacheControl.getOptional("cache_control") + + /** + * Configuration overrides for specific tools, keyed by tool name + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun configs(): Optional = configs.getOptional("configs") + + /** + * Default configuration applied to all tools from this server + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun defaultConfig(): Optional = + defaultConfig.getOptional("default_config") + + /** + * Returns the raw JSON value of [mcpServerName]. + * + * Unlike [mcpServerName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("mcp_server_name") + @ExcludeMissing + fun _mcpServerName(): JsonField = mcpServerName + + /** + * Returns the raw JSON value of [cacheControl]. + * + * Unlike [cacheControl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("cache_control") + @ExcludeMissing + fun _cacheControl(): JsonField = cacheControl + + /** + * Returns the raw JSON value of [configs]. + * + * Unlike [configs], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("configs") @ExcludeMissing fun _configs(): JsonField = configs + + /** + * Returns the raw JSON value of [defaultConfig]. + * + * Unlike [defaultConfig], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("default_config") + @ExcludeMissing + fun _defaultConfig(): JsonField = defaultConfig + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [BetaMcpToolset]. + * + * The following fields are required: + * ```java + * .mcpServerName() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaMcpToolset]. */ + class Builder internal constructor() { + + private var mcpServerName: JsonField? = null + private var type: JsonValue = JsonValue.from("mcp_toolset") + private var cacheControl: JsonField = JsonMissing.of() + private var configs: JsonField = JsonMissing.of() + private var defaultConfig: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaMcpToolset: BetaMcpToolset) = apply { + mcpServerName = betaMcpToolset.mcpServerName + type = betaMcpToolset.type + cacheControl = betaMcpToolset.cacheControl + configs = betaMcpToolset.configs + defaultConfig = betaMcpToolset.defaultConfig + additionalProperties = betaMcpToolset.additionalProperties.toMutableMap() + } + + /** Name of the MCP server to configure tools for */ + fun mcpServerName(mcpServerName: String) = mcpServerName(JsonField.of(mcpServerName)) + + /** + * Sets [Builder.mcpServerName] to an arbitrary JSON value. + * + * You should usually call [Builder.mcpServerName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun mcpServerName(mcpServerName: JsonField) = apply { + this.mcpServerName = mcpServerName + } + + /** + * 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("mcp_toolset") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** Create a cache control breakpoint at this content block. */ + fun cacheControl(cacheControl: BetaCacheControlEphemeral?) = + cacheControl(JsonField.ofNullable(cacheControl)) + + /** Alias for calling [Builder.cacheControl] with `cacheControl.orElse(null)`. */ + fun cacheControl(cacheControl: Optional) = + cacheControl(cacheControl.getOrNull()) + + /** + * Sets [Builder.cacheControl] to an arbitrary JSON value. + * + * You should usually call [Builder.cacheControl] with a well-typed + * [BetaCacheControlEphemeral] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun cacheControl(cacheControl: JsonField) = apply { + this.cacheControl = cacheControl + } + + /** Configuration overrides for specific tools, keyed by tool name */ + fun configs(configs: Configs?) = configs(JsonField.ofNullable(configs)) + + /** Alias for calling [Builder.configs] with `configs.orElse(null)`. */ + fun configs(configs: Optional) = configs(configs.getOrNull()) + + /** + * Sets [Builder.configs] to an arbitrary JSON value. + * + * You should usually call [Builder.configs] with a well-typed [Configs] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun configs(configs: JsonField) = apply { this.configs = configs } + + /** Default configuration applied to all tools from this server */ + fun defaultConfig(defaultConfig: BetaMcpToolDefaultConfig) = + defaultConfig(JsonField.of(defaultConfig)) + + /** + * Sets [Builder.defaultConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.defaultConfig] with a well-typed + * [BetaMcpToolDefaultConfig] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun defaultConfig(defaultConfig: JsonField) = apply { + this.defaultConfig = defaultConfig + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [BetaMcpToolset]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .mcpServerName() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaMcpToolset = + BetaMcpToolset( + checkRequired("mcpServerName", mcpServerName), + type, + cacheControl, + configs, + defaultConfig, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BetaMcpToolset = apply { + if (validated) { + return@apply + } + + mcpServerName() + _type().let { + if (it != JsonValue.from("mcp_toolset")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + cacheControl().ifPresent { it.validate() } + configs().ifPresent { it.validate() } + defaultConfig().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 (mcpServerName.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("mcp_toolset")) 1 else 0 } + + (cacheControl.asKnown().getOrNull()?.validity() ?: 0) + + (configs.asKnown().getOrNull()?.validity() ?: 0) + + (defaultConfig.asKnown().getOrNull()?.validity() ?: 0) + + /** Configuration overrides for specific tools, keyed by tool name */ + class Configs + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Configs]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Configs]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(configs: Configs) = apply { + additionalProperties = configs.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Configs]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Configs = Configs(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Configs = apply { + if (validated) { + return@apply + } + + 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 = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Configs && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Configs{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaMcpToolset && + mcpServerName == other.mcpServerName && + type == other.type && + cacheControl == other.cacheControl && + configs == other.configs && + defaultConfig == other.defaultConfig && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + mcpServerName, + type, + cacheControl, + configs, + defaultConfig, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaMcpToolset{mcpServerName=$mcpServerName, type=$type, cacheControl=$cacheControl, configs=$configs, defaultConfig=$defaultConfig, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaMemoryTool20250818.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaMemoryTool20250818.kt index 9ebe66c86..952d2eb5f 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaMemoryTool20250818.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaMemoryTool20250818.kt @@ -2,10 +2,13 @@ package com.anthropic.models.beta.messages +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.toImmutable import com.anthropic.errors.AnthropicInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -21,7 +24,10 @@ class BetaMemoryTool20250818 private constructor( private val name: JsonValue, private val type: JsonValue, + private val allowedCallers: JsonField>, private val cacheControl: JsonField, + private val deferLoading: JsonField, + private val inputExamples: JsonField>, private val strict: JsonField, private val additionalProperties: MutableMap, ) { @@ -30,11 +36,29 @@ private constructor( private constructor( @JsonProperty("name") @ExcludeMissing name: JsonValue = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("allowed_callers") + @ExcludeMissing + allowedCallers: JsonField> = JsonMissing.of(), @JsonProperty("cache_control") @ExcludeMissing cacheControl: JsonField = JsonMissing.of(), + @JsonProperty("defer_loading") + @ExcludeMissing + deferLoading: JsonField = JsonMissing.of(), + @JsonProperty("input_examples") + @ExcludeMissing + inputExamples: JsonField> = JsonMissing.of(), @JsonProperty("strict") @ExcludeMissing strict: JsonField = JsonMissing.of(), - ) : this(name, type, cacheControl, strict, mutableMapOf()) + ) : this( + name, + type, + allowedCallers, + cacheControl, + deferLoading, + inputExamples, + strict, + mutableMapOf(), + ) /** * Name of the tool. @@ -62,6 +86,13 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun allowedCallers(): Optional> = + allowedCallers.getOptional("allowed_callers") + /** * Create a cache control breakpoint at this content block. * @@ -71,12 +102,36 @@ private constructor( fun cacheControl(): Optional = cacheControl.getOptional("cache_control") + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned via + * tool_reference from tool search. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun deferLoading(): Optional = deferLoading.getOptional("defer_loading") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun inputExamples(): Optional> = inputExamples.getOptional("input_examples") + /** * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ fun strict(): Optional = strict.getOptional("strict") + /** + * Returns the raw JSON value of [allowedCallers]. + * + * Unlike [allowedCallers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("allowed_callers") + @ExcludeMissing + fun _allowedCallers(): JsonField> = allowedCallers + /** * Returns the raw JSON value of [cacheControl]. * @@ -86,6 +141,24 @@ private constructor( @ExcludeMissing fun _cacheControl(): JsonField = cacheControl + /** + * Returns the raw JSON value of [deferLoading]. + * + * Unlike [deferLoading], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("defer_loading") + @ExcludeMissing + fun _deferLoading(): JsonField = deferLoading + + /** + * Returns the raw JSON value of [inputExamples]. + * + * Unlike [inputExamples], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("input_examples") + @ExcludeMissing + fun _inputExamples(): JsonField> = inputExamples + /** * Returns the raw JSON value of [strict]. * @@ -116,7 +189,10 @@ private constructor( private var name: JsonValue = JsonValue.from("memory") private var type: JsonValue = JsonValue.from("memory_20250818") + private var allowedCallers: JsonField>? = null private var cacheControl: JsonField = JsonMissing.of() + private var deferLoading: JsonField = JsonMissing.of() + private var inputExamples: JsonField>? = null private var strict: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -124,7 +200,10 @@ private constructor( internal fun from(betaMemoryTool20250818: BetaMemoryTool20250818) = apply { name = betaMemoryTool20250818.name type = betaMemoryTool20250818.type + allowedCallers = betaMemoryTool20250818.allowedCallers.map { it.toMutableList() } cacheControl = betaMemoryTool20250818.cacheControl + deferLoading = betaMemoryTool20250818.deferLoading + inputExamples = betaMemoryTool20250818.inputExamples.map { it.toMutableList() } strict = betaMemoryTool20250818.strict additionalProperties = betaMemoryTool20250818.additionalProperties.toMutableMap() } @@ -157,6 +236,32 @@ private constructor( */ fun type(type: JsonValue) = apply { this.type = type } + fun allowedCallers(allowedCallers: List) = + allowedCallers(JsonField.of(allowedCallers)) + + /** + * Sets [Builder.allowedCallers] to an arbitrary JSON value. + * + * You should usually call [Builder.allowedCallers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun allowedCallers(allowedCallers: JsonField>) = apply { + this.allowedCallers = allowedCallers.map { it.toMutableList() } + } + + /** + * Adds a single [AllowedCaller] to [allowedCallers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAllowedCaller(allowedCaller: AllowedCaller) = apply { + allowedCallers = + (allowedCallers ?: JsonField.of(mutableListOf())).also { + checkKnown("allowedCallers", it).add(allowedCaller) + } + } + /** Create a cache control breakpoint at this content block. */ fun cacheControl(cacheControl: BetaCacheControlEphemeral?) = cacheControl(JsonField.ofNullable(cacheControl)) @@ -176,6 +281,49 @@ private constructor( this.cacheControl = cacheControl } + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned + * via tool_reference from tool search. + */ + fun deferLoading(deferLoading: Boolean) = deferLoading(JsonField.of(deferLoading)) + + /** + * Sets [Builder.deferLoading] to an arbitrary JSON value. + * + * You should usually call [Builder.deferLoading] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun deferLoading(deferLoading: JsonField) = apply { + this.deferLoading = deferLoading + } + + fun inputExamples(inputExamples: List) = + inputExamples(JsonField.of(inputExamples)) + + /** + * Sets [Builder.inputExamples] to an arbitrary JSON value. + * + * You should usually call [Builder.inputExamples] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun inputExamples(inputExamples: JsonField>) = apply { + this.inputExamples = inputExamples.map { it.toMutableList() } + } + + /** + * Adds a single [InputExample] to [inputExamples]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addInputExample(inputExample: InputExample) = apply { + inputExamples = + (inputExamples ?: JsonField.of(mutableListOf())).also { + checkKnown("inputExamples", it).add(inputExample) + } + } + fun strict(strict: Boolean) = strict(JsonField.of(strict)) /** @@ -214,7 +362,10 @@ private constructor( BetaMemoryTool20250818( name, type, + (allowedCallers ?: JsonMissing.of()).map { it.toImmutable() }, cacheControl, + deferLoading, + (inputExamples ?: JsonMissing.of()).map { it.toImmutable() }, strict, additionalProperties.toMutableMap(), ) @@ -237,7 +388,10 @@ private constructor( throw AnthropicInvalidDataException("'type' is invalid, received $it") } } + allowedCallers().ifPresent { it.forEach { it.validate() } } cacheControl().ifPresent { it.validate() } + deferLoading() + inputExamples().ifPresent { it.forEach { it.validate() } } strict() validated = true } @@ -259,9 +413,242 @@ private constructor( internal fun validity(): Int = name.let { if (it == JsonValue.from("memory")) 1 else 0 } + type.let { if (it == JsonValue.from("memory_20250818")) 1 else 0 } + + (allowedCallers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (cacheControl.asKnown().getOrNull()?.validity() ?: 0) + + (if (deferLoading.asKnown().isPresent) 1 else 0) + + (inputExamples.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (strict.asKnown().isPresent) 1 else 0) + class AllowedCaller @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 DIRECT = of("direct") + + @JvmField val CODE_EXECUTION_20250825 = of("code_execution_20250825") + + @JvmStatic fun of(value: String) = AllowedCaller(JsonField.of(value)) + } + + /** An enum containing [AllowedCaller]'s known values. */ + enum class Known { + DIRECT, + CODE_EXECUTION_20250825, + } + + /** + * An enum containing [AllowedCaller]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [AllowedCaller] 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 { + DIRECT, + CODE_EXECUTION_20250825, + /** + * An enum member indicating that [AllowedCaller] 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) { + DIRECT -> Value.DIRECT + CODE_EXECUTION_20250825 -> Value.CODE_EXECUTION_20250825 + 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) { + DIRECT -> Known.DIRECT + CODE_EXECUTION_20250825 -> Known.CODE_EXECUTION_20250825 + else -> throw AnthropicInvalidDataException("Unknown AllowedCaller: $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 + + fun validate(): AllowedCaller = 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 AllowedCaller && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class InputExample + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [InputExample]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InputExample]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(inputExample: InputExample) = apply { + additionalProperties = inputExample.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [InputExample]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): InputExample = InputExample(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): InputExample = apply { + if (validated) { + return@apply + } + + 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 = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InputExample && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "InputExample{additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -270,17 +657,29 @@ private constructor( return other is BetaMemoryTool20250818 && name == other.name && type == other.type && + allowedCallers == other.allowedCallers && cacheControl == other.cacheControl && + deferLoading == other.deferLoading && + inputExamples == other.inputExamples && strict == other.strict && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(name, type, cacheControl, strict, additionalProperties) + Objects.hash( + name, + type, + allowedCallers, + cacheControl, + deferLoading, + inputExamples, + strict, + additionalProperties, + ) } override fun hashCode(): Int = hashCode override fun toString() = - "BetaMemoryTool20250818{name=$name, type=$type, cacheControl=$cacheControl, strict=$strict, additionalProperties=$additionalProperties}" + "BetaMemoryTool20250818{name=$name, type=$type, allowedCallers=$allowedCallers, cacheControl=$cacheControl, deferLoading=$deferLoading, inputExamples=$inputExamples, strict=$strict, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaMessage.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaMessage.kt index 585472aa1..de6459884 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaMessage.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaMessage.kt @@ -519,6 +519,13 @@ private constructor( ) ) + /** + * Alias for calling [addContent] with + * `BetaContentBlock.ofToolSearchToolResult(toolSearchToolResult)`. + */ + fun addContent(toolSearchToolResult: BetaToolSearchToolResultBlock) = + addContent(BetaContentBlock.ofToolSearchToolResult(toolSearchToolResult)) + /** Alias for calling [addContent] with `BetaContentBlock.ofMcpToolUse(mcpToolUse)`. */ fun addContent(mcpToolUse: BetaMcpToolUseBlock) = addContent(BetaContentBlock.ofMcpToolUse(mcpToolUse)) diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaOutputConfig.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaOutputConfig.kt new file mode 100644 index 000000000..a986e815c --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaOutputConfig.kt @@ -0,0 +1,295 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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.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 + +class BetaOutputConfig +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val effort: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("effort") @ExcludeMissing effort: JsonField = JsonMissing.of() + ) : this(effort, mutableMapOf()) + + /** + * All possible effort levels. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun effort(): Optional = effort.getOptional("effort") + + /** + * Returns the raw JSON value of [effort]. + * + * Unlike [effort], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("effort") @ExcludeMissing fun _effort(): JsonField = effort + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [BetaOutputConfig]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaOutputConfig]. */ + class Builder internal constructor() { + + private var effort: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaOutputConfig: BetaOutputConfig) = apply { + effort = betaOutputConfig.effort + additionalProperties = betaOutputConfig.additionalProperties.toMutableMap() + } + + /** All possible effort levels. */ + fun effort(effort: Effort?) = effort(JsonField.ofNullable(effort)) + + /** Alias for calling [Builder.effort] with `effort.orElse(null)`. */ + fun effort(effort: Optional) = effort(effort.getOrNull()) + + /** + * Sets [Builder.effort] to an arbitrary JSON value. + * + * You should usually call [Builder.effort] with a well-typed [Effort] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun effort(effort: JsonField) = apply { this.effort = effort } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [BetaOutputConfig]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): BetaOutputConfig = + BetaOutputConfig(effort, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): BetaOutputConfig = apply { + if (validated) { + return@apply + } + + effort().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 = (effort.asKnown().getOrNull()?.validity() ?: 0) + + /** All possible effort levels. */ + class Effort @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 LOW = of("low") + + @JvmField val MEDIUM = of("medium") + + @JvmField val HIGH = of("high") + + @JvmStatic fun of(value: String) = Effort(JsonField.of(value)) + } + + /** An enum containing [Effort]'s known values. */ + enum class Known { + LOW, + MEDIUM, + HIGH, + } + + /** + * An enum containing [Effort]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Effort] 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 { + LOW, + MEDIUM, + HIGH, + /** An enum member indicating that [Effort] 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) { + LOW -> Value.LOW + MEDIUM -> Value.MEDIUM + HIGH -> Value.HIGH + 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) { + LOW -> Known.LOW + MEDIUM -> Known.MEDIUM + HIGH -> Known.HIGH + else -> throw AnthropicInvalidDataException("Unknown Effort: $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 + + fun validate(): Effort = 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 Effort && 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 BetaOutputConfig && + effort == other.effort && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(effort, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaOutputConfig{effort=$effort, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaRawContentBlockStartEvent.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaRawContentBlockStartEvent.kt index 6bd5c38e9..9e6db7582 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaRawContentBlockStartEvent.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaRawContentBlockStartEvent.kt @@ -214,6 +214,13 @@ private constructor( ContentBlock.ofTextEditorCodeExecutionToolResult(textEditorCodeExecutionToolResult) ) + /** + * Alias for calling [contentBlock] with + * `ContentBlock.ofToolSearchToolResult(toolSearchToolResult)`. + */ + fun contentBlock(toolSearchToolResult: BetaToolSearchToolResultBlock) = + contentBlock(ContentBlock.ofToolSearchToolResult(toolSearchToolResult)) + /** Alias for calling [contentBlock] with `ContentBlock.ofMcpToolUse(mcpToolUse)`. */ fun contentBlock(mcpToolUse: BetaMcpToolUseBlock) = contentBlock(ContentBlock.ofMcpToolUse(mcpToolUse)) @@ -356,6 +363,7 @@ private constructor( private val bashCodeExecutionToolResult: BetaBashCodeExecutionToolResultBlock? = null, private val textEditorCodeExecutionToolResult: BetaTextEditorCodeExecutionToolResultBlock? = null, + private val toolSearchToolResult: BetaToolSearchToolResultBlock? = null, private val mcpToolUse: BetaMcpToolUseBlock? = null, private val mcpToolResult: BetaMcpToolResultBlock? = null, private val containerUpload: BetaContainerUploadBlock? = null, @@ -389,6 +397,9 @@ private constructor( Optional = Optional.ofNullable(textEditorCodeExecutionToolResult) + fun toolSearchToolResult(): Optional = + Optional.ofNullable(toolSearchToolResult) + fun mcpToolUse(): Optional = Optional.ofNullable(mcpToolUse) fun mcpToolResult(): Optional = Optional.ofNullable(mcpToolResult) @@ -418,6 +429,8 @@ private constructor( fun isTextEditorCodeExecutionToolResult(): Boolean = textEditorCodeExecutionToolResult != null + fun isToolSearchToolResult(): Boolean = toolSearchToolResult != null + fun isMcpToolUse(): Boolean = mcpToolUse != null fun isMcpToolResult(): Boolean = mcpToolResult != null @@ -450,6 +463,9 @@ private constructor( fun asTextEditorCodeExecutionToolResult(): BetaTextEditorCodeExecutionToolResultBlock = textEditorCodeExecutionToolResult.getOrThrow("textEditorCodeExecutionToolResult") + fun asToolSearchToolResult(): BetaToolSearchToolResultBlock = + toolSearchToolResult.getOrThrow("toolSearchToolResult") + fun asMcpToolUse(): BetaMcpToolUseBlock = mcpToolUse.getOrThrow("mcpToolUse") fun asMcpToolResult(): BetaMcpToolResultBlock = mcpToolResult.getOrThrow("mcpToolResult") @@ -477,6 +493,8 @@ private constructor( visitor.visitTextEditorCodeExecutionToolResult( textEditorCodeExecutionToolResult ) + toolSearchToolResult != null -> + visitor.visitToolSearchToolResult(toolSearchToolResult) mcpToolUse != null -> visitor.visitMcpToolUse(mcpToolUse) mcpToolResult != null -> visitor.visitMcpToolResult(mcpToolResult) containerUpload != null -> visitor.visitContainerUpload(containerUpload) @@ -545,6 +563,12 @@ private constructor( textEditorCodeExecutionToolResult.validate() } + override fun visitToolSearchToolResult( + toolSearchToolResult: BetaToolSearchToolResultBlock + ) { + toolSearchToolResult.validate() + } + override fun visitMcpToolUse(mcpToolUse: BetaMcpToolUseBlock) { mcpToolUse.validate() } @@ -613,6 +637,10 @@ private constructor( BetaTextEditorCodeExecutionToolResultBlock ) = textEditorCodeExecutionToolResult.validity() + override fun visitToolSearchToolResult( + toolSearchToolResult: BetaToolSearchToolResultBlock + ) = toolSearchToolResult.validity() + override fun visitMcpToolUse(mcpToolUse: BetaMcpToolUseBlock) = mcpToolUse.validity() @@ -642,6 +670,7 @@ private constructor( codeExecutionToolResult == other.codeExecutionToolResult && bashCodeExecutionToolResult == other.bashCodeExecutionToolResult && textEditorCodeExecutionToolResult == other.textEditorCodeExecutionToolResult && + toolSearchToolResult == other.toolSearchToolResult && mcpToolUse == other.mcpToolUse && mcpToolResult == other.mcpToolResult && containerUpload == other.containerUpload @@ -659,6 +688,7 @@ private constructor( codeExecutionToolResult, bashCodeExecutionToolResult, textEditorCodeExecutionToolResult, + toolSearchToolResult, mcpToolUse, mcpToolResult, containerUpload, @@ -680,6 +710,8 @@ private constructor( "ContentBlock{bashCodeExecutionToolResult=$bashCodeExecutionToolResult}" textEditorCodeExecutionToolResult != null -> "ContentBlock{textEditorCodeExecutionToolResult=$textEditorCodeExecutionToolResult}" + toolSearchToolResult != null -> + "ContentBlock{toolSearchToolResult=$toolSearchToolResult}" mcpToolUse != null -> "ContentBlock{mcpToolUse=$mcpToolUse}" mcpToolResult != null -> "ContentBlock{mcpToolResult=$mcpToolResult}" containerUpload != null -> "ContentBlock{containerUpload=$containerUpload}" @@ -727,6 +759,10 @@ private constructor( textEditorCodeExecutionToolResult: BetaTextEditorCodeExecutionToolResultBlock ) = ContentBlock(textEditorCodeExecutionToolResult = textEditorCodeExecutionToolResult) + @JvmStatic + fun ofToolSearchToolResult(toolSearchToolResult: BetaToolSearchToolResultBlock) = + ContentBlock(toolSearchToolResult = toolSearchToolResult) + @JvmStatic fun ofMcpToolUse(mcpToolUse: BetaMcpToolUseBlock) = ContentBlock(mcpToolUse = mcpToolUse) @@ -773,6 +809,8 @@ private constructor( textEditorCodeExecutionToolResult: BetaTextEditorCodeExecutionToolResultBlock ): T + fun visitToolSearchToolResult(toolSearchToolResult: BetaToolSearchToolResultBlock): T + fun visitMcpToolUse(mcpToolUse: BetaMcpToolUseBlock): T fun visitMcpToolResult(mcpToolResult: BetaMcpToolResultBlock): T @@ -862,6 +900,11 @@ private constructor( ContentBlock(textEditorCodeExecutionToolResult = it, _json = json) } ?: ContentBlock(_json = json) } + "tool_search_tool_result" -> { + return tryDeserialize(node, jacksonTypeRef()) + ?.let { ContentBlock(toolSearchToolResult = it, _json = json) } + ?: ContentBlock(_json = json) + } "mcp_tool_use" -> { return tryDeserialize(node, jacksonTypeRef())?.let { ContentBlock(mcpToolUse = it, _json = json) @@ -906,6 +949,8 @@ private constructor( generator.writeObject(value.bashCodeExecutionToolResult) value.textEditorCodeExecutionToolResult != null -> generator.writeObject(value.textEditorCodeExecutionToolResult) + value.toolSearchToolResult != null -> + generator.writeObject(value.toolSearchToolResult) value.mcpToolUse != null -> generator.writeObject(value.mcpToolUse) value.mcpToolResult != null -> generator.writeObject(value.mcpToolResult) value.containerUpload != null -> generator.writeObject(value.containerUpload) diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaServerToolCaller.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaServerToolCaller.kt new file mode 100644 index 000000000..5add5faaf --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaServerToolCaller.kt @@ -0,0 +1,210 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 + +/** Tool invocation generated by a server-side tool. */ +class BetaServerToolCaller +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val toolId: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("tool_id") @ExcludeMissing toolId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(toolId, 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 toolId(): String = toolId.getRequired("tool_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("code_execution_20250825") + * ``` + * + * 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 [toolId]. + * + * Unlike [toolId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tool_id") @ExcludeMissing fun _toolId(): JsonField = toolId + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [BetaServerToolCaller]. + * + * The following fields are required: + * ```java + * .toolId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaServerToolCaller]. */ + class Builder internal constructor() { + + private var toolId: JsonField? = null + private var type: JsonValue = JsonValue.from("code_execution_20250825") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaServerToolCaller: BetaServerToolCaller) = apply { + toolId = betaServerToolCaller.toolId + type = betaServerToolCaller.type + additionalProperties = betaServerToolCaller.additionalProperties.toMutableMap() + } + + fun toolId(toolId: String) = toolId(JsonField.of(toolId)) + + /** + * Sets [Builder.toolId] to an arbitrary JSON value. + * + * You should usually call [Builder.toolId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun toolId(toolId: JsonField) = apply { this.toolId = toolId } + + /** + * 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("code_execution_20250825") + * ``` + * + * 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 [BetaServerToolCaller]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .toolId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaServerToolCaller = + BetaServerToolCaller( + checkRequired("toolId", toolId), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BetaServerToolCaller = apply { + if (validated) { + return@apply + } + + toolId() + _type().let { + if (it != JsonValue.from("code_execution_20250825")) { + 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 (toolId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("code_execution_20250825")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaServerToolCaller && + toolId == other.toolId && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(toolId, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaServerToolCaller{toolId=$toolId, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaServerToolUseBlock.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaServerToolUseBlock.kt index 8b703b152..ad9fa92db 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaServerToolUseBlock.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaServerToolUseBlock.kt @@ -2,25 +2,37 @@ package com.anthropic.models.beta.messages +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 class BetaServerToolUseBlock @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val id: JsonField, + private val caller: JsonField, private val input: JsonValue, private val name: JsonField, private val type: JsonValue, @@ -30,16 +42,39 @@ private constructor( @JsonCreator private constructor( @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("caller") @ExcludeMissing caller: JsonField = JsonMissing.of(), @JsonProperty("input") @ExcludeMissing input: JsonValue = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), - ) : this(id, input, name, type, mutableMapOf()) + ) : this(id, caller, input, name, type, mutableMapOf()) fun toParam(): BetaServerToolUseBlockParam = BetaServerToolUseBlockParam.builder() .id(_id()) .input(_input()) .name(_name().map { BetaServerToolUseBlockParam.Name.of(it.toString()) }) + .caller( + _caller().map { + it.accept( + object : + BetaServerToolUseBlock.Caller.Visitor< + BetaServerToolUseBlockParam.Caller + > { + override fun visitDirect( + direct: BetaDirectCaller + ): BetaServerToolUseBlockParam.Caller = + BetaServerToolUseBlockParam.Caller.ofDirect(direct) + + override fun visitCodeExecution20250825( + codeExecution20250825: BetaServerToolCaller + ): BetaServerToolUseBlockParam.Caller = + BetaServerToolUseBlockParam.Caller.ofDirect( + BetaDirectCaller.builder().build() + ) + } + ) + } + ) .build() /** @@ -50,6 +85,14 @@ private constructor( @JsonProperty("input") @ExcludeMissing fun _input(): JsonValue = input + /** + * Tool invocation directly from the 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 caller(): Caller = caller.getRequired("caller") + /** * @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,6 +117,13 @@ private constructor( */ @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + /** + * Returns the raw JSON value of [caller]. + * + * Unlike [caller], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("caller") @ExcludeMissing fun _caller(): JsonField = caller + /** * Returns the raw JSON value of [name]. * @@ -101,6 +151,7 @@ private constructor( * The following fields are required: * ```java * .id() + * .caller() * .input() * .name() * ``` @@ -112,6 +163,7 @@ private constructor( class Builder internal constructor() { private var id: JsonField? = null + private var caller: JsonField? = null private var input: JsonValue? = null private var name: JsonField? = null private var type: JsonValue = JsonValue.from("server_tool_use") @@ -120,6 +172,7 @@ private constructor( @JvmSynthetic internal fun from(betaServerToolUseBlock: BetaServerToolUseBlock) = apply { id = betaServerToolUseBlock.id + caller = betaServerToolUseBlock.caller input = betaServerToolUseBlock.input name = betaServerToolUseBlock.name type = betaServerToolUseBlock.type @@ -138,6 +191,37 @@ private constructor( fun input(input: JsonValue) = apply { this.input = input } + /** Tool invocation directly from the model. */ + fun caller(caller: Caller) = caller(JsonField.of(caller)) + + /** + * Sets [Builder.caller] to an arbitrary JSON value. + * + * You should usually call [Builder.caller] with a well-typed [Caller] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun caller(caller: JsonField) = apply { this.caller = caller } + + /** Alias for calling [caller] with `Caller.ofDirect(direct)`. */ + fun caller(direct: BetaDirectCaller) = caller(Caller.ofDirect(direct)) + + /** + * Alias for calling [caller] with `Caller.ofCodeExecution20250825(codeExecution20250825)`. + */ + fun caller(codeExecution20250825: BetaServerToolCaller) = + caller(Caller.ofCodeExecution20250825(codeExecution20250825)) + + /** + * Alias for calling [caller] with the following: + * ```java + * BetaServerToolCaller.builder() + * .toolId(toolId) + * .build() + * ``` + */ + fun codeExecution20250825Caller(toolId: String) = + caller(BetaServerToolCaller.builder().toolId(toolId).build()) + fun name(name: Name) = name(JsonField.of(name)) /** @@ -189,6 +273,7 @@ private constructor( * The following fields are required: * ```java * .id() + * .caller() * .input() * .name() * ``` @@ -198,6 +283,7 @@ private constructor( fun build(): BetaServerToolUseBlock = BetaServerToolUseBlock( checkRequired("id", id), + checkRequired("caller", caller), checkRequired("input", input), checkRequired("name", name), type, @@ -213,6 +299,7 @@ private constructor( } id() + caller().validate() name().validate() _type().let { if (it != JsonValue.from("server_tool_use")) { @@ -239,8 +326,195 @@ private constructor( internal fun validity(): Int = (if (id.asKnown().isPresent) 1 else 0) + (name.asKnown().getOrNull()?.validity() ?: 0) + + (caller.asKnown().getOrNull()?.validity() ?: 0) + type.let { if (it == JsonValue.from("server_tool_use")) 1 else 0 } + /** Tool invocation directly from the model. */ + @JsonDeserialize(using = Caller.Deserializer::class) + @JsonSerialize(using = Caller.Serializer::class) + class Caller + private constructor( + private val direct: BetaDirectCaller? = null, + private val codeExecution20250825: BetaServerToolCaller? = null, + private val _json: JsonValue? = null, + ) { + + /** Tool invocation directly from the model. */ + fun direct(): Optional = Optional.ofNullable(direct) + + /** Tool invocation generated by a server-side tool. */ + fun codeExecution20250825(): Optional = + Optional.ofNullable(codeExecution20250825) + + fun isDirect(): Boolean = direct != null + + fun isCodeExecution20250825(): Boolean = codeExecution20250825 != null + + /** Tool invocation directly from the model. */ + fun asDirect(): BetaDirectCaller = direct.getOrThrow("direct") + + /** Tool invocation generated by a server-side tool. */ + fun asCodeExecution20250825(): BetaServerToolCaller = + codeExecution20250825.getOrThrow("codeExecution20250825") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + direct != null -> visitor.visitDirect(direct) + codeExecution20250825 != null -> + visitor.visitCodeExecution20250825(codeExecution20250825) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Caller = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitDirect(direct: BetaDirectCaller) { + direct.validate() + } + + override fun visitCodeExecution20250825( + codeExecution20250825: BetaServerToolCaller + ) { + codeExecution20250825.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 visitDirect(direct: BetaDirectCaller) = direct.validity() + + override fun visitCodeExecution20250825( + codeExecution20250825: BetaServerToolCaller + ) = codeExecution20250825.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Caller && + direct == other.direct && + codeExecution20250825 == other.codeExecution20250825 + } + + override fun hashCode(): Int = Objects.hash(direct, codeExecution20250825) + + override fun toString(): String = + when { + direct != null -> "Caller{direct=$direct}" + codeExecution20250825 != null -> + "Caller{codeExecution20250825=$codeExecution20250825}" + _json != null -> "Caller{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Caller") + } + + companion object { + + /** Tool invocation directly from the model. */ + @JvmStatic fun ofDirect(direct: BetaDirectCaller) = Caller(direct = direct) + + /** Tool invocation generated by a server-side tool. */ + @JvmStatic + fun ofCodeExecution20250825(codeExecution20250825: BetaServerToolCaller) = + Caller(codeExecution20250825 = codeExecution20250825) + } + + /** An interface that defines how to map each variant of [Caller] to a value of type [T]. */ + interface Visitor { + + /** Tool invocation directly from the model. */ + fun visitDirect(direct: BetaDirectCaller): T + + /** Tool invocation generated by a server-side tool. */ + fun visitCodeExecution20250825(codeExecution20250825: BetaServerToolCaller): T + + /** + * Maps an unknown variant of [Caller] to a value of type [T]. + * + * An instance of [Caller] 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 Caller: $json") + } + } + + internal class Deserializer : BaseDeserializer(Caller::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Caller { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "direct" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Caller(direct = it, _json = json) + } ?: Caller(_json = json) + } + "code_execution_20250825" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Caller(codeExecution20250825 = it, _json = json) + } ?: Caller(_json = json) + } + } + + return Caller(_json = json) + } + } + + internal class Serializer : BaseSerializer(Caller::class) { + + override fun serialize( + value: Caller, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.direct != null -> generator.writeObject(value.direct) + value.codeExecution20250825 != null -> + generator.writeObject(value.codeExecution20250825) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Caller") + } + } + } + } + class Name @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -265,6 +539,10 @@ private constructor( @JvmField val TEXT_EDITOR_CODE_EXECUTION = of("text_editor_code_execution") + @JvmField val TOOL_SEARCH_TOOL_REGEX = of("tool_search_tool_regex") + + @JvmField val TOOL_SEARCH_TOOL_BM25 = of("tool_search_tool_bm25") + @JvmStatic fun of(value: String) = Name(JsonField.of(value)) } @@ -275,6 +553,8 @@ private constructor( CODE_EXECUTION, BASH_CODE_EXECUTION, TEXT_EDITOR_CODE_EXECUTION, + TOOL_SEARCH_TOOL_REGEX, + TOOL_SEARCH_TOOL_BM25, } /** @@ -292,6 +572,8 @@ private constructor( CODE_EXECUTION, BASH_CODE_EXECUTION, TEXT_EDITOR_CODE_EXECUTION, + TOOL_SEARCH_TOOL_REGEX, + TOOL_SEARCH_TOOL_BM25, /** An enum member indicating that [Name] was instantiated with an unknown value. */ _UNKNOWN, } @@ -310,6 +592,8 @@ private constructor( CODE_EXECUTION -> Value.CODE_EXECUTION BASH_CODE_EXECUTION -> Value.BASH_CODE_EXECUTION TEXT_EDITOR_CODE_EXECUTION -> Value.TEXT_EDITOR_CODE_EXECUTION + TOOL_SEARCH_TOOL_REGEX -> Value.TOOL_SEARCH_TOOL_REGEX + TOOL_SEARCH_TOOL_BM25 -> Value.TOOL_SEARCH_TOOL_BM25 else -> Value._UNKNOWN } @@ -329,6 +613,8 @@ private constructor( CODE_EXECUTION -> Known.CODE_EXECUTION BASH_CODE_EXECUTION -> Known.BASH_CODE_EXECUTION TEXT_EDITOR_CODE_EXECUTION -> Known.TEXT_EDITOR_CODE_EXECUTION + TOOL_SEARCH_TOOL_REGEX -> Known.TOOL_SEARCH_TOOL_REGEX + TOOL_SEARCH_TOOL_BM25 -> Known.TOOL_SEARCH_TOOL_BM25 else -> throw AnthropicInvalidDataException("Unknown Name: $value") } @@ -393,16 +679,19 @@ private constructor( return other is BetaServerToolUseBlock && id == other.id && + caller == other.caller && input == other.input && name == other.name && type == other.type && additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { Objects.hash(id, input, name, type, additionalProperties) } + private val hashCode: Int by lazy { + Objects.hash(id, caller, input, name, type, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "BetaServerToolUseBlock{id=$id, input=$input, name=$name, type=$type, additionalProperties=$additionalProperties}" + "BetaServerToolUseBlock{id=$id, caller=$caller, input=$input, name=$name, type=$type, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaServerToolUseBlockParam.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaServerToolUseBlockParam.kt index 490eec2ff..d781831c8 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaServerToolUseBlockParam.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaServerToolUseBlockParam.kt @@ -2,18 +2,28 @@ package com.anthropic.models.beta.messages +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.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.util.Collections import java.util.Objects import java.util.Optional @@ -27,6 +37,7 @@ private constructor( private val name: JsonField, private val type: JsonValue, private val cacheControl: JsonField, + private val caller: JsonField, private val additionalProperties: MutableMap, ) { @@ -39,7 +50,8 @@ private constructor( @JsonProperty("cache_control") @ExcludeMissing cacheControl: JsonField = JsonMissing.of(), - ) : this(id, input, name, type, cacheControl, mutableMapOf()) + @JsonProperty("caller") @ExcludeMissing caller: JsonField = JsonMissing.of(), + ) : this(id, input, name, type, cacheControl, caller, mutableMapOf()) /** * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is @@ -79,6 +91,14 @@ private constructor( fun cacheControl(): Optional = cacheControl.getOptional("cache_control") + /** + * Tool invocation directly from the model. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun caller(): Optional = caller.getOptional("caller") + /** * Returns the raw JSON value of [id]. * @@ -109,6 +129,13 @@ private constructor( @ExcludeMissing fun _cacheControl(): JsonField = cacheControl + /** + * Returns the raw JSON value of [caller]. + * + * Unlike [caller], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("caller") @ExcludeMissing fun _caller(): JsonField = caller + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -144,6 +171,7 @@ private constructor( private var name: JsonField? = null private var type: JsonValue = JsonValue.from("server_tool_use") private var cacheControl: JsonField = JsonMissing.of() + private var caller: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -153,6 +181,7 @@ private constructor( name = betaServerToolUseBlockParam.name type = betaServerToolUseBlockParam.type cacheControl = betaServerToolUseBlockParam.cacheControl + caller = betaServerToolUseBlockParam.caller additionalProperties = betaServerToolUseBlockParam.additionalProperties.toMutableMap() } @@ -219,6 +248,37 @@ private constructor( this.cacheControl = cacheControl } + /** Tool invocation directly from the model. */ + fun caller(caller: Caller) = caller(JsonField.of(caller)) + + /** + * Sets [Builder.caller] to an arbitrary JSON value. + * + * You should usually call [Builder.caller] with a well-typed [Caller] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun caller(caller: JsonField) = apply { this.caller = caller } + + /** Alias for calling [caller] with `Caller.ofDirect(direct)`. */ + fun caller(direct: BetaDirectCaller) = caller(Caller.ofDirect(direct)) + + /** + * Alias for calling [caller] with `Caller.ofCodeExecution20250825(codeExecution20250825)`. + */ + fun caller(codeExecution20250825: BetaServerToolCaller) = + caller(Caller.ofCodeExecution20250825(codeExecution20250825)) + + /** + * Alias for calling [caller] with the following: + * ```java + * BetaServerToolCaller.builder() + * .toolId(toolId) + * .build() + * ``` + */ + fun codeExecution20250825Caller(toolId: String) = + caller(BetaServerToolCaller.builder().toolId(toolId).build()) + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -259,6 +319,7 @@ private constructor( checkRequired("name", name), type, cacheControl, + caller, additionalProperties.toMutableMap(), ) } @@ -279,6 +340,7 @@ private constructor( } } cacheControl().ifPresent { it.validate() } + caller().ifPresent { it.validate() } validated = true } @@ -301,7 +363,8 @@ private constructor( (input.asKnown().getOrNull()?.validity() ?: 0) + (name.asKnown().getOrNull()?.validity() ?: 0) + type.let { if (it == JsonValue.from("server_tool_use")) 1 else 0 } + - (cacheControl.asKnown().getOrNull()?.validity() ?: 0) + (cacheControl.asKnown().getOrNull()?.validity() ?: 0) + + (caller.asKnown().getOrNull()?.validity() ?: 0) class Input @JsonCreator @@ -426,6 +489,10 @@ private constructor( @JvmField val TEXT_EDITOR_CODE_EXECUTION = of("text_editor_code_execution") + @JvmField val TOOL_SEARCH_TOOL_REGEX = of("tool_search_tool_regex") + + @JvmField val TOOL_SEARCH_TOOL_BM25 = of("tool_search_tool_bm25") + @JvmStatic fun of(value: String) = Name(JsonField.of(value)) } @@ -436,6 +503,8 @@ private constructor( CODE_EXECUTION, BASH_CODE_EXECUTION, TEXT_EDITOR_CODE_EXECUTION, + TOOL_SEARCH_TOOL_REGEX, + TOOL_SEARCH_TOOL_BM25, } /** @@ -453,6 +522,8 @@ private constructor( CODE_EXECUTION, BASH_CODE_EXECUTION, TEXT_EDITOR_CODE_EXECUTION, + TOOL_SEARCH_TOOL_REGEX, + TOOL_SEARCH_TOOL_BM25, /** An enum member indicating that [Name] was instantiated with an unknown value. */ _UNKNOWN, } @@ -471,6 +542,8 @@ private constructor( CODE_EXECUTION -> Value.CODE_EXECUTION BASH_CODE_EXECUTION -> Value.BASH_CODE_EXECUTION TEXT_EDITOR_CODE_EXECUTION -> Value.TEXT_EDITOR_CODE_EXECUTION + TOOL_SEARCH_TOOL_REGEX -> Value.TOOL_SEARCH_TOOL_REGEX + TOOL_SEARCH_TOOL_BM25 -> Value.TOOL_SEARCH_TOOL_BM25 else -> Value._UNKNOWN } @@ -490,6 +563,8 @@ private constructor( CODE_EXECUTION -> Known.CODE_EXECUTION BASH_CODE_EXECUTION -> Known.BASH_CODE_EXECUTION TEXT_EDITOR_CODE_EXECUTION -> Known.TEXT_EDITOR_CODE_EXECUTION + TOOL_SEARCH_TOOL_REGEX -> Known.TOOL_SEARCH_TOOL_REGEX + TOOL_SEARCH_TOOL_BM25 -> Known.TOOL_SEARCH_TOOL_BM25 else -> throw AnthropicInvalidDataException("Unknown Name: $value") } @@ -547,6 +622,192 @@ private constructor( override fun toString() = value.toString() } + /** Tool invocation directly from the model. */ + @JsonDeserialize(using = Caller.Deserializer::class) + @JsonSerialize(using = Caller.Serializer::class) + class Caller + private constructor( + private val direct: BetaDirectCaller? = null, + private val codeExecution20250825: BetaServerToolCaller? = null, + private val _json: JsonValue? = null, + ) { + + /** Tool invocation directly from the model. */ + fun direct(): Optional = Optional.ofNullable(direct) + + /** Tool invocation generated by a server-side tool. */ + fun codeExecution20250825(): Optional = + Optional.ofNullable(codeExecution20250825) + + fun isDirect(): Boolean = direct != null + + fun isCodeExecution20250825(): Boolean = codeExecution20250825 != null + + /** Tool invocation directly from the model. */ + fun asDirect(): BetaDirectCaller = direct.getOrThrow("direct") + + /** Tool invocation generated by a server-side tool. */ + fun asCodeExecution20250825(): BetaServerToolCaller = + codeExecution20250825.getOrThrow("codeExecution20250825") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + direct != null -> visitor.visitDirect(direct) + codeExecution20250825 != null -> + visitor.visitCodeExecution20250825(codeExecution20250825) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Caller = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitDirect(direct: BetaDirectCaller) { + direct.validate() + } + + override fun visitCodeExecution20250825( + codeExecution20250825: BetaServerToolCaller + ) { + codeExecution20250825.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 visitDirect(direct: BetaDirectCaller) = direct.validity() + + override fun visitCodeExecution20250825( + codeExecution20250825: BetaServerToolCaller + ) = codeExecution20250825.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Caller && + direct == other.direct && + codeExecution20250825 == other.codeExecution20250825 + } + + override fun hashCode(): Int = Objects.hash(direct, codeExecution20250825) + + override fun toString(): String = + when { + direct != null -> "Caller{direct=$direct}" + codeExecution20250825 != null -> + "Caller{codeExecution20250825=$codeExecution20250825}" + _json != null -> "Caller{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Caller") + } + + companion object { + + /** Tool invocation directly from the model. */ + @JvmStatic fun ofDirect(direct: BetaDirectCaller) = Caller(direct = direct) + + /** Tool invocation generated by a server-side tool. */ + @JvmStatic + fun ofCodeExecution20250825(codeExecution20250825: BetaServerToolCaller) = + Caller(codeExecution20250825 = codeExecution20250825) + } + + /** An interface that defines how to map each variant of [Caller] to a value of type [T]. */ + interface Visitor { + + /** Tool invocation directly from the model. */ + fun visitDirect(direct: BetaDirectCaller): T + + /** Tool invocation generated by a server-side tool. */ + fun visitCodeExecution20250825(codeExecution20250825: BetaServerToolCaller): T + + /** + * Maps an unknown variant of [Caller] to a value of type [T]. + * + * An instance of [Caller] 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 Caller: $json") + } + } + + internal class Deserializer : BaseDeserializer(Caller::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Caller { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "direct" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Caller(direct = it, _json = json) + } ?: Caller(_json = json) + } + "code_execution_20250825" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Caller(codeExecution20250825 = it, _json = json) + } ?: Caller(_json = json) + } + } + + return Caller(_json = json) + } + } + + internal class Serializer : BaseSerializer(Caller::class) { + + override fun serialize( + value: Caller, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.direct != null -> generator.writeObject(value.direct) + value.codeExecution20250825 != null -> + generator.writeObject(value.codeExecution20250825) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Caller") + } + } + } + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -558,15 +819,16 @@ private constructor( name == other.name && type == other.type && cacheControl == other.cacheControl && + caller == other.caller && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(id, input, name, type, cacheControl, additionalProperties) + Objects.hash(id, input, name, type, cacheControl, caller, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "BetaServerToolUseBlockParam{id=$id, input=$input, name=$name, type=$type, cacheControl=$cacheControl, additionalProperties=$additionalProperties}" + "BetaServerToolUseBlockParam{id=$id, input=$input, name=$name, type=$type, cacheControl=$cacheControl, caller=$caller, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaTool.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaTool.kt index 2e1e51672..7e9a16b89 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaTool.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaTool.kt @@ -25,8 +25,11 @@ class BetaTool private constructor( private val inputSchema: JsonField, private val name: JsonField, + private val allowedCallers: JsonField>, private val cacheControl: JsonField, + private val deferLoading: JsonField, private val description: JsonField, + private val inputExamples: JsonField>, private val strict: JsonField, private val type: JsonField, private val additionalProperties: MutableMap, @@ -38,15 +41,35 @@ private constructor( @ExcludeMissing inputSchema: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("allowed_callers") + @ExcludeMissing + allowedCallers: JsonField> = JsonMissing.of(), @JsonProperty("cache_control") @ExcludeMissing cacheControl: JsonField = JsonMissing.of(), + @JsonProperty("defer_loading") + @ExcludeMissing + deferLoading: JsonField = JsonMissing.of(), @JsonProperty("description") @ExcludeMissing description: JsonField = JsonMissing.of(), + @JsonProperty("input_examples") + @ExcludeMissing + inputExamples: JsonField> = JsonMissing.of(), @JsonProperty("strict") @ExcludeMissing strict: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), - ) : this(inputSchema, name, cacheControl, description, strict, type, mutableMapOf()) + ) : this( + inputSchema, + name, + allowedCallers, + cacheControl, + deferLoading, + description, + inputExamples, + strict, + type, + mutableMapOf(), + ) /** * [JSON schema](https://json-schema.org/draft/2020-12) for this tool's input. @@ -68,6 +91,13 @@ private constructor( */ fun name(): String = name.getRequired("name") + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun allowedCallers(): Optional> = + allowedCallers.getOptional("allowed_callers") + /** * Create a cache control breakpoint at this content block. * @@ -77,6 +107,15 @@ private constructor( fun cacheControl(): Optional = cacheControl.getOptional("cache_control") + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned via + * tool_reference from tool search. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun deferLoading(): Optional = deferLoading.getOptional("defer_loading") + /** * Description of what this tool does. * @@ -89,6 +128,12 @@ private constructor( */ fun description(): Optional = description.getOptional("description") + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun inputExamples(): Optional> = inputExamples.getOptional("input_examples") + /** * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -117,6 +162,15 @@ private constructor( */ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + /** + * Returns the raw JSON value of [allowedCallers]. + * + * Unlike [allowedCallers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("allowed_callers") + @ExcludeMissing + fun _allowedCallers(): JsonField> = allowedCallers + /** * Returns the raw JSON value of [cacheControl]. * @@ -126,6 +180,15 @@ private constructor( @ExcludeMissing fun _cacheControl(): JsonField = cacheControl + /** + * Returns the raw JSON value of [deferLoading]. + * + * Unlike [deferLoading], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("defer_loading") + @ExcludeMissing + fun _deferLoading(): JsonField = deferLoading + /** * Returns the raw JSON value of [description]. * @@ -133,6 +196,15 @@ private constructor( */ @JsonProperty("description") @ExcludeMissing fun _description(): JsonField = description + /** + * Returns the raw JSON value of [inputExamples]. + * + * Unlike [inputExamples], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("input_examples") + @ExcludeMissing + fun _inputExamples(): JsonField> = inputExamples + /** * Returns the raw JSON value of [strict]. * @@ -178,8 +250,11 @@ private constructor( private var inputSchema: JsonField? = null private var name: JsonField? = null + private var allowedCallers: JsonField>? = null private var cacheControl: JsonField = JsonMissing.of() + private var deferLoading: JsonField = JsonMissing.of() private var description: JsonField = JsonMissing.of() + private var inputExamples: JsonField>? = null private var strict: JsonField = JsonMissing.of() private var type: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -188,8 +263,11 @@ private constructor( internal fun from(betaTool: BetaTool) = apply { inputSchema = betaTool.inputSchema name = betaTool.name + allowedCallers = betaTool.allowedCallers.map { it.toMutableList() } cacheControl = betaTool.cacheControl + deferLoading = betaTool.deferLoading description = betaTool.description + inputExamples = betaTool.inputExamples.map { it.toMutableList() } strict = betaTool.strict type = betaTool.type additionalProperties = betaTool.additionalProperties.toMutableMap() @@ -229,6 +307,32 @@ private constructor( */ fun name(name: JsonField) = apply { this.name = name } + fun allowedCallers(allowedCallers: List) = + allowedCallers(JsonField.of(allowedCallers)) + + /** + * Sets [Builder.allowedCallers] to an arbitrary JSON value. + * + * You should usually call [Builder.allowedCallers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun allowedCallers(allowedCallers: JsonField>) = apply { + this.allowedCallers = allowedCallers.map { it.toMutableList() } + } + + /** + * Adds a single [AllowedCaller] to [allowedCallers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAllowedCaller(allowedCaller: AllowedCaller) = apply { + allowedCallers = + (allowedCallers ?: JsonField.of(mutableListOf())).also { + checkKnown("allowedCallers", it).add(allowedCaller) + } + } + /** Create a cache control breakpoint at this content block. */ fun cacheControl(cacheControl: BetaCacheControlEphemeral?) = cacheControl(JsonField.ofNullable(cacheControl)) @@ -248,6 +352,23 @@ private constructor( this.cacheControl = cacheControl } + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned + * via tool_reference from tool search. + */ + fun deferLoading(deferLoading: Boolean) = deferLoading(JsonField.of(deferLoading)) + + /** + * Sets [Builder.deferLoading] to an arbitrary JSON value. + * + * You should usually call [Builder.deferLoading] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun deferLoading(deferLoading: JsonField) = apply { + this.deferLoading = deferLoading + } + /** * Description of what this tool does. * @@ -267,6 +388,32 @@ private constructor( */ fun description(description: JsonField) = apply { this.description = description } + fun inputExamples(inputExamples: List) = + inputExamples(JsonField.of(inputExamples)) + + /** + * Sets [Builder.inputExamples] to an arbitrary JSON value. + * + * You should usually call [Builder.inputExamples] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun inputExamples(inputExamples: JsonField>) = apply { + this.inputExamples = inputExamples.map { it.toMutableList() } + } + + /** + * Adds a single [InputExample] to [inputExamples]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addInputExample(inputExample: InputExample) = apply { + inputExamples = + (inputExamples ?: JsonField.of(mutableListOf())).also { + checkKnown("inputExamples", it).add(inputExample) + } + } + fun strict(strict: Boolean) = strict(JsonField.of(strict)) /** @@ -326,8 +473,11 @@ private constructor( BetaTool( checkRequired("inputSchema", inputSchema), checkRequired("name", name), + (allowedCallers ?: JsonMissing.of()).map { it.toImmutable() }, cacheControl, + deferLoading, description, + (inputExamples ?: JsonMissing.of()).map { it.toImmutable() }, strict, type, additionalProperties.toMutableMap(), @@ -343,8 +493,11 @@ private constructor( inputSchema().validate() name() + allowedCallers().ifPresent { it.forEach { it.validate() } } cacheControl().ifPresent { it.validate() } + deferLoading() description() + inputExamples().ifPresent { it.forEach { it.validate() } } strict() type().ifPresent { it.validate() } validated = true @@ -367,8 +520,11 @@ private constructor( internal fun validity(): Int = (inputSchema.asKnown().getOrNull()?.validity() ?: 0) + (if (name.asKnown().isPresent) 1 else 0) + + (allowedCallers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (cacheControl.asKnown().getOrNull()?.validity() ?: 0) + + (if (deferLoading.asKnown().isPresent) 1 else 0) + (if (description.asKnown().isPresent) 1 else 0) + + (inputExamples.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (strict.asKnown().isPresent) 1 else 0) + (type.asKnown().getOrNull()?.validity() ?: 0) @@ -724,6 +880,236 @@ private constructor( "InputSchema{type=$type, properties=$properties, required=$required, additionalProperties=$additionalProperties}" } + class AllowedCaller @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 DIRECT = of("direct") + + @JvmField val CODE_EXECUTION_20250825 = of("code_execution_20250825") + + @JvmStatic fun of(value: String) = AllowedCaller(JsonField.of(value)) + } + + /** An enum containing [AllowedCaller]'s known values. */ + enum class Known { + DIRECT, + CODE_EXECUTION_20250825, + } + + /** + * An enum containing [AllowedCaller]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [AllowedCaller] 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 { + DIRECT, + CODE_EXECUTION_20250825, + /** + * An enum member indicating that [AllowedCaller] 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) { + DIRECT -> Value.DIRECT + CODE_EXECUTION_20250825 -> Value.CODE_EXECUTION_20250825 + 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) { + DIRECT -> Known.DIRECT + CODE_EXECUTION_20250825 -> Known.CODE_EXECUTION_20250825 + else -> throw AnthropicInvalidDataException("Unknown AllowedCaller: $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 + + fun validate(): AllowedCaller = 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 AllowedCaller && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class InputExample + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [InputExample]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InputExample]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(inputExample: InputExample) = apply { + additionalProperties = inputExample.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [InputExample]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): InputExample = InputExample(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): InputExample = apply { + if (validated) { + return@apply + } + + 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 = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InputExample && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "InputExample{additionalProperties=$additionalProperties}" + } + class Type @JsonCreator private constructor(private val value: JsonField) : Enum { /** @@ -853,8 +1239,11 @@ private constructor( return other is BetaTool && inputSchema == other.inputSchema && name == other.name && + allowedCallers == other.allowedCallers && cacheControl == other.cacheControl && + deferLoading == other.deferLoading && description == other.description && + inputExamples == other.inputExamples && strict == other.strict && type == other.type && additionalProperties == other.additionalProperties @@ -864,8 +1253,11 @@ private constructor( Objects.hash( inputSchema, name, + allowedCallers, cacheControl, + deferLoading, description, + inputExamples, strict, type, additionalProperties, @@ -875,5 +1267,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "BetaTool{inputSchema=$inputSchema, name=$name, cacheControl=$cacheControl, description=$description, strict=$strict, type=$type, additionalProperties=$additionalProperties}" + "BetaTool{inputSchema=$inputSchema, name=$name, allowedCallers=$allowedCallers, cacheControl=$cacheControl, deferLoading=$deferLoading, description=$description, inputExamples=$inputExamples, strict=$strict, type=$type, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolBash20241022.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolBash20241022.kt index 369c2fb60..23b301612 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolBash20241022.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolBash20241022.kt @@ -2,10 +2,13 @@ package com.anthropic.models.beta.messages +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.toImmutable import com.anthropic.errors.AnthropicInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -21,7 +24,10 @@ class BetaToolBash20241022 private constructor( private val name: JsonValue, private val type: JsonValue, + private val allowedCallers: JsonField>, private val cacheControl: JsonField, + private val deferLoading: JsonField, + private val inputExamples: JsonField>, private val strict: JsonField, private val additionalProperties: MutableMap, ) { @@ -30,11 +36,29 @@ private constructor( private constructor( @JsonProperty("name") @ExcludeMissing name: JsonValue = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("allowed_callers") + @ExcludeMissing + allowedCallers: JsonField> = JsonMissing.of(), @JsonProperty("cache_control") @ExcludeMissing cacheControl: JsonField = JsonMissing.of(), + @JsonProperty("defer_loading") + @ExcludeMissing + deferLoading: JsonField = JsonMissing.of(), + @JsonProperty("input_examples") + @ExcludeMissing + inputExamples: JsonField> = JsonMissing.of(), @JsonProperty("strict") @ExcludeMissing strict: JsonField = JsonMissing.of(), - ) : this(name, type, cacheControl, strict, mutableMapOf()) + ) : this( + name, + type, + allowedCallers, + cacheControl, + deferLoading, + inputExamples, + strict, + mutableMapOf(), + ) /** * Name of the tool. @@ -62,6 +86,13 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun allowedCallers(): Optional> = + allowedCallers.getOptional("allowed_callers") + /** * Create a cache control breakpoint at this content block. * @@ -71,12 +102,36 @@ private constructor( fun cacheControl(): Optional = cacheControl.getOptional("cache_control") + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned via + * tool_reference from tool search. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun deferLoading(): Optional = deferLoading.getOptional("defer_loading") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun inputExamples(): Optional> = inputExamples.getOptional("input_examples") + /** * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ fun strict(): Optional = strict.getOptional("strict") + /** + * Returns the raw JSON value of [allowedCallers]. + * + * Unlike [allowedCallers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("allowed_callers") + @ExcludeMissing + fun _allowedCallers(): JsonField> = allowedCallers + /** * Returns the raw JSON value of [cacheControl]. * @@ -86,6 +141,24 @@ private constructor( @ExcludeMissing fun _cacheControl(): JsonField = cacheControl + /** + * Returns the raw JSON value of [deferLoading]. + * + * Unlike [deferLoading], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("defer_loading") + @ExcludeMissing + fun _deferLoading(): JsonField = deferLoading + + /** + * Returns the raw JSON value of [inputExamples]. + * + * Unlike [inputExamples], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("input_examples") + @ExcludeMissing + fun _inputExamples(): JsonField> = inputExamples + /** * Returns the raw JSON value of [strict]. * @@ -116,7 +189,10 @@ private constructor( private var name: JsonValue = JsonValue.from("bash") private var type: JsonValue = JsonValue.from("bash_20241022") + private var allowedCallers: JsonField>? = null private var cacheControl: JsonField = JsonMissing.of() + private var deferLoading: JsonField = JsonMissing.of() + private var inputExamples: JsonField>? = null private var strict: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -124,7 +200,10 @@ private constructor( internal fun from(betaToolBash20241022: BetaToolBash20241022) = apply { name = betaToolBash20241022.name type = betaToolBash20241022.type + allowedCallers = betaToolBash20241022.allowedCallers.map { it.toMutableList() } cacheControl = betaToolBash20241022.cacheControl + deferLoading = betaToolBash20241022.deferLoading + inputExamples = betaToolBash20241022.inputExamples.map { it.toMutableList() } strict = betaToolBash20241022.strict additionalProperties = betaToolBash20241022.additionalProperties.toMutableMap() } @@ -157,6 +236,32 @@ private constructor( */ fun type(type: JsonValue) = apply { this.type = type } + fun allowedCallers(allowedCallers: List) = + allowedCallers(JsonField.of(allowedCallers)) + + /** + * Sets [Builder.allowedCallers] to an arbitrary JSON value. + * + * You should usually call [Builder.allowedCallers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun allowedCallers(allowedCallers: JsonField>) = apply { + this.allowedCallers = allowedCallers.map { it.toMutableList() } + } + + /** + * Adds a single [AllowedCaller] to [allowedCallers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAllowedCaller(allowedCaller: AllowedCaller) = apply { + allowedCallers = + (allowedCallers ?: JsonField.of(mutableListOf())).also { + checkKnown("allowedCallers", it).add(allowedCaller) + } + } + /** Create a cache control breakpoint at this content block. */ fun cacheControl(cacheControl: BetaCacheControlEphemeral?) = cacheControl(JsonField.ofNullable(cacheControl)) @@ -176,6 +281,49 @@ private constructor( this.cacheControl = cacheControl } + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned + * via tool_reference from tool search. + */ + fun deferLoading(deferLoading: Boolean) = deferLoading(JsonField.of(deferLoading)) + + /** + * Sets [Builder.deferLoading] to an arbitrary JSON value. + * + * You should usually call [Builder.deferLoading] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun deferLoading(deferLoading: JsonField) = apply { + this.deferLoading = deferLoading + } + + fun inputExamples(inputExamples: List) = + inputExamples(JsonField.of(inputExamples)) + + /** + * Sets [Builder.inputExamples] to an arbitrary JSON value. + * + * You should usually call [Builder.inputExamples] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun inputExamples(inputExamples: JsonField>) = apply { + this.inputExamples = inputExamples.map { it.toMutableList() } + } + + /** + * Adds a single [InputExample] to [inputExamples]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addInputExample(inputExample: InputExample) = apply { + inputExamples = + (inputExamples ?: JsonField.of(mutableListOf())).also { + checkKnown("inputExamples", it).add(inputExample) + } + } + fun strict(strict: Boolean) = strict(JsonField.of(strict)) /** @@ -214,7 +362,10 @@ private constructor( BetaToolBash20241022( name, type, + (allowedCallers ?: JsonMissing.of()).map { it.toImmutable() }, cacheControl, + deferLoading, + (inputExamples ?: JsonMissing.of()).map { it.toImmutable() }, strict, additionalProperties.toMutableMap(), ) @@ -237,7 +388,10 @@ private constructor( throw AnthropicInvalidDataException("'type' is invalid, received $it") } } + allowedCallers().ifPresent { it.forEach { it.validate() } } cacheControl().ifPresent { it.validate() } + deferLoading() + inputExamples().ifPresent { it.forEach { it.validate() } } strict() validated = true } @@ -259,9 +413,242 @@ private constructor( internal fun validity(): Int = name.let { if (it == JsonValue.from("bash")) 1 else 0 } + type.let { if (it == JsonValue.from("bash_20241022")) 1 else 0 } + + (allowedCallers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (cacheControl.asKnown().getOrNull()?.validity() ?: 0) + + (if (deferLoading.asKnown().isPresent) 1 else 0) + + (inputExamples.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (strict.asKnown().isPresent) 1 else 0) + class AllowedCaller @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 DIRECT = of("direct") + + @JvmField val CODE_EXECUTION_20250825 = of("code_execution_20250825") + + @JvmStatic fun of(value: String) = AllowedCaller(JsonField.of(value)) + } + + /** An enum containing [AllowedCaller]'s known values. */ + enum class Known { + DIRECT, + CODE_EXECUTION_20250825, + } + + /** + * An enum containing [AllowedCaller]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [AllowedCaller] 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 { + DIRECT, + CODE_EXECUTION_20250825, + /** + * An enum member indicating that [AllowedCaller] 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) { + DIRECT -> Value.DIRECT + CODE_EXECUTION_20250825 -> Value.CODE_EXECUTION_20250825 + 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) { + DIRECT -> Known.DIRECT + CODE_EXECUTION_20250825 -> Known.CODE_EXECUTION_20250825 + else -> throw AnthropicInvalidDataException("Unknown AllowedCaller: $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 + + fun validate(): AllowedCaller = 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 AllowedCaller && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class InputExample + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [InputExample]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InputExample]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(inputExample: InputExample) = apply { + additionalProperties = inputExample.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [InputExample]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): InputExample = InputExample(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): InputExample = apply { + if (validated) { + return@apply + } + + 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 = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InputExample && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "InputExample{additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -270,17 +657,29 @@ private constructor( return other is BetaToolBash20241022 && name == other.name && type == other.type && + allowedCallers == other.allowedCallers && cacheControl == other.cacheControl && + deferLoading == other.deferLoading && + inputExamples == other.inputExamples && strict == other.strict && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(name, type, cacheControl, strict, additionalProperties) + Objects.hash( + name, + type, + allowedCallers, + cacheControl, + deferLoading, + inputExamples, + strict, + additionalProperties, + ) } override fun hashCode(): Int = hashCode override fun toString() = - "BetaToolBash20241022{name=$name, type=$type, cacheControl=$cacheControl, strict=$strict, additionalProperties=$additionalProperties}" + "BetaToolBash20241022{name=$name, type=$type, allowedCallers=$allowedCallers, cacheControl=$cacheControl, deferLoading=$deferLoading, inputExamples=$inputExamples, strict=$strict, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolBash20250124.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolBash20250124.kt index 58ca1bda7..8c5a14925 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolBash20250124.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolBash20250124.kt @@ -2,10 +2,13 @@ package com.anthropic.models.beta.messages +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.toImmutable import com.anthropic.errors.AnthropicInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -21,7 +24,10 @@ class BetaToolBash20250124 private constructor( private val name: JsonValue, private val type: JsonValue, + private val allowedCallers: JsonField>, private val cacheControl: JsonField, + private val deferLoading: JsonField, + private val inputExamples: JsonField>, private val strict: JsonField, private val additionalProperties: MutableMap, ) { @@ -30,11 +36,29 @@ private constructor( private constructor( @JsonProperty("name") @ExcludeMissing name: JsonValue = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("allowed_callers") + @ExcludeMissing + allowedCallers: JsonField> = JsonMissing.of(), @JsonProperty("cache_control") @ExcludeMissing cacheControl: JsonField = JsonMissing.of(), + @JsonProperty("defer_loading") + @ExcludeMissing + deferLoading: JsonField = JsonMissing.of(), + @JsonProperty("input_examples") + @ExcludeMissing + inputExamples: JsonField> = JsonMissing.of(), @JsonProperty("strict") @ExcludeMissing strict: JsonField = JsonMissing.of(), - ) : this(name, type, cacheControl, strict, mutableMapOf()) + ) : this( + name, + type, + allowedCallers, + cacheControl, + deferLoading, + inputExamples, + strict, + mutableMapOf(), + ) /** * Name of the tool. @@ -62,6 +86,13 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun allowedCallers(): Optional> = + allowedCallers.getOptional("allowed_callers") + /** * Create a cache control breakpoint at this content block. * @@ -71,12 +102,36 @@ private constructor( fun cacheControl(): Optional = cacheControl.getOptional("cache_control") + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned via + * tool_reference from tool search. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun deferLoading(): Optional = deferLoading.getOptional("defer_loading") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun inputExamples(): Optional> = inputExamples.getOptional("input_examples") + /** * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ fun strict(): Optional = strict.getOptional("strict") + /** + * Returns the raw JSON value of [allowedCallers]. + * + * Unlike [allowedCallers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("allowed_callers") + @ExcludeMissing + fun _allowedCallers(): JsonField> = allowedCallers + /** * Returns the raw JSON value of [cacheControl]. * @@ -86,6 +141,24 @@ private constructor( @ExcludeMissing fun _cacheControl(): JsonField = cacheControl + /** + * Returns the raw JSON value of [deferLoading]. + * + * Unlike [deferLoading], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("defer_loading") + @ExcludeMissing + fun _deferLoading(): JsonField = deferLoading + + /** + * Returns the raw JSON value of [inputExamples]. + * + * Unlike [inputExamples], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("input_examples") + @ExcludeMissing + fun _inputExamples(): JsonField> = inputExamples + /** * Returns the raw JSON value of [strict]. * @@ -116,7 +189,10 @@ private constructor( private var name: JsonValue = JsonValue.from("bash") private var type: JsonValue = JsonValue.from("bash_20250124") + private var allowedCallers: JsonField>? = null private var cacheControl: JsonField = JsonMissing.of() + private var deferLoading: JsonField = JsonMissing.of() + private var inputExamples: JsonField>? = null private var strict: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -124,7 +200,10 @@ private constructor( internal fun from(betaToolBash20250124: BetaToolBash20250124) = apply { name = betaToolBash20250124.name type = betaToolBash20250124.type + allowedCallers = betaToolBash20250124.allowedCallers.map { it.toMutableList() } cacheControl = betaToolBash20250124.cacheControl + deferLoading = betaToolBash20250124.deferLoading + inputExamples = betaToolBash20250124.inputExamples.map { it.toMutableList() } strict = betaToolBash20250124.strict additionalProperties = betaToolBash20250124.additionalProperties.toMutableMap() } @@ -157,6 +236,32 @@ private constructor( */ fun type(type: JsonValue) = apply { this.type = type } + fun allowedCallers(allowedCallers: List) = + allowedCallers(JsonField.of(allowedCallers)) + + /** + * Sets [Builder.allowedCallers] to an arbitrary JSON value. + * + * You should usually call [Builder.allowedCallers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun allowedCallers(allowedCallers: JsonField>) = apply { + this.allowedCallers = allowedCallers.map { it.toMutableList() } + } + + /** + * Adds a single [AllowedCaller] to [allowedCallers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAllowedCaller(allowedCaller: AllowedCaller) = apply { + allowedCallers = + (allowedCallers ?: JsonField.of(mutableListOf())).also { + checkKnown("allowedCallers", it).add(allowedCaller) + } + } + /** Create a cache control breakpoint at this content block. */ fun cacheControl(cacheControl: BetaCacheControlEphemeral?) = cacheControl(JsonField.ofNullable(cacheControl)) @@ -176,6 +281,49 @@ private constructor( this.cacheControl = cacheControl } + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned + * via tool_reference from tool search. + */ + fun deferLoading(deferLoading: Boolean) = deferLoading(JsonField.of(deferLoading)) + + /** + * Sets [Builder.deferLoading] to an arbitrary JSON value. + * + * You should usually call [Builder.deferLoading] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun deferLoading(deferLoading: JsonField) = apply { + this.deferLoading = deferLoading + } + + fun inputExamples(inputExamples: List) = + inputExamples(JsonField.of(inputExamples)) + + /** + * Sets [Builder.inputExamples] to an arbitrary JSON value. + * + * You should usually call [Builder.inputExamples] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun inputExamples(inputExamples: JsonField>) = apply { + this.inputExamples = inputExamples.map { it.toMutableList() } + } + + /** + * Adds a single [InputExample] to [inputExamples]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addInputExample(inputExample: InputExample) = apply { + inputExamples = + (inputExamples ?: JsonField.of(mutableListOf())).also { + checkKnown("inputExamples", it).add(inputExample) + } + } + fun strict(strict: Boolean) = strict(JsonField.of(strict)) /** @@ -214,7 +362,10 @@ private constructor( BetaToolBash20250124( name, type, + (allowedCallers ?: JsonMissing.of()).map { it.toImmutable() }, cacheControl, + deferLoading, + (inputExamples ?: JsonMissing.of()).map { it.toImmutable() }, strict, additionalProperties.toMutableMap(), ) @@ -237,7 +388,10 @@ private constructor( throw AnthropicInvalidDataException("'type' is invalid, received $it") } } + allowedCallers().ifPresent { it.forEach { it.validate() } } cacheControl().ifPresent { it.validate() } + deferLoading() + inputExamples().ifPresent { it.forEach { it.validate() } } strict() validated = true } @@ -259,9 +413,242 @@ private constructor( internal fun validity(): Int = name.let { if (it == JsonValue.from("bash")) 1 else 0 } + type.let { if (it == JsonValue.from("bash_20250124")) 1 else 0 } + + (allowedCallers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (cacheControl.asKnown().getOrNull()?.validity() ?: 0) + + (if (deferLoading.asKnown().isPresent) 1 else 0) + + (inputExamples.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (strict.asKnown().isPresent) 1 else 0) + class AllowedCaller @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 DIRECT = of("direct") + + @JvmField val CODE_EXECUTION_20250825 = of("code_execution_20250825") + + @JvmStatic fun of(value: String) = AllowedCaller(JsonField.of(value)) + } + + /** An enum containing [AllowedCaller]'s known values. */ + enum class Known { + DIRECT, + CODE_EXECUTION_20250825, + } + + /** + * An enum containing [AllowedCaller]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [AllowedCaller] 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 { + DIRECT, + CODE_EXECUTION_20250825, + /** + * An enum member indicating that [AllowedCaller] 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) { + DIRECT -> Value.DIRECT + CODE_EXECUTION_20250825 -> Value.CODE_EXECUTION_20250825 + 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) { + DIRECT -> Known.DIRECT + CODE_EXECUTION_20250825 -> Known.CODE_EXECUTION_20250825 + else -> throw AnthropicInvalidDataException("Unknown AllowedCaller: $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 + + fun validate(): AllowedCaller = 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 AllowedCaller && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class InputExample + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [InputExample]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InputExample]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(inputExample: InputExample) = apply { + additionalProperties = inputExample.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [InputExample]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): InputExample = InputExample(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): InputExample = apply { + if (validated) { + return@apply + } + + 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 = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InputExample && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "InputExample{additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -270,17 +657,29 @@ private constructor( return other is BetaToolBash20250124 && name == other.name && type == other.type && + allowedCallers == other.allowedCallers && cacheControl == other.cacheControl && + deferLoading == other.deferLoading && + inputExamples == other.inputExamples && strict == other.strict && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(name, type, cacheControl, strict, additionalProperties) + Objects.hash( + name, + type, + allowedCallers, + cacheControl, + deferLoading, + inputExamples, + strict, + additionalProperties, + ) } override fun hashCode(): Int = hashCode override fun toString() = - "BetaToolBash20250124{name=$name, type=$type, cacheControl=$cacheControl, strict=$strict, additionalProperties=$additionalProperties}" + "BetaToolBash20250124{name=$name, type=$type, allowedCallers=$allowedCallers, cacheControl=$cacheControl, deferLoading=$deferLoading, inputExamples=$inputExamples, strict=$strict, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolComputerUse20241022.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolComputerUse20241022.kt index ecb002a5c..e45113a16 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolComputerUse20241022.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolComputerUse20241022.kt @@ -2,11 +2,14 @@ package com.anthropic.models.beta.messages +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 @@ -24,8 +27,11 @@ private constructor( private val displayWidthPx: JsonField, private val name: JsonValue, private val type: JsonValue, + private val allowedCallers: JsonField>, private val cacheControl: JsonField, + private val deferLoading: JsonField, private val displayNumber: JsonField, + private val inputExamples: JsonField>, private val strict: JsonField, private val additionalProperties: MutableMap, ) { @@ -40,20 +46,32 @@ private constructor( displayWidthPx: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonValue = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("allowed_callers") + @ExcludeMissing + allowedCallers: JsonField> = JsonMissing.of(), @JsonProperty("cache_control") @ExcludeMissing cacheControl: JsonField = JsonMissing.of(), + @JsonProperty("defer_loading") + @ExcludeMissing + deferLoading: JsonField = JsonMissing.of(), @JsonProperty("display_number") @ExcludeMissing displayNumber: JsonField = JsonMissing.of(), + @JsonProperty("input_examples") + @ExcludeMissing + inputExamples: JsonField> = JsonMissing.of(), @JsonProperty("strict") @ExcludeMissing strict: JsonField = JsonMissing.of(), ) : this( displayHeightPx, displayWidthPx, name, type, + allowedCallers, cacheControl, + deferLoading, displayNumber, + inputExamples, strict, mutableMapOf(), ) @@ -100,6 +118,13 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun allowedCallers(): Optional> = + allowedCallers.getOptional("allowed_callers") + /** * Create a cache control breakpoint at this content block. * @@ -109,6 +134,15 @@ private constructor( fun cacheControl(): Optional = cacheControl.getOptional("cache_control") + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned via + * tool_reference from tool search. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun deferLoading(): Optional = deferLoading.getOptional("defer_loading") + /** * The X11 display number (e.g. 0, 1) for the display. * @@ -117,6 +151,12 @@ private constructor( */ fun displayNumber(): Optional = displayNumber.getOptional("display_number") + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun inputExamples(): Optional> = inputExamples.getOptional("input_examples") + /** * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -141,6 +181,15 @@ private constructor( @ExcludeMissing fun _displayWidthPx(): JsonField = displayWidthPx + /** + * Returns the raw JSON value of [allowedCallers]. + * + * Unlike [allowedCallers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("allowed_callers") + @ExcludeMissing + fun _allowedCallers(): JsonField> = allowedCallers + /** * Returns the raw JSON value of [cacheControl]. * @@ -150,6 +199,15 @@ private constructor( @ExcludeMissing fun _cacheControl(): JsonField = cacheControl + /** + * Returns the raw JSON value of [deferLoading]. + * + * Unlike [deferLoading], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("defer_loading") + @ExcludeMissing + fun _deferLoading(): JsonField = deferLoading + /** * Returns the raw JSON value of [displayNumber]. * @@ -159,6 +217,15 @@ private constructor( @ExcludeMissing fun _displayNumber(): JsonField = displayNumber + /** + * Returns the raw JSON value of [inputExamples]. + * + * Unlike [inputExamples], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("input_examples") + @ExcludeMissing + fun _inputExamples(): JsonField> = inputExamples + /** * Returns the raw JSON value of [strict]. * @@ -199,8 +266,11 @@ private constructor( private var displayWidthPx: JsonField? = null private var name: JsonValue = JsonValue.from("computer") private var type: JsonValue = JsonValue.from("computer_20241022") + private var allowedCallers: JsonField>? = null private var cacheControl: JsonField = JsonMissing.of() + private var deferLoading: JsonField = JsonMissing.of() private var displayNumber: JsonField = JsonMissing.of() + private var inputExamples: JsonField>? = null private var strict: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -210,8 +280,11 @@ private constructor( displayWidthPx = betaToolComputerUse20241022.displayWidthPx name = betaToolComputerUse20241022.name type = betaToolComputerUse20241022.type + allowedCallers = betaToolComputerUse20241022.allowedCallers.map { it.toMutableList() } cacheControl = betaToolComputerUse20241022.cacheControl + deferLoading = betaToolComputerUse20241022.deferLoading displayNumber = betaToolComputerUse20241022.displayNumber + inputExamples = betaToolComputerUse20241022.inputExamples.map { it.toMutableList() } strict = betaToolComputerUse20241022.strict additionalProperties = betaToolComputerUse20241022.additionalProperties.toMutableMap() } @@ -272,6 +345,32 @@ private constructor( */ fun type(type: JsonValue) = apply { this.type = type } + fun allowedCallers(allowedCallers: List) = + allowedCallers(JsonField.of(allowedCallers)) + + /** + * Sets [Builder.allowedCallers] to an arbitrary JSON value. + * + * You should usually call [Builder.allowedCallers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun allowedCallers(allowedCallers: JsonField>) = apply { + this.allowedCallers = allowedCallers.map { it.toMutableList() } + } + + /** + * Adds a single [AllowedCaller] to [allowedCallers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAllowedCaller(allowedCaller: AllowedCaller) = apply { + allowedCallers = + (allowedCallers ?: JsonField.of(mutableListOf())).also { + checkKnown("allowedCallers", it).add(allowedCaller) + } + } + /** Create a cache control breakpoint at this content block. */ fun cacheControl(cacheControl: BetaCacheControlEphemeral?) = cacheControl(JsonField.ofNullable(cacheControl)) @@ -291,6 +390,23 @@ private constructor( this.cacheControl = cacheControl } + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned + * via tool_reference from tool search. + */ + fun deferLoading(deferLoading: Boolean) = deferLoading(JsonField.of(deferLoading)) + + /** + * Sets [Builder.deferLoading] to an arbitrary JSON value. + * + * You should usually call [Builder.deferLoading] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun deferLoading(deferLoading: JsonField) = apply { + this.deferLoading = deferLoading + } + /** The X11 display number (e.g. 0, 1) for the display. */ fun displayNumber(displayNumber: Long?) = displayNumber(JsonField.ofNullable(displayNumber)) @@ -315,6 +431,32 @@ private constructor( this.displayNumber = displayNumber } + fun inputExamples(inputExamples: List) = + inputExamples(JsonField.of(inputExamples)) + + /** + * Sets [Builder.inputExamples] to an arbitrary JSON value. + * + * You should usually call [Builder.inputExamples] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun inputExamples(inputExamples: JsonField>) = apply { + this.inputExamples = inputExamples.map { it.toMutableList() } + } + + /** + * Adds a single [InputExample] to [inputExamples]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addInputExample(inputExample: InputExample) = apply { + inputExamples = + (inputExamples ?: JsonField.of(mutableListOf())).also { + checkKnown("inputExamples", it).add(inputExample) + } + } + fun strict(strict: Boolean) = strict(JsonField.of(strict)) /** @@ -363,8 +505,11 @@ private constructor( checkRequired("displayWidthPx", displayWidthPx), name, type, + (allowedCallers ?: JsonMissing.of()).map { it.toImmutable() }, cacheControl, + deferLoading, displayNumber, + (inputExamples ?: JsonMissing.of()).map { it.toImmutable() }, strict, additionalProperties.toMutableMap(), ) @@ -389,8 +534,11 @@ private constructor( throw AnthropicInvalidDataException("'type' is invalid, received $it") } } + allowedCallers().ifPresent { it.forEach { it.validate() } } cacheControl().ifPresent { it.validate() } + deferLoading() displayNumber() + inputExamples().ifPresent { it.forEach { it.validate() } } strict() validated = true } @@ -414,10 +562,243 @@ private constructor( (if (displayWidthPx.asKnown().isPresent) 1 else 0) + name.let { if (it == JsonValue.from("computer")) 1 else 0 } + type.let { if (it == JsonValue.from("computer_20241022")) 1 else 0 } + + (allowedCallers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (cacheControl.asKnown().getOrNull()?.validity() ?: 0) + + (if (deferLoading.asKnown().isPresent) 1 else 0) + (if (displayNumber.asKnown().isPresent) 1 else 0) + + (inputExamples.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (strict.asKnown().isPresent) 1 else 0) + class AllowedCaller @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 DIRECT = of("direct") + + @JvmField val CODE_EXECUTION_20250825 = of("code_execution_20250825") + + @JvmStatic fun of(value: String) = AllowedCaller(JsonField.of(value)) + } + + /** An enum containing [AllowedCaller]'s known values. */ + enum class Known { + DIRECT, + CODE_EXECUTION_20250825, + } + + /** + * An enum containing [AllowedCaller]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [AllowedCaller] 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 { + DIRECT, + CODE_EXECUTION_20250825, + /** + * An enum member indicating that [AllowedCaller] 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) { + DIRECT -> Value.DIRECT + CODE_EXECUTION_20250825 -> Value.CODE_EXECUTION_20250825 + 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) { + DIRECT -> Known.DIRECT + CODE_EXECUTION_20250825 -> Known.CODE_EXECUTION_20250825 + else -> throw AnthropicInvalidDataException("Unknown AllowedCaller: $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 + + fun validate(): AllowedCaller = 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 AllowedCaller && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class InputExample + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [InputExample]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InputExample]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(inputExample: InputExample) = apply { + additionalProperties = inputExample.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [InputExample]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): InputExample = InputExample(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): InputExample = apply { + if (validated) { + return@apply + } + + 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 = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InputExample && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "InputExample{additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -428,8 +809,11 @@ private constructor( displayWidthPx == other.displayWidthPx && name == other.name && type == other.type && + allowedCallers == other.allowedCallers && cacheControl == other.cacheControl && + deferLoading == other.deferLoading && displayNumber == other.displayNumber && + inputExamples == other.inputExamples && strict == other.strict && additionalProperties == other.additionalProperties } @@ -440,8 +824,11 @@ private constructor( displayWidthPx, name, type, + allowedCallers, cacheControl, + deferLoading, displayNumber, + inputExamples, strict, additionalProperties, ) @@ -450,5 +837,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "BetaToolComputerUse20241022{displayHeightPx=$displayHeightPx, displayWidthPx=$displayWidthPx, name=$name, type=$type, cacheControl=$cacheControl, displayNumber=$displayNumber, strict=$strict, additionalProperties=$additionalProperties}" + "BetaToolComputerUse20241022{displayHeightPx=$displayHeightPx, displayWidthPx=$displayWidthPx, name=$name, type=$type, allowedCallers=$allowedCallers, cacheControl=$cacheControl, deferLoading=$deferLoading, displayNumber=$displayNumber, inputExamples=$inputExamples, strict=$strict, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolComputerUse20250124.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolComputerUse20250124.kt index fc0cd82fb..565819781 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolComputerUse20250124.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolComputerUse20250124.kt @@ -2,11 +2,14 @@ package com.anthropic.models.beta.messages +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 @@ -24,8 +27,11 @@ private constructor( private val displayWidthPx: JsonField, private val name: JsonValue, private val type: JsonValue, + private val allowedCallers: JsonField>, private val cacheControl: JsonField, + private val deferLoading: JsonField, private val displayNumber: JsonField, + private val inputExamples: JsonField>, private val strict: JsonField, private val additionalProperties: MutableMap, ) { @@ -40,20 +46,32 @@ private constructor( displayWidthPx: JsonField = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonValue = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("allowed_callers") + @ExcludeMissing + allowedCallers: JsonField> = JsonMissing.of(), @JsonProperty("cache_control") @ExcludeMissing cacheControl: JsonField = JsonMissing.of(), + @JsonProperty("defer_loading") + @ExcludeMissing + deferLoading: JsonField = JsonMissing.of(), @JsonProperty("display_number") @ExcludeMissing displayNumber: JsonField = JsonMissing.of(), + @JsonProperty("input_examples") + @ExcludeMissing + inputExamples: JsonField> = JsonMissing.of(), @JsonProperty("strict") @ExcludeMissing strict: JsonField = JsonMissing.of(), ) : this( displayHeightPx, displayWidthPx, name, type, + allowedCallers, cacheControl, + deferLoading, displayNumber, + inputExamples, strict, mutableMapOf(), ) @@ -100,6 +118,13 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun allowedCallers(): Optional> = + allowedCallers.getOptional("allowed_callers") + /** * Create a cache control breakpoint at this content block. * @@ -109,6 +134,15 @@ private constructor( fun cacheControl(): Optional = cacheControl.getOptional("cache_control") + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned via + * tool_reference from tool search. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun deferLoading(): Optional = deferLoading.getOptional("defer_loading") + /** * The X11 display number (e.g. 0, 1) for the display. * @@ -117,6 +151,12 @@ private constructor( */ fun displayNumber(): Optional = displayNumber.getOptional("display_number") + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun inputExamples(): Optional> = inputExamples.getOptional("input_examples") + /** * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). @@ -141,6 +181,15 @@ private constructor( @ExcludeMissing fun _displayWidthPx(): JsonField = displayWidthPx + /** + * Returns the raw JSON value of [allowedCallers]. + * + * Unlike [allowedCallers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("allowed_callers") + @ExcludeMissing + fun _allowedCallers(): JsonField> = allowedCallers + /** * Returns the raw JSON value of [cacheControl]. * @@ -150,6 +199,15 @@ private constructor( @ExcludeMissing fun _cacheControl(): JsonField = cacheControl + /** + * Returns the raw JSON value of [deferLoading]. + * + * Unlike [deferLoading], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("defer_loading") + @ExcludeMissing + fun _deferLoading(): JsonField = deferLoading + /** * Returns the raw JSON value of [displayNumber]. * @@ -159,6 +217,15 @@ private constructor( @ExcludeMissing fun _displayNumber(): JsonField = displayNumber + /** + * Returns the raw JSON value of [inputExamples]. + * + * Unlike [inputExamples], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("input_examples") + @ExcludeMissing + fun _inputExamples(): JsonField> = inputExamples + /** * Returns the raw JSON value of [strict]. * @@ -199,8 +266,11 @@ private constructor( private var displayWidthPx: JsonField? = null private var name: JsonValue = JsonValue.from("computer") private var type: JsonValue = JsonValue.from("computer_20250124") + private var allowedCallers: JsonField>? = null private var cacheControl: JsonField = JsonMissing.of() + private var deferLoading: JsonField = JsonMissing.of() private var displayNumber: JsonField = JsonMissing.of() + private var inputExamples: JsonField>? = null private var strict: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -210,8 +280,11 @@ private constructor( displayWidthPx = betaToolComputerUse20250124.displayWidthPx name = betaToolComputerUse20250124.name type = betaToolComputerUse20250124.type + allowedCallers = betaToolComputerUse20250124.allowedCallers.map { it.toMutableList() } cacheControl = betaToolComputerUse20250124.cacheControl + deferLoading = betaToolComputerUse20250124.deferLoading displayNumber = betaToolComputerUse20250124.displayNumber + inputExamples = betaToolComputerUse20250124.inputExamples.map { it.toMutableList() } strict = betaToolComputerUse20250124.strict additionalProperties = betaToolComputerUse20250124.additionalProperties.toMutableMap() } @@ -272,6 +345,32 @@ private constructor( */ fun type(type: JsonValue) = apply { this.type = type } + fun allowedCallers(allowedCallers: List) = + allowedCallers(JsonField.of(allowedCallers)) + + /** + * Sets [Builder.allowedCallers] to an arbitrary JSON value. + * + * You should usually call [Builder.allowedCallers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun allowedCallers(allowedCallers: JsonField>) = apply { + this.allowedCallers = allowedCallers.map { it.toMutableList() } + } + + /** + * Adds a single [AllowedCaller] to [allowedCallers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAllowedCaller(allowedCaller: AllowedCaller) = apply { + allowedCallers = + (allowedCallers ?: JsonField.of(mutableListOf())).also { + checkKnown("allowedCallers", it).add(allowedCaller) + } + } + /** Create a cache control breakpoint at this content block. */ fun cacheControl(cacheControl: BetaCacheControlEphemeral?) = cacheControl(JsonField.ofNullable(cacheControl)) @@ -291,6 +390,23 @@ private constructor( this.cacheControl = cacheControl } + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned + * via tool_reference from tool search. + */ + fun deferLoading(deferLoading: Boolean) = deferLoading(JsonField.of(deferLoading)) + + /** + * Sets [Builder.deferLoading] to an arbitrary JSON value. + * + * You should usually call [Builder.deferLoading] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun deferLoading(deferLoading: JsonField) = apply { + this.deferLoading = deferLoading + } + /** The X11 display number (e.g. 0, 1) for the display. */ fun displayNumber(displayNumber: Long?) = displayNumber(JsonField.ofNullable(displayNumber)) @@ -315,6 +431,32 @@ private constructor( this.displayNumber = displayNumber } + fun inputExamples(inputExamples: List) = + inputExamples(JsonField.of(inputExamples)) + + /** + * Sets [Builder.inputExamples] to an arbitrary JSON value. + * + * You should usually call [Builder.inputExamples] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun inputExamples(inputExamples: JsonField>) = apply { + this.inputExamples = inputExamples.map { it.toMutableList() } + } + + /** + * Adds a single [InputExample] to [inputExamples]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addInputExample(inputExample: InputExample) = apply { + inputExamples = + (inputExamples ?: JsonField.of(mutableListOf())).also { + checkKnown("inputExamples", it).add(inputExample) + } + } + fun strict(strict: Boolean) = strict(JsonField.of(strict)) /** @@ -363,8 +505,11 @@ private constructor( checkRequired("displayWidthPx", displayWidthPx), name, type, + (allowedCallers ?: JsonMissing.of()).map { it.toImmutable() }, cacheControl, + deferLoading, displayNumber, + (inputExamples ?: JsonMissing.of()).map { it.toImmutable() }, strict, additionalProperties.toMutableMap(), ) @@ -389,8 +534,11 @@ private constructor( throw AnthropicInvalidDataException("'type' is invalid, received $it") } } + allowedCallers().ifPresent { it.forEach { it.validate() } } cacheControl().ifPresent { it.validate() } + deferLoading() displayNumber() + inputExamples().ifPresent { it.forEach { it.validate() } } strict() validated = true } @@ -414,10 +562,243 @@ private constructor( (if (displayWidthPx.asKnown().isPresent) 1 else 0) + name.let { if (it == JsonValue.from("computer")) 1 else 0 } + type.let { if (it == JsonValue.from("computer_20250124")) 1 else 0 } + + (allowedCallers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (cacheControl.asKnown().getOrNull()?.validity() ?: 0) + + (if (deferLoading.asKnown().isPresent) 1 else 0) + (if (displayNumber.asKnown().isPresent) 1 else 0) + + (inputExamples.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (strict.asKnown().isPresent) 1 else 0) + class AllowedCaller @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 DIRECT = of("direct") + + @JvmField val CODE_EXECUTION_20250825 = of("code_execution_20250825") + + @JvmStatic fun of(value: String) = AllowedCaller(JsonField.of(value)) + } + + /** An enum containing [AllowedCaller]'s known values. */ + enum class Known { + DIRECT, + CODE_EXECUTION_20250825, + } + + /** + * An enum containing [AllowedCaller]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [AllowedCaller] 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 { + DIRECT, + CODE_EXECUTION_20250825, + /** + * An enum member indicating that [AllowedCaller] 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) { + DIRECT -> Value.DIRECT + CODE_EXECUTION_20250825 -> Value.CODE_EXECUTION_20250825 + 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) { + DIRECT -> Known.DIRECT + CODE_EXECUTION_20250825 -> Known.CODE_EXECUTION_20250825 + else -> throw AnthropicInvalidDataException("Unknown AllowedCaller: $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 + + fun validate(): AllowedCaller = 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 AllowedCaller && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class InputExample + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [InputExample]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InputExample]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(inputExample: InputExample) = apply { + additionalProperties = inputExample.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [InputExample]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): InputExample = InputExample(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): InputExample = apply { + if (validated) { + return@apply + } + + 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 = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InputExample && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "InputExample{additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -428,8 +809,11 @@ private constructor( displayWidthPx == other.displayWidthPx && name == other.name && type == other.type && + allowedCallers == other.allowedCallers && cacheControl == other.cacheControl && + deferLoading == other.deferLoading && displayNumber == other.displayNumber && + inputExamples == other.inputExamples && strict == other.strict && additionalProperties == other.additionalProperties } @@ -440,8 +824,11 @@ private constructor( displayWidthPx, name, type, + allowedCallers, cacheControl, + deferLoading, displayNumber, + inputExamples, strict, additionalProperties, ) @@ -450,5 +837,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "BetaToolComputerUse20250124{displayHeightPx=$displayHeightPx, displayWidthPx=$displayWidthPx, name=$name, type=$type, cacheControl=$cacheControl, displayNumber=$displayNumber, strict=$strict, additionalProperties=$additionalProperties}" + "BetaToolComputerUse20250124{displayHeightPx=$displayHeightPx, displayWidthPx=$displayWidthPx, name=$name, type=$type, allowedCallers=$allowedCallers, cacheControl=$cacheControl, deferLoading=$deferLoading, displayNumber=$displayNumber, inputExamples=$inputExamples, strict=$strict, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolComputerUse20251124.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolComputerUse20251124.kt new file mode 100644 index 000000000..a09287199 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolComputerUse20251124.kt @@ -0,0 +1,880 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class BetaToolComputerUse20251124 +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val displayHeightPx: JsonField, + private val displayWidthPx: JsonField, + private val name: JsonValue, + private val type: JsonValue, + private val allowedCallers: JsonField>, + private val cacheControl: JsonField, + private val deferLoading: JsonField, + private val displayNumber: JsonField, + private val enableZoom: JsonField, + private val inputExamples: JsonField>, + private val strict: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("display_height_px") + @ExcludeMissing + displayHeightPx: JsonField = JsonMissing.of(), + @JsonProperty("display_width_px") + @ExcludeMissing + displayWidthPx: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonValue = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("allowed_callers") + @ExcludeMissing + allowedCallers: JsonField> = JsonMissing.of(), + @JsonProperty("cache_control") + @ExcludeMissing + cacheControl: JsonField = JsonMissing.of(), + @JsonProperty("defer_loading") + @ExcludeMissing + deferLoading: JsonField = JsonMissing.of(), + @JsonProperty("display_number") + @ExcludeMissing + displayNumber: JsonField = JsonMissing.of(), + @JsonProperty("enable_zoom") + @ExcludeMissing + enableZoom: JsonField = JsonMissing.of(), + @JsonProperty("input_examples") + @ExcludeMissing + inputExamples: JsonField> = JsonMissing.of(), + @JsonProperty("strict") @ExcludeMissing strict: JsonField = JsonMissing.of(), + ) : this( + displayHeightPx, + displayWidthPx, + name, + type, + allowedCallers, + cacheControl, + deferLoading, + displayNumber, + enableZoom, + inputExamples, + strict, + mutableMapOf(), + ) + + /** + * The height of the display in pixels. + * + * @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 displayHeightPx(): Long = displayHeightPx.getRequired("display_height_px") + + /** + * The width of the display in pixels. + * + * @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 displayWidthPx(): Long = displayWidthPx.getRequired("display_width_px") + + /** + * Name of the tool. + * + * This is how the tool will be called by the model and in `tool_use` blocks. + * + * Expected to always return the following: + * ```java + * JsonValue.from("computer") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonValue = name + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("computer_20251124") + * ``` + * + * 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 (e.g. if the + * server responded with an unexpected value). + */ + fun allowedCallers(): Optional> = + allowedCallers.getOptional("allowed_callers") + + /** + * Create a cache control breakpoint at this content block. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun cacheControl(): Optional = + cacheControl.getOptional("cache_control") + + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned via + * tool_reference from tool search. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun deferLoading(): Optional = deferLoading.getOptional("defer_loading") + + /** + * The X11 display number (e.g. 0, 1) for the display. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun displayNumber(): Optional = displayNumber.getOptional("display_number") + + /** + * Whether to enable an action to take a zoomed-in screenshot of the screen. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun enableZoom(): Optional = enableZoom.getOptional("enable_zoom") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun inputExamples(): Optional> = inputExamples.getOptional("input_examples") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun strict(): Optional = strict.getOptional("strict") + + /** + * Returns the raw JSON value of [displayHeightPx]. + * + * Unlike [displayHeightPx], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("display_height_px") + @ExcludeMissing + fun _displayHeightPx(): JsonField = displayHeightPx + + /** + * Returns the raw JSON value of [displayWidthPx]. + * + * Unlike [displayWidthPx], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("display_width_px") + @ExcludeMissing + fun _displayWidthPx(): JsonField = displayWidthPx + + /** + * Returns the raw JSON value of [allowedCallers]. + * + * Unlike [allowedCallers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("allowed_callers") + @ExcludeMissing + fun _allowedCallers(): JsonField> = allowedCallers + + /** + * Returns the raw JSON value of [cacheControl]. + * + * Unlike [cacheControl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("cache_control") + @ExcludeMissing + fun _cacheControl(): JsonField = cacheControl + + /** + * Returns the raw JSON value of [deferLoading]. + * + * Unlike [deferLoading], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("defer_loading") + @ExcludeMissing + fun _deferLoading(): JsonField = deferLoading + + /** + * Returns the raw JSON value of [displayNumber]. + * + * Unlike [displayNumber], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("display_number") + @ExcludeMissing + fun _displayNumber(): JsonField = displayNumber + + /** + * Returns the raw JSON value of [enableZoom]. + * + * Unlike [enableZoom], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("enable_zoom") @ExcludeMissing fun _enableZoom(): JsonField = enableZoom + + /** + * Returns the raw JSON value of [inputExamples]. + * + * Unlike [inputExamples], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("input_examples") + @ExcludeMissing + fun _inputExamples(): JsonField> = inputExamples + + /** + * Returns the raw JSON value of [strict]. + * + * Unlike [strict], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("strict") @ExcludeMissing fun _strict(): JsonField = strict + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [BetaToolComputerUse20251124]. + * + * The following fields are required: + * ```java + * .displayHeightPx() + * .displayWidthPx() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaToolComputerUse20251124]. */ + class Builder internal constructor() { + + private var displayHeightPx: JsonField? = null + private var displayWidthPx: JsonField? = null + private var name: JsonValue = JsonValue.from("computer") + private var type: JsonValue = JsonValue.from("computer_20251124") + private var allowedCallers: JsonField>? = null + private var cacheControl: JsonField = JsonMissing.of() + private var deferLoading: JsonField = JsonMissing.of() + private var displayNumber: JsonField = JsonMissing.of() + private var enableZoom: JsonField = JsonMissing.of() + private var inputExamples: JsonField>? = null + private var strict: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaToolComputerUse20251124: BetaToolComputerUse20251124) = apply { + displayHeightPx = betaToolComputerUse20251124.displayHeightPx + displayWidthPx = betaToolComputerUse20251124.displayWidthPx + name = betaToolComputerUse20251124.name + type = betaToolComputerUse20251124.type + allowedCallers = betaToolComputerUse20251124.allowedCallers.map { it.toMutableList() } + cacheControl = betaToolComputerUse20251124.cacheControl + deferLoading = betaToolComputerUse20251124.deferLoading + displayNumber = betaToolComputerUse20251124.displayNumber + enableZoom = betaToolComputerUse20251124.enableZoom + inputExamples = betaToolComputerUse20251124.inputExamples.map { it.toMutableList() } + strict = betaToolComputerUse20251124.strict + additionalProperties = betaToolComputerUse20251124.additionalProperties.toMutableMap() + } + + /** The height of the display in pixels. */ + fun displayHeightPx(displayHeightPx: Long) = displayHeightPx(JsonField.of(displayHeightPx)) + + /** + * Sets [Builder.displayHeightPx] to an arbitrary JSON value. + * + * You should usually call [Builder.displayHeightPx] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun displayHeightPx(displayHeightPx: JsonField) = apply { + this.displayHeightPx = displayHeightPx + } + + /** The width of the display in pixels. */ + fun displayWidthPx(displayWidthPx: Long) = displayWidthPx(JsonField.of(displayWidthPx)) + + /** + * Sets [Builder.displayWidthPx] to an arbitrary JSON value. + * + * You should usually call [Builder.displayWidthPx] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun displayWidthPx(displayWidthPx: JsonField) = apply { + this.displayWidthPx = displayWidthPx + } + + /** + * 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("computer") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonValue) = apply { this.name = name } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("computer_20251124") + * ``` + * + * 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 allowedCallers(allowedCallers: List) = + allowedCallers(JsonField.of(allowedCallers)) + + /** + * Sets [Builder.allowedCallers] to an arbitrary JSON value. + * + * You should usually call [Builder.allowedCallers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun allowedCallers(allowedCallers: JsonField>) = apply { + this.allowedCallers = allowedCallers.map { it.toMutableList() } + } + + /** + * Adds a single [AllowedCaller] to [allowedCallers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAllowedCaller(allowedCaller: AllowedCaller) = apply { + allowedCallers = + (allowedCallers ?: JsonField.of(mutableListOf())).also { + checkKnown("allowedCallers", it).add(allowedCaller) + } + } + + /** Create a cache control breakpoint at this content block. */ + fun cacheControl(cacheControl: BetaCacheControlEphemeral?) = + cacheControl(JsonField.ofNullable(cacheControl)) + + /** Alias for calling [Builder.cacheControl] with `cacheControl.orElse(null)`. */ + fun cacheControl(cacheControl: Optional) = + cacheControl(cacheControl.getOrNull()) + + /** + * Sets [Builder.cacheControl] to an arbitrary JSON value. + * + * You should usually call [Builder.cacheControl] with a well-typed + * [BetaCacheControlEphemeral] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun cacheControl(cacheControl: JsonField) = apply { + this.cacheControl = cacheControl + } + + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned + * via tool_reference from tool search. + */ + fun deferLoading(deferLoading: Boolean) = deferLoading(JsonField.of(deferLoading)) + + /** + * Sets [Builder.deferLoading] to an arbitrary JSON value. + * + * You should usually call [Builder.deferLoading] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun deferLoading(deferLoading: JsonField) = apply { + this.deferLoading = deferLoading + } + + /** The X11 display number (e.g. 0, 1) for the display. */ + fun displayNumber(displayNumber: Long?) = displayNumber(JsonField.ofNullable(displayNumber)) + + /** + * Alias for [Builder.displayNumber]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun displayNumber(displayNumber: Long) = displayNumber(displayNumber as Long?) + + /** Alias for calling [Builder.displayNumber] with `displayNumber.orElse(null)`. */ + fun displayNumber(displayNumber: Optional) = displayNumber(displayNumber.getOrNull()) + + /** + * Sets [Builder.displayNumber] to an arbitrary JSON value. + * + * You should usually call [Builder.displayNumber] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun displayNumber(displayNumber: JsonField) = apply { + this.displayNumber = displayNumber + } + + /** Whether to enable an action to take a zoomed-in screenshot of the screen. */ + fun enableZoom(enableZoom: Boolean) = enableZoom(JsonField.of(enableZoom)) + + /** + * Sets [Builder.enableZoom] to an arbitrary JSON value. + * + * You should usually call [Builder.enableZoom] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun enableZoom(enableZoom: JsonField) = apply { this.enableZoom = enableZoom } + + fun inputExamples(inputExamples: List) = + inputExamples(JsonField.of(inputExamples)) + + /** + * Sets [Builder.inputExamples] to an arbitrary JSON value. + * + * You should usually call [Builder.inputExamples] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun inputExamples(inputExamples: JsonField>) = apply { + this.inputExamples = inputExamples.map { it.toMutableList() } + } + + /** + * Adds a single [InputExample] to [inputExamples]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addInputExample(inputExample: InputExample) = apply { + inputExamples = + (inputExamples ?: JsonField.of(mutableListOf())).also { + checkKnown("inputExamples", it).add(inputExample) + } + } + + fun strict(strict: Boolean) = strict(JsonField.of(strict)) + + /** + * Sets [Builder.strict] to an arbitrary JSON value. + * + * You should usually call [Builder.strict] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun strict(strict: JsonField) = apply { this.strict = strict } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [BetaToolComputerUse20251124]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .displayHeightPx() + * .displayWidthPx() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaToolComputerUse20251124 = + BetaToolComputerUse20251124( + checkRequired("displayHeightPx", displayHeightPx), + checkRequired("displayWidthPx", displayWidthPx), + name, + type, + (allowedCallers ?: JsonMissing.of()).map { it.toImmutable() }, + cacheControl, + deferLoading, + displayNumber, + enableZoom, + (inputExamples ?: JsonMissing.of()).map { it.toImmutable() }, + strict, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BetaToolComputerUse20251124 = apply { + if (validated) { + return@apply + } + + displayHeightPx() + displayWidthPx() + _name().let { + if (it != JsonValue.from("computer")) { + throw AnthropicInvalidDataException("'name' is invalid, received $it") + } + } + _type().let { + if (it != JsonValue.from("computer_20251124")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + allowedCallers().ifPresent { it.forEach { it.validate() } } + cacheControl().ifPresent { it.validate() } + deferLoading() + displayNumber() + enableZoom() + inputExamples().ifPresent { it.forEach { it.validate() } } + strict() + 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 (displayHeightPx.asKnown().isPresent) 1 else 0) + + (if (displayWidthPx.asKnown().isPresent) 1 else 0) + + name.let { if (it == JsonValue.from("computer")) 1 else 0 } + + type.let { if (it == JsonValue.from("computer_20251124")) 1 else 0 } + + (allowedCallers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (cacheControl.asKnown().getOrNull()?.validity() ?: 0) + + (if (deferLoading.asKnown().isPresent) 1 else 0) + + (if (displayNumber.asKnown().isPresent) 1 else 0) + + (if (enableZoom.asKnown().isPresent) 1 else 0) + + (inputExamples.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (strict.asKnown().isPresent) 1 else 0) + + class AllowedCaller @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 DIRECT = of("direct") + + @JvmField val CODE_EXECUTION_20250825 = of("code_execution_20250825") + + @JvmStatic fun of(value: String) = AllowedCaller(JsonField.of(value)) + } + + /** An enum containing [AllowedCaller]'s known values. */ + enum class Known { + DIRECT, + CODE_EXECUTION_20250825, + } + + /** + * An enum containing [AllowedCaller]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [AllowedCaller] 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 { + DIRECT, + CODE_EXECUTION_20250825, + /** + * An enum member indicating that [AllowedCaller] 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) { + DIRECT -> Value.DIRECT + CODE_EXECUTION_20250825 -> Value.CODE_EXECUTION_20250825 + 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) { + DIRECT -> Known.DIRECT + CODE_EXECUTION_20250825 -> Known.CODE_EXECUTION_20250825 + else -> throw AnthropicInvalidDataException("Unknown AllowedCaller: $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 + + fun validate(): AllowedCaller = 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 AllowedCaller && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class InputExample + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [InputExample]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InputExample]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(inputExample: InputExample) = apply { + additionalProperties = inputExample.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [InputExample]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): InputExample = InputExample(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): InputExample = apply { + if (validated) { + return@apply + } + + 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 = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InputExample && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "InputExample{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaToolComputerUse20251124 && + displayHeightPx == other.displayHeightPx && + displayWidthPx == other.displayWidthPx && + name == other.name && + type == other.type && + allowedCallers == other.allowedCallers && + cacheControl == other.cacheControl && + deferLoading == other.deferLoading && + displayNumber == other.displayNumber && + enableZoom == other.enableZoom && + inputExamples == other.inputExamples && + strict == other.strict && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + displayHeightPx, + displayWidthPx, + name, + type, + allowedCallers, + cacheControl, + deferLoading, + displayNumber, + enableZoom, + inputExamples, + strict, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaToolComputerUse20251124{displayHeightPx=$displayHeightPx, displayWidthPx=$displayWidthPx, name=$name, type=$type, allowedCallers=$allowedCallers, cacheControl=$cacheControl, deferLoading=$deferLoading, displayNumber=$displayNumber, enableZoom=$enableZoom, inputExamples=$inputExamples, strict=$strict, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolReferenceBlock.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolReferenceBlock.kt new file mode 100644 index 000000000..c26302e04 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolReferenceBlock.kt @@ -0,0 +1,212 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 BetaToolReferenceBlock +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val toolName: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("tool_name") @ExcludeMissing toolName: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(toolName, type, mutableMapOf()) + + fun toParam(): BetaToolReferenceBlockParam = + BetaToolReferenceBlockParam.builder().toolName(_toolName()).build() + + /** + * @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 toolName(): String = toolName.getRequired("tool_name") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("tool_reference") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * Returns the raw JSON value of [toolName]. + * + * Unlike [toolName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tool_name") @ExcludeMissing fun _toolName(): JsonField = toolName + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [BetaToolReferenceBlock]. + * + * The following fields are required: + * ```java + * .toolName() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaToolReferenceBlock]. */ + class Builder internal constructor() { + + private var toolName: JsonField? = null + private var type: JsonValue = JsonValue.from("tool_reference") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaToolReferenceBlock: BetaToolReferenceBlock) = apply { + toolName = betaToolReferenceBlock.toolName + type = betaToolReferenceBlock.type + additionalProperties = betaToolReferenceBlock.additionalProperties.toMutableMap() + } + + fun toolName(toolName: String) = toolName(JsonField.of(toolName)) + + /** + * Sets [Builder.toolName] to an arbitrary JSON value. + * + * You should usually call [Builder.toolName] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun toolName(toolName: JsonField) = apply { this.toolName = toolName } + + /** + * 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("tool_reference") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [BetaToolReferenceBlock]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .toolName() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaToolReferenceBlock = + BetaToolReferenceBlock( + checkRequired("toolName", toolName), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BetaToolReferenceBlock = apply { + if (validated) { + return@apply + } + + toolName() + _type().let { + if (it != JsonValue.from("tool_reference")) { + 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 (toolName.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("tool_reference")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaToolReferenceBlock && + toolName == other.toolName && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(toolName, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaToolReferenceBlock{toolName=$toolName, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolReferenceBlockParam.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolReferenceBlockParam.kt new file mode 100644 index 000000000..48be20188 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolReferenceBlockParam.kt @@ -0,0 +1,261 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 + +/** Tool reference block that can be included in tool_result content. */ +class BetaToolReferenceBlockParam +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val toolName: JsonField, + private val type: JsonValue, + private val cacheControl: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("tool_name") @ExcludeMissing toolName: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("cache_control") + @ExcludeMissing + cacheControl: JsonField = JsonMissing.of(), + ) : this(toolName, type, cacheControl, 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 toolName(): String = toolName.getRequired("tool_name") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("tool_reference") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + + /** + * Create a cache control breakpoint at this content block. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun cacheControl(): Optional = + cacheControl.getOptional("cache_control") + + /** + * Returns the raw JSON value of [toolName]. + * + * Unlike [toolName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tool_name") @ExcludeMissing fun _toolName(): JsonField = toolName + + /** + * Returns the raw JSON value of [cacheControl]. + * + * Unlike [cacheControl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("cache_control") + @ExcludeMissing + fun _cacheControl(): JsonField = cacheControl + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [BetaToolReferenceBlockParam]. + * + * The following fields are required: + * ```java + * .toolName() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaToolReferenceBlockParam]. */ + class Builder internal constructor() { + + private var toolName: JsonField? = null + private var type: JsonValue = JsonValue.from("tool_reference") + private var cacheControl: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaToolReferenceBlockParam: BetaToolReferenceBlockParam) = apply { + toolName = betaToolReferenceBlockParam.toolName + type = betaToolReferenceBlockParam.type + cacheControl = betaToolReferenceBlockParam.cacheControl + additionalProperties = betaToolReferenceBlockParam.additionalProperties.toMutableMap() + } + + fun toolName(toolName: String) = toolName(JsonField.of(toolName)) + + /** + * Sets [Builder.toolName] to an arbitrary JSON value. + * + * You should usually call [Builder.toolName] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun toolName(toolName: JsonField) = apply { this.toolName = toolName } + + /** + * 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("tool_reference") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** Create a cache control breakpoint at this content block. */ + fun cacheControl(cacheControl: BetaCacheControlEphemeral?) = + cacheControl(JsonField.ofNullable(cacheControl)) + + /** Alias for calling [Builder.cacheControl] with `cacheControl.orElse(null)`. */ + fun cacheControl(cacheControl: Optional) = + cacheControl(cacheControl.getOrNull()) + + /** + * Sets [Builder.cacheControl] to an arbitrary JSON value. + * + * You should usually call [Builder.cacheControl] with a well-typed + * [BetaCacheControlEphemeral] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun cacheControl(cacheControl: JsonField) = apply { + this.cacheControl = cacheControl + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [BetaToolReferenceBlockParam]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .toolName() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaToolReferenceBlockParam = + BetaToolReferenceBlockParam( + checkRequired("toolName", toolName), + type, + cacheControl, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BetaToolReferenceBlockParam = apply { + if (validated) { + return@apply + } + + toolName() + _type().let { + if (it != JsonValue.from("tool_reference")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + cacheControl().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 (toolName.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("tool_reference")) 1 else 0 } + + (cacheControl.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaToolReferenceBlockParam && + toolName == other.toolName && + type == other.type && + cacheControl == other.cacheControl && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(toolName, type, cacheControl, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaToolReferenceBlockParam{toolName=$toolName, type=$type, cacheControl=$cacheControl, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolResultBlockParam.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolResultBlockParam.kt index 43b2f40b9..721c5383a 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolResultBlockParam.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolResultBlockParam.kt @@ -498,6 +498,7 @@ private constructor( } } + /** Tool reference block that can be included in tool_result content. */ @JsonDeserialize(using = Block.Deserializer::class) @JsonSerialize(using = Block.Serializer::class) class Block @@ -506,6 +507,7 @@ private constructor( private val image: BetaImageBlockParam? = null, private val searchResult: BetaSearchResultBlockParam? = null, private val document: BetaRequestDocumentBlock? = null, + private val toolReference: BetaToolReferenceBlockParam? = null, private val _json: JsonValue? = null, ) { @@ -518,6 +520,10 @@ private constructor( fun document(): Optional = Optional.ofNullable(document) + /** Tool reference block that can be included in tool_result content. */ + fun toolReference(): Optional = + Optional.ofNullable(toolReference) + fun isText(): Boolean = text != null fun isImage(): Boolean = image != null @@ -526,6 +532,8 @@ private constructor( fun isDocument(): Boolean = document != null + fun isToolReference(): Boolean = toolReference != null + fun asText(): BetaTextBlockParam = text.getOrThrow("text") fun asImage(): BetaImageBlockParam = image.getOrThrow("image") @@ -535,6 +543,10 @@ private constructor( fun asDocument(): BetaRequestDocumentBlock = document.getOrThrow("document") + /** Tool reference block that can be included in tool_result content. */ + fun asToolReference(): BetaToolReferenceBlockParam = + toolReference.getOrThrow("toolReference") + fun _json(): Optional = Optional.ofNullable(_json) fun accept(visitor: Visitor): T = @@ -543,6 +555,7 @@ private constructor( image != null -> visitor.visitImage(image) searchResult != null -> visitor.visitSearchResult(searchResult) document != null -> visitor.visitDocument(document) + toolReference != null -> visitor.visitToolReference(toolReference) else -> visitor.unknown(_json) } @@ -570,6 +583,12 @@ private constructor( override fun visitDocument(document: BetaRequestDocumentBlock) { document.validate() } + + override fun visitToolReference( + toolReference: BetaToolReferenceBlockParam + ) { + toolReference.validate() + } } ) validated = true @@ -603,6 +622,10 @@ private constructor( override fun visitDocument(document: BetaRequestDocumentBlock) = document.validity() + override fun visitToolReference( + toolReference: BetaToolReferenceBlockParam + ) = toolReference.validity() + override fun unknown(json: JsonValue?) = 0 } ) @@ -616,10 +639,12 @@ private constructor( text == other.text && image == other.image && searchResult == other.searchResult && - document == other.document + document == other.document && + toolReference == other.toolReference } - override fun hashCode(): Int = Objects.hash(text, image, searchResult, document) + override fun hashCode(): Int = + Objects.hash(text, image, searchResult, document, toolReference) override fun toString(): String = when { @@ -627,6 +652,7 @@ private constructor( image != null -> "Block{image=$image}" searchResult != null -> "Block{searchResult=$searchResult}" document != null -> "Block{document=$document}" + toolReference != null -> "Block{toolReference=$toolReference}" _json != null -> "Block{_unknown=$_json}" else -> throw IllegalStateException("Invalid Block") } @@ -643,6 +669,11 @@ private constructor( @JvmStatic fun ofDocument(document: BetaRequestDocumentBlock) = Block(document = document) + + /** Tool reference block that can be included in tool_result content. */ + @JvmStatic + fun ofToolReference(toolReference: BetaToolReferenceBlockParam) = + Block(toolReference = toolReference) } /** @@ -658,6 +689,9 @@ private constructor( fun visitDocument(document: BetaRequestDocumentBlock): T + /** Tool reference block that can be included in tool_result content. */ + fun visitToolReference(toolReference: BetaToolReferenceBlockParam): T + /** * Maps an unknown variant of [Block] to a value of type [T]. * @@ -701,6 +735,14 @@ private constructor( return tryDeserialize(node, jacksonTypeRef()) ?.let { Block(document = it, _json = json) } ?: Block(_json = json) } + "tool_reference" -> { + return tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { Block(toolReference = it, _json = json) } + ?: Block(_json = json) + } } return Block(_json = json) @@ -719,6 +761,7 @@ private constructor( value.image != null -> generator.writeObject(value.image) value.searchResult != null -> generator.writeObject(value.searchResult) value.document != null -> generator.writeObject(value.document) + value.toolReference != null -> generator.writeObject(value.toolReference) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid Block") } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolBm25_20251119.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolBm25_20251119.kt new file mode 100644 index 000000000..54ccbfce4 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolBm25_20251119.kt @@ -0,0 +1,665 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class BetaToolSearchToolBm25_20251119 +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val name: JsonValue, + private val type: JsonField, + private val allowedCallers: JsonField>, + private val cacheControl: JsonField, + private val deferLoading: JsonField, + private val strict: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonValue = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("allowed_callers") + @ExcludeMissing + allowedCallers: JsonField> = JsonMissing.of(), + @JsonProperty("cache_control") + @ExcludeMissing + cacheControl: JsonField = JsonMissing.of(), + @JsonProperty("defer_loading") + @ExcludeMissing + deferLoading: JsonField = JsonMissing.of(), + @JsonProperty("strict") @ExcludeMissing strict: JsonField = JsonMissing.of(), + ) : this(name, type, allowedCallers, cacheControl, deferLoading, strict, mutableMapOf()) + + /** + * Name of the tool. + * + * This is how the tool will be called by the model and in `tool_use` blocks. + * + * Expected to always return the following: + * ```java + * JsonValue.from("tool_search_tool_bm25") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonValue = 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 type(): Type = type.getRequired("type") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun allowedCallers(): Optional> = + allowedCallers.getOptional("allowed_callers") + + /** + * Create a cache control breakpoint at this content block. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun cacheControl(): Optional = + cacheControl.getOptional("cache_control") + + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned via + * tool_reference from tool search. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun deferLoading(): Optional = deferLoading.getOptional("defer_loading") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun strict(): Optional = strict.getOptional("strict") + + /** + * 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 [allowedCallers]. + * + * Unlike [allowedCallers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("allowed_callers") + @ExcludeMissing + fun _allowedCallers(): JsonField> = allowedCallers + + /** + * Returns the raw JSON value of [cacheControl]. + * + * Unlike [cacheControl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("cache_control") + @ExcludeMissing + fun _cacheControl(): JsonField = cacheControl + + /** + * Returns the raw JSON value of [deferLoading]. + * + * Unlike [deferLoading], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("defer_loading") + @ExcludeMissing + fun _deferLoading(): JsonField = deferLoading + + /** + * Returns the raw JSON value of [strict]. + * + * Unlike [strict], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("strict") @ExcludeMissing fun _strict(): JsonField = strict + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [BetaToolSearchToolBm25_20251119]. + * + * The following fields are required: + * ```java + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaToolSearchToolBm25_20251119]. */ + class Builder internal constructor() { + + private var name: JsonValue = JsonValue.from("tool_search_tool_bm25") + private var type: JsonField? = null + private var allowedCallers: JsonField>? = null + private var cacheControl: JsonField = JsonMissing.of() + private var deferLoading: JsonField = JsonMissing.of() + private var strict: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaToolSearchToolBm25_20251119: BetaToolSearchToolBm25_20251119) = + apply { + name = betaToolSearchToolBm25_20251119.name + type = betaToolSearchToolBm25_20251119.type + allowedCallers = + betaToolSearchToolBm25_20251119.allowedCallers.map { it.toMutableList() } + cacheControl = betaToolSearchToolBm25_20251119.cacheControl + deferLoading = betaToolSearchToolBm25_20251119.deferLoading + strict = betaToolSearchToolBm25_20251119.strict + additionalProperties = + betaToolSearchToolBm25_20251119.additionalProperties.toMutableMap() + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("tool_search_tool_bm25") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonValue) = apply { this.name = name } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun allowedCallers(allowedCallers: List) = + allowedCallers(JsonField.of(allowedCallers)) + + /** + * Sets [Builder.allowedCallers] to an arbitrary JSON value. + * + * You should usually call [Builder.allowedCallers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun allowedCallers(allowedCallers: JsonField>) = apply { + this.allowedCallers = allowedCallers.map { it.toMutableList() } + } + + /** + * Adds a single [AllowedCaller] to [allowedCallers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAllowedCaller(allowedCaller: AllowedCaller) = apply { + allowedCallers = + (allowedCallers ?: JsonField.of(mutableListOf())).also { + checkKnown("allowedCallers", it).add(allowedCaller) + } + } + + /** Create a cache control breakpoint at this content block. */ + fun cacheControl(cacheControl: BetaCacheControlEphemeral?) = + cacheControl(JsonField.ofNullable(cacheControl)) + + /** Alias for calling [Builder.cacheControl] with `cacheControl.orElse(null)`. */ + fun cacheControl(cacheControl: Optional) = + cacheControl(cacheControl.getOrNull()) + + /** + * Sets [Builder.cacheControl] to an arbitrary JSON value. + * + * You should usually call [Builder.cacheControl] with a well-typed + * [BetaCacheControlEphemeral] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun cacheControl(cacheControl: JsonField) = apply { + this.cacheControl = cacheControl + } + + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned + * via tool_reference from tool search. + */ + fun deferLoading(deferLoading: Boolean) = deferLoading(JsonField.of(deferLoading)) + + /** + * Sets [Builder.deferLoading] to an arbitrary JSON value. + * + * You should usually call [Builder.deferLoading] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun deferLoading(deferLoading: JsonField) = apply { + this.deferLoading = deferLoading + } + + fun strict(strict: Boolean) = strict(JsonField.of(strict)) + + /** + * Sets [Builder.strict] to an arbitrary JSON value. + * + * You should usually call [Builder.strict] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun strict(strict: JsonField) = apply { this.strict = strict } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [BetaToolSearchToolBm25_20251119]. + * + * 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(): BetaToolSearchToolBm25_20251119 = + BetaToolSearchToolBm25_20251119( + name, + checkRequired("type", type), + (allowedCallers ?: JsonMissing.of()).map { it.toImmutable() }, + cacheControl, + deferLoading, + strict, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BetaToolSearchToolBm25_20251119 = apply { + if (validated) { + return@apply + } + + _name().let { + if (it != JsonValue.from("tool_search_tool_bm25")) { + throw AnthropicInvalidDataException("'name' is invalid, received $it") + } + } + type().validate() + allowedCallers().ifPresent { it.forEach { it.validate() } } + cacheControl().ifPresent { it.validate() } + deferLoading() + strict() + 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 = + name.let { if (it == JsonValue.from("tool_search_tool_bm25")) 1 else 0 } + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (allowedCallers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (cacheControl.asKnown().getOrNull()?.validity() ?: 0) + + (if (deferLoading.asKnown().isPresent) 1 else 0) + + (if (strict.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 TOOL_SEARCH_TOOL_BM25_20251119 = of("tool_search_tool_bm25_20251119") + + @JvmField val TOOL_SEARCH_TOOL_BM25 = of("tool_search_tool_bm25") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + TOOL_SEARCH_TOOL_BM25_20251119, + TOOL_SEARCH_TOOL_BM25, + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TOOL_SEARCH_TOOL_BM25_20251119, + TOOL_SEARCH_TOOL_BM25, + /** An enum member indicating that [Type] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TOOL_SEARCH_TOOL_BM25_20251119 -> Value.TOOL_SEARCH_TOOL_BM25_20251119 + TOOL_SEARCH_TOOL_BM25 -> Value.TOOL_SEARCH_TOOL_BM25 + 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) { + TOOL_SEARCH_TOOL_BM25_20251119 -> Known.TOOL_SEARCH_TOOL_BM25_20251119 + TOOL_SEARCH_TOOL_BM25 -> Known.TOOL_SEARCH_TOOL_BM25 + 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 + + 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() + } + + class AllowedCaller @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 DIRECT = of("direct") + + @JvmField val CODE_EXECUTION_20250825 = of("code_execution_20250825") + + @JvmStatic fun of(value: String) = AllowedCaller(JsonField.of(value)) + } + + /** An enum containing [AllowedCaller]'s known values. */ + enum class Known { + DIRECT, + CODE_EXECUTION_20250825, + } + + /** + * An enum containing [AllowedCaller]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [AllowedCaller] 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 { + DIRECT, + CODE_EXECUTION_20250825, + /** + * An enum member indicating that [AllowedCaller] 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) { + DIRECT -> Value.DIRECT + CODE_EXECUTION_20250825 -> Value.CODE_EXECUTION_20250825 + 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) { + DIRECT -> Known.DIRECT + CODE_EXECUTION_20250825 -> Known.CODE_EXECUTION_20250825 + else -> throw AnthropicInvalidDataException("Unknown AllowedCaller: $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 + + fun validate(): AllowedCaller = 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 AllowedCaller && 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 BetaToolSearchToolBm25_20251119 && + name == other.name && + type == other.type && + allowedCallers == other.allowedCallers && + cacheControl == other.cacheControl && + deferLoading == other.deferLoading && + strict == other.strict && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + name, + type, + allowedCallers, + cacheControl, + deferLoading, + strict, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaToolSearchToolBm25_20251119{name=$name, type=$type, allowedCallers=$allowedCallers, cacheControl=$cacheControl, deferLoading=$deferLoading, strict=$strict, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolRegex20251119.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolRegex20251119.kt new file mode 100644 index 000000000..d119b58c6 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolRegex20251119.kt @@ -0,0 +1,665 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 java.util.Optional +import kotlin.jvm.optionals.getOrNull + +class BetaToolSearchToolRegex20251119 +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val name: JsonValue, + private val type: JsonField, + private val allowedCallers: JsonField>, + private val cacheControl: JsonField, + private val deferLoading: JsonField, + private val strict: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonValue = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("allowed_callers") + @ExcludeMissing + allowedCallers: JsonField> = JsonMissing.of(), + @JsonProperty("cache_control") + @ExcludeMissing + cacheControl: JsonField = JsonMissing.of(), + @JsonProperty("defer_loading") + @ExcludeMissing + deferLoading: JsonField = JsonMissing.of(), + @JsonProperty("strict") @ExcludeMissing strict: JsonField = JsonMissing.of(), + ) : this(name, type, allowedCallers, cacheControl, deferLoading, strict, mutableMapOf()) + + /** + * Name of the tool. + * + * This is how the tool will be called by the model and in `tool_use` blocks. + * + * Expected to always return the following: + * ```java + * JsonValue.from("tool_search_tool_regex") + * ``` + * + * However, this method can be useful for debugging and logging (e.g. if the server responded + * with an unexpected value). + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonValue = 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 type(): Type = type.getRequired("type") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun allowedCallers(): Optional> = + allowedCallers.getOptional("allowed_callers") + + /** + * Create a cache control breakpoint at this content block. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun cacheControl(): Optional = + cacheControl.getOptional("cache_control") + + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned via + * tool_reference from tool search. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun deferLoading(): Optional = deferLoading.getOptional("defer_loading") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun strict(): Optional = strict.getOptional("strict") + + /** + * 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 [allowedCallers]. + * + * Unlike [allowedCallers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("allowed_callers") + @ExcludeMissing + fun _allowedCallers(): JsonField> = allowedCallers + + /** + * Returns the raw JSON value of [cacheControl]. + * + * Unlike [cacheControl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("cache_control") + @ExcludeMissing + fun _cacheControl(): JsonField = cacheControl + + /** + * Returns the raw JSON value of [deferLoading]. + * + * Unlike [deferLoading], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("defer_loading") + @ExcludeMissing + fun _deferLoading(): JsonField = deferLoading + + /** + * Returns the raw JSON value of [strict]. + * + * Unlike [strict], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("strict") @ExcludeMissing fun _strict(): JsonField = strict + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [BetaToolSearchToolRegex20251119]. + * + * The following fields are required: + * ```java + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaToolSearchToolRegex20251119]. */ + class Builder internal constructor() { + + private var name: JsonValue = JsonValue.from("tool_search_tool_regex") + private var type: JsonField? = null + private var allowedCallers: JsonField>? = null + private var cacheControl: JsonField = JsonMissing.of() + private var deferLoading: JsonField = JsonMissing.of() + private var strict: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaToolSearchToolRegex20251119: BetaToolSearchToolRegex20251119) = + apply { + name = betaToolSearchToolRegex20251119.name + type = betaToolSearchToolRegex20251119.type + allowedCallers = + betaToolSearchToolRegex20251119.allowedCallers.map { it.toMutableList() } + cacheControl = betaToolSearchToolRegex20251119.cacheControl + deferLoading = betaToolSearchToolRegex20251119.deferLoading + strict = betaToolSearchToolRegex20251119.strict + additionalProperties = + betaToolSearchToolRegex20251119.additionalProperties.toMutableMap() + } + + /** + * Sets the field to an arbitrary JSON value. + * + * It is usually unnecessary to call this method because the field defaults to the + * following: + * ```java + * JsonValue.from("tool_search_tool_regex") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun name(name: JsonValue) = apply { this.name = name } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun allowedCallers(allowedCallers: List) = + allowedCallers(JsonField.of(allowedCallers)) + + /** + * Sets [Builder.allowedCallers] to an arbitrary JSON value. + * + * You should usually call [Builder.allowedCallers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun allowedCallers(allowedCallers: JsonField>) = apply { + this.allowedCallers = allowedCallers.map { it.toMutableList() } + } + + /** + * Adds a single [AllowedCaller] to [allowedCallers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAllowedCaller(allowedCaller: AllowedCaller) = apply { + allowedCallers = + (allowedCallers ?: JsonField.of(mutableListOf())).also { + checkKnown("allowedCallers", it).add(allowedCaller) + } + } + + /** Create a cache control breakpoint at this content block. */ + fun cacheControl(cacheControl: BetaCacheControlEphemeral?) = + cacheControl(JsonField.ofNullable(cacheControl)) + + /** Alias for calling [Builder.cacheControl] with `cacheControl.orElse(null)`. */ + fun cacheControl(cacheControl: Optional) = + cacheControl(cacheControl.getOrNull()) + + /** + * Sets [Builder.cacheControl] to an arbitrary JSON value. + * + * You should usually call [Builder.cacheControl] with a well-typed + * [BetaCacheControlEphemeral] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun cacheControl(cacheControl: JsonField) = apply { + this.cacheControl = cacheControl + } + + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned + * via tool_reference from tool search. + */ + fun deferLoading(deferLoading: Boolean) = deferLoading(JsonField.of(deferLoading)) + + /** + * Sets [Builder.deferLoading] to an arbitrary JSON value. + * + * You should usually call [Builder.deferLoading] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun deferLoading(deferLoading: JsonField) = apply { + this.deferLoading = deferLoading + } + + fun strict(strict: Boolean) = strict(JsonField.of(strict)) + + /** + * Sets [Builder.strict] to an arbitrary JSON value. + * + * You should usually call [Builder.strict] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun strict(strict: JsonField) = apply { this.strict = strict } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [BetaToolSearchToolRegex20251119]. + * + * 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(): BetaToolSearchToolRegex20251119 = + BetaToolSearchToolRegex20251119( + name, + checkRequired("type", type), + (allowedCallers ?: JsonMissing.of()).map { it.toImmutable() }, + cacheControl, + deferLoading, + strict, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BetaToolSearchToolRegex20251119 = apply { + if (validated) { + return@apply + } + + _name().let { + if (it != JsonValue.from("tool_search_tool_regex")) { + throw AnthropicInvalidDataException("'name' is invalid, received $it") + } + } + type().validate() + allowedCallers().ifPresent { it.forEach { it.validate() } } + cacheControl().ifPresent { it.validate() } + deferLoading() + strict() + 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 = + name.let { if (it == JsonValue.from("tool_search_tool_regex")) 1 else 0 } + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (allowedCallers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (cacheControl.asKnown().getOrNull()?.validity() ?: 0) + + (if (deferLoading.asKnown().isPresent) 1 else 0) + + (if (strict.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 TOOL_SEARCH_TOOL_REGEX_20251119 = of("tool_search_tool_regex_20251119") + + @JvmField val TOOL_SEARCH_TOOL_REGEX = of("tool_search_tool_regex") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + TOOL_SEARCH_TOOL_REGEX_20251119, + TOOL_SEARCH_TOOL_REGEX, + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TOOL_SEARCH_TOOL_REGEX_20251119, + TOOL_SEARCH_TOOL_REGEX, + /** An enum member indicating that [Type] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + TOOL_SEARCH_TOOL_REGEX_20251119 -> Value.TOOL_SEARCH_TOOL_REGEX_20251119 + TOOL_SEARCH_TOOL_REGEX -> Value.TOOL_SEARCH_TOOL_REGEX + 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) { + TOOL_SEARCH_TOOL_REGEX_20251119 -> Known.TOOL_SEARCH_TOOL_REGEX_20251119 + TOOL_SEARCH_TOOL_REGEX -> Known.TOOL_SEARCH_TOOL_REGEX + 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 + + 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() + } + + class AllowedCaller @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 DIRECT = of("direct") + + @JvmField val CODE_EXECUTION_20250825 = of("code_execution_20250825") + + @JvmStatic fun of(value: String) = AllowedCaller(JsonField.of(value)) + } + + /** An enum containing [AllowedCaller]'s known values. */ + enum class Known { + DIRECT, + CODE_EXECUTION_20250825, + } + + /** + * An enum containing [AllowedCaller]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [AllowedCaller] 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 { + DIRECT, + CODE_EXECUTION_20250825, + /** + * An enum member indicating that [AllowedCaller] 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) { + DIRECT -> Value.DIRECT + CODE_EXECUTION_20250825 -> Value.CODE_EXECUTION_20250825 + 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) { + DIRECT -> Known.DIRECT + CODE_EXECUTION_20250825 -> Known.CODE_EXECUTION_20250825 + else -> throw AnthropicInvalidDataException("Unknown AllowedCaller: $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 + + fun validate(): AllowedCaller = 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 AllowedCaller && 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 BetaToolSearchToolRegex20251119 && + name == other.name && + type == other.type && + allowedCallers == other.allowedCallers && + cacheControl == other.cacheControl && + deferLoading == other.deferLoading && + strict == other.strict && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + name, + type, + allowedCallers, + cacheControl, + deferLoading, + strict, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaToolSearchToolRegex20251119{name=$name, type=$type, allowedCallers=$allowedCallers, cacheControl=$cacheControl, deferLoading=$deferLoading, strict=$strict, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolResultBlock.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolResultBlock.kt new file mode 100644 index 000000000..ff2f1888d --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolResultBlock.kt @@ -0,0 +1,520 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +import com.anthropic.core.BaseDeserializer +import com.anthropic.core.BaseSerializer +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.allMaxBy +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 + +class BetaToolSearchToolResultBlock +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val content: JsonField, + private val toolUseId: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("content") @ExcludeMissing content: JsonField = JsonMissing.of(), + @JsonProperty("tool_use_id") + @ExcludeMissing + toolUseId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(content, toolUseId, type, mutableMapOf()) + + fun toParam(): BetaToolSearchToolResultBlockParam = + BetaToolSearchToolResultBlockParam.builder() + .content( + _content().map { + it.accept( + object : + BetaToolSearchToolResultBlock.Content.Visitor< + BetaToolSearchToolResultBlockParam.Content + > { + override fun visitBetaToolSearchToolResultError( + betaToolSearchToolResultError: BetaToolSearchToolResultError + ): BetaToolSearchToolResultBlockParam.Content = + BetaToolSearchToolResultBlockParam.Content + .ofBetaToolSearchToolResultErrorParam( + betaToolSearchToolResultError.toParam() + ) + + override fun visitBetaToolSearchToolSearchResultBlock( + betaToolSearchToolSearchResultBlock: + BetaToolSearchToolSearchResultBlock + ): BetaToolSearchToolResultBlockParam.Content = + BetaToolSearchToolResultBlockParam.Content + .ofBetaToolSearchToolSearchResultBlockParam( + betaToolSearchToolSearchResultBlock.toParam() + ) + } + ) + } + ) + .toolUseId(_toolUseId()) + .build() + + /** + * @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(): Content = 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 toolUseId(): String = toolUseId.getRequired("tool_use_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("tool_search_tool_result") + * ``` + * + * 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 [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 [toolUseId]. + * + * Unlike [toolUseId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tool_use_id") @ExcludeMissing fun _toolUseId(): JsonField = toolUseId + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [BetaToolSearchToolResultBlock]. + * + * The following fields are required: + * ```java + * .content() + * .toolUseId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaToolSearchToolResultBlock]. */ + class Builder internal constructor() { + + private var content: JsonField? = null + private var toolUseId: JsonField? = null + private var type: JsonValue = JsonValue.from("tool_search_tool_result") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaToolSearchToolResultBlock: BetaToolSearchToolResultBlock) = apply { + content = betaToolSearchToolResultBlock.content + toolUseId = betaToolSearchToolResultBlock.toolUseId + type = betaToolSearchToolResultBlock.type + additionalProperties = betaToolSearchToolResultBlock.additionalProperties.toMutableMap() + } + + fun content(content: Content) = content(JsonField.of(content)) + + /** + * Sets [Builder.content] to an arbitrary JSON value. + * + * You should usually call [Builder.content] with a well-typed [Content] 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 } + + /** + * Alias for calling [content] with + * `Content.ofBetaToolSearchToolResultError(betaToolSearchToolResultError)`. + */ + fun content(betaToolSearchToolResultError: BetaToolSearchToolResultError) = + content(Content.ofBetaToolSearchToolResultError(betaToolSearchToolResultError)) + + /** + * Alias for calling [content] with + * `Content.ofBetaToolSearchToolSearchResultBlock(betaToolSearchToolSearchResultBlock)`. + */ + fun content(betaToolSearchToolSearchResultBlock: BetaToolSearchToolSearchResultBlock) = + content( + Content.ofBetaToolSearchToolSearchResultBlock(betaToolSearchToolSearchResultBlock) + ) + + fun toolUseId(toolUseId: String) = toolUseId(JsonField.of(toolUseId)) + + /** + * Sets [Builder.toolUseId] to an arbitrary JSON value. + * + * You should usually call [Builder.toolUseId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun toolUseId(toolUseId: JsonField) = apply { this.toolUseId = toolUseId } + + /** + * 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("tool_search_tool_result") + * ``` + * + * 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 [BetaToolSearchToolResultBlock]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .content() + * .toolUseId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaToolSearchToolResultBlock = + BetaToolSearchToolResultBlock( + checkRequired("content", content), + checkRequired("toolUseId", toolUseId), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BetaToolSearchToolResultBlock = apply { + if (validated) { + return@apply + } + + content().validate() + toolUseId() + _type().let { + if (it != JsonValue.from("tool_search_tool_result")) { + 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 = + (content.asKnown().getOrNull()?.validity() ?: 0) + + (if (toolUseId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("tool_search_tool_result")) 1 else 0 } + + @JsonDeserialize(using = Content.Deserializer::class) + @JsonSerialize(using = Content.Serializer::class) + class Content + private constructor( + private val betaToolSearchToolResultError: BetaToolSearchToolResultError? = null, + private val betaToolSearchToolSearchResultBlock: BetaToolSearchToolSearchResultBlock? = + null, + private val _json: JsonValue? = null, + ) { + + fun betaToolSearchToolResultError(): Optional = + Optional.ofNullable(betaToolSearchToolResultError) + + fun betaToolSearchToolSearchResultBlock(): Optional = + Optional.ofNullable(betaToolSearchToolSearchResultBlock) + + fun isBetaToolSearchToolResultError(): Boolean = betaToolSearchToolResultError != null + + fun isBetaToolSearchToolSearchResultBlock(): Boolean = + betaToolSearchToolSearchResultBlock != null + + fun asBetaToolSearchToolResultError(): BetaToolSearchToolResultError = + betaToolSearchToolResultError.getOrThrow("betaToolSearchToolResultError") + + fun asBetaToolSearchToolSearchResultBlock(): BetaToolSearchToolSearchResultBlock = + betaToolSearchToolSearchResultBlock.getOrThrow("betaToolSearchToolSearchResultBlock") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + betaToolSearchToolResultError != null -> + visitor.visitBetaToolSearchToolResultError(betaToolSearchToolResultError) + betaToolSearchToolSearchResultBlock != null -> + visitor.visitBetaToolSearchToolSearchResultBlock( + betaToolSearchToolSearchResultBlock + ) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Content = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitBetaToolSearchToolResultError( + betaToolSearchToolResultError: BetaToolSearchToolResultError + ) { + betaToolSearchToolResultError.validate() + } + + override fun visitBetaToolSearchToolSearchResultBlock( + betaToolSearchToolSearchResultBlock: BetaToolSearchToolSearchResultBlock + ) { + betaToolSearchToolSearchResultBlock.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 visitBetaToolSearchToolResultError( + betaToolSearchToolResultError: BetaToolSearchToolResultError + ) = betaToolSearchToolResultError.validity() + + override fun visitBetaToolSearchToolSearchResultBlock( + betaToolSearchToolSearchResultBlock: BetaToolSearchToolSearchResultBlock + ) = betaToolSearchToolSearchResultBlock.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Content && + betaToolSearchToolResultError == other.betaToolSearchToolResultError && + betaToolSearchToolSearchResultBlock == other.betaToolSearchToolSearchResultBlock + } + + override fun hashCode(): Int = + Objects.hash(betaToolSearchToolResultError, betaToolSearchToolSearchResultBlock) + + override fun toString(): String = + when { + betaToolSearchToolResultError != null -> + "Content{betaToolSearchToolResultError=$betaToolSearchToolResultError}" + betaToolSearchToolSearchResultBlock != null -> + "Content{betaToolSearchToolSearchResultBlock=$betaToolSearchToolSearchResultBlock}" + _json != null -> "Content{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Content") + } + + companion object { + + @JvmStatic + fun ofBetaToolSearchToolResultError( + betaToolSearchToolResultError: BetaToolSearchToolResultError + ) = Content(betaToolSearchToolResultError = betaToolSearchToolResultError) + + @JvmStatic + fun ofBetaToolSearchToolSearchResultBlock( + betaToolSearchToolSearchResultBlock: BetaToolSearchToolSearchResultBlock + ) = Content(betaToolSearchToolSearchResultBlock = betaToolSearchToolSearchResultBlock) + } + + /** + * An interface that defines how to map each variant of [Content] to a value of type [T]. + */ + interface Visitor { + + fun visitBetaToolSearchToolResultError( + betaToolSearchToolResultError: BetaToolSearchToolResultError + ): T + + fun visitBetaToolSearchToolSearchResultBlock( + betaToolSearchToolSearchResultBlock: BetaToolSearchToolSearchResultBlock + ): 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 bestMatches = + sequenceOf( + tryDeserialize(node, jacksonTypeRef()) + ?.let { Content(betaToolSearchToolResultError = it, _json = json) }, + tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + Content(betaToolSearchToolSearchResultBlock = 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 -> Content(_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(Content::class) { + + override fun serialize( + value: Content, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.betaToolSearchToolResultError != null -> + generator.writeObject(value.betaToolSearchToolResultError) + value.betaToolSearchToolSearchResultBlock != null -> + generator.writeObject(value.betaToolSearchToolSearchResultBlock) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Content") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaToolSearchToolResultBlock && + content == other.content && + toolUseId == other.toolUseId && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(content, toolUseId, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaToolSearchToolResultBlock{content=$content, toolUseId=$toolUseId, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolResultBlockParam.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolResultBlockParam.kt new file mode 100644 index 000000000..da9b1205a --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolResultBlockParam.kt @@ -0,0 +1,578 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +import com.anthropic.core.BaseDeserializer +import com.anthropic.core.BaseSerializer +import com.anthropic.core.ExcludeMissing +import com.anthropic.core.JsonField +import com.anthropic.core.JsonMissing +import com.anthropic.core.JsonValue +import com.anthropic.core.allMaxBy +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 + +class BetaToolSearchToolResultBlockParam +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val content: JsonField, + private val toolUseId: JsonField, + private val type: JsonValue, + private val cacheControl: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("content") @ExcludeMissing content: JsonField = JsonMissing.of(), + @JsonProperty("tool_use_id") + @ExcludeMissing + toolUseId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("cache_control") + @ExcludeMissing + cacheControl: JsonField = JsonMissing.of(), + ) : this(content, toolUseId, type, cacheControl, 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 content(): Content = 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 toolUseId(): String = toolUseId.getRequired("tool_use_id") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("tool_search_tool_result") + * ``` + * + * 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 + + /** + * Create a cache control breakpoint at this content block. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun cacheControl(): Optional = + cacheControl.getOptional("cache_control") + + /** + * 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 [toolUseId]. + * + * Unlike [toolUseId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tool_use_id") @ExcludeMissing fun _toolUseId(): JsonField = toolUseId + + /** + * Returns the raw JSON value of [cacheControl]. + * + * Unlike [cacheControl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("cache_control") + @ExcludeMissing + fun _cacheControl(): JsonField = cacheControl + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [BetaToolSearchToolResultBlockParam]. + * + * The following fields are required: + * ```java + * .content() + * .toolUseId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaToolSearchToolResultBlockParam]. */ + class Builder internal constructor() { + + private var content: JsonField? = null + private var toolUseId: JsonField? = null + private var type: JsonValue = JsonValue.from("tool_search_tool_result") + private var cacheControl: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaToolSearchToolResultBlockParam: BetaToolSearchToolResultBlockParam) = + apply { + content = betaToolSearchToolResultBlockParam.content + toolUseId = betaToolSearchToolResultBlockParam.toolUseId + type = betaToolSearchToolResultBlockParam.type + cacheControl = betaToolSearchToolResultBlockParam.cacheControl + additionalProperties = + betaToolSearchToolResultBlockParam.additionalProperties.toMutableMap() + } + + fun content(content: Content) = content(JsonField.of(content)) + + /** + * Sets [Builder.content] to an arbitrary JSON value. + * + * You should usually call [Builder.content] with a well-typed [Content] 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 } + + /** + * Alias for calling [content] with + * `Content.ofBetaToolSearchToolResultErrorParam(betaToolSearchToolResultErrorParam)`. + */ + fun content(betaToolSearchToolResultErrorParam: BetaToolSearchToolResultErrorParam) = + content( + Content.ofBetaToolSearchToolResultErrorParam(betaToolSearchToolResultErrorParam) + ) + + /** Alias for calling [content] with `betaToolSearchToolResultErrorParam.toParam()`. */ + fun content(betaToolSearchToolResultErrorParam: BetaToolSearchToolResultError) = + content(betaToolSearchToolResultErrorParam.toParam()) + + /** + * Alias for calling [content] with + * `Content.ofBetaToolSearchToolSearchResultBlockParam(betaToolSearchToolSearchResultBlockParam)`. + */ + fun content( + betaToolSearchToolSearchResultBlockParam: BetaToolSearchToolSearchResultBlockParam + ) = + content( + Content.ofBetaToolSearchToolSearchResultBlockParam( + betaToolSearchToolSearchResultBlockParam + ) + ) + + /** + * Alias for calling [content] with `betaToolSearchToolSearchResultBlockParam.toParam()`. + */ + fun content(betaToolSearchToolSearchResultBlockParam: BetaToolSearchToolSearchResultBlock) = + content(betaToolSearchToolSearchResultBlockParam.toParam()) + + fun toolUseId(toolUseId: String) = toolUseId(JsonField.of(toolUseId)) + + /** + * Sets [Builder.toolUseId] to an arbitrary JSON value. + * + * You should usually call [Builder.toolUseId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun toolUseId(toolUseId: JsonField) = apply { this.toolUseId = toolUseId } + + /** + * 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("tool_search_tool_result") + * ``` + * + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonValue) = apply { this.type = type } + + /** Create a cache control breakpoint at this content block. */ + fun cacheControl(cacheControl: BetaCacheControlEphemeral?) = + cacheControl(JsonField.ofNullable(cacheControl)) + + /** Alias for calling [Builder.cacheControl] with `cacheControl.orElse(null)`. */ + fun cacheControl(cacheControl: Optional) = + cacheControl(cacheControl.getOrNull()) + + /** + * Sets [Builder.cacheControl] to an arbitrary JSON value. + * + * You should usually call [Builder.cacheControl] with a well-typed + * [BetaCacheControlEphemeral] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun cacheControl(cacheControl: JsonField) = apply { + this.cacheControl = cacheControl + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [BetaToolSearchToolResultBlockParam]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .content() + * .toolUseId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaToolSearchToolResultBlockParam = + BetaToolSearchToolResultBlockParam( + checkRequired("content", content), + checkRequired("toolUseId", toolUseId), + type, + cacheControl, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BetaToolSearchToolResultBlockParam = apply { + if (validated) { + return@apply + } + + content().validate() + toolUseId() + _type().let { + if (it != JsonValue.from("tool_search_tool_result")) { + throw AnthropicInvalidDataException("'type' is invalid, received $it") + } + } + cacheControl().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 = + (content.asKnown().getOrNull()?.validity() ?: 0) + + (if (toolUseId.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("tool_search_tool_result")) 1 else 0 } + + (cacheControl.asKnown().getOrNull()?.validity() ?: 0) + + @JsonDeserialize(using = Content.Deserializer::class) + @JsonSerialize(using = Content.Serializer::class) + class Content + private constructor( + private val betaToolSearchToolResultErrorParam: BetaToolSearchToolResultErrorParam? = null, + private val betaToolSearchToolSearchResultBlockParam: + BetaToolSearchToolSearchResultBlockParam? = + null, + private val _json: JsonValue? = null, + ) { + + fun betaToolSearchToolResultErrorParam(): Optional = + Optional.ofNullable(betaToolSearchToolResultErrorParam) + + fun betaToolSearchToolSearchResultBlockParam(): + Optional = + Optional.ofNullable(betaToolSearchToolSearchResultBlockParam) + + fun isBetaToolSearchToolResultErrorParam(): Boolean = + betaToolSearchToolResultErrorParam != null + + fun isBetaToolSearchToolSearchResultBlockParam(): Boolean = + betaToolSearchToolSearchResultBlockParam != null + + fun asBetaToolSearchToolResultErrorParam(): BetaToolSearchToolResultErrorParam = + betaToolSearchToolResultErrorParam.getOrThrow("betaToolSearchToolResultErrorParam") + + fun asBetaToolSearchToolSearchResultBlockParam(): BetaToolSearchToolSearchResultBlockParam = + betaToolSearchToolSearchResultBlockParam.getOrThrow( + "betaToolSearchToolSearchResultBlockParam" + ) + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + betaToolSearchToolResultErrorParam != null -> + visitor.visitBetaToolSearchToolResultErrorParam( + betaToolSearchToolResultErrorParam + ) + betaToolSearchToolSearchResultBlockParam != null -> + visitor.visitBetaToolSearchToolSearchResultBlockParam( + betaToolSearchToolSearchResultBlockParam + ) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Content = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitBetaToolSearchToolResultErrorParam( + betaToolSearchToolResultErrorParam: BetaToolSearchToolResultErrorParam + ) { + betaToolSearchToolResultErrorParam.validate() + } + + override fun visitBetaToolSearchToolSearchResultBlockParam( + betaToolSearchToolSearchResultBlockParam: + BetaToolSearchToolSearchResultBlockParam + ) { + betaToolSearchToolSearchResultBlockParam.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 visitBetaToolSearchToolResultErrorParam( + betaToolSearchToolResultErrorParam: BetaToolSearchToolResultErrorParam + ) = betaToolSearchToolResultErrorParam.validity() + + override fun visitBetaToolSearchToolSearchResultBlockParam( + betaToolSearchToolSearchResultBlockParam: + BetaToolSearchToolSearchResultBlockParam + ) = betaToolSearchToolSearchResultBlockParam.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Content && + betaToolSearchToolResultErrorParam == other.betaToolSearchToolResultErrorParam && + betaToolSearchToolSearchResultBlockParam == + other.betaToolSearchToolSearchResultBlockParam + } + + override fun hashCode(): Int = + Objects.hash( + betaToolSearchToolResultErrorParam, + betaToolSearchToolSearchResultBlockParam, + ) + + override fun toString(): String = + when { + betaToolSearchToolResultErrorParam != null -> + "Content{betaToolSearchToolResultErrorParam=$betaToolSearchToolResultErrorParam}" + betaToolSearchToolSearchResultBlockParam != null -> + "Content{betaToolSearchToolSearchResultBlockParam=$betaToolSearchToolSearchResultBlockParam}" + _json != null -> "Content{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Content") + } + + companion object { + + @JvmStatic + fun ofBetaToolSearchToolResultErrorParam( + betaToolSearchToolResultErrorParam: BetaToolSearchToolResultErrorParam + ) = Content(betaToolSearchToolResultErrorParam = betaToolSearchToolResultErrorParam) + + @JvmStatic + fun ofBetaToolSearchToolSearchResultBlockParam( + betaToolSearchToolSearchResultBlockParam: BetaToolSearchToolSearchResultBlockParam + ) = + Content( + betaToolSearchToolSearchResultBlockParam = + betaToolSearchToolSearchResultBlockParam + ) + } + + /** + * An interface that defines how to map each variant of [Content] to a value of type [T]. + */ + interface Visitor { + + fun visitBetaToolSearchToolResultErrorParam( + betaToolSearchToolResultErrorParam: BetaToolSearchToolResultErrorParam + ): T + + fun visitBetaToolSearchToolSearchResultBlockParam( + betaToolSearchToolSearchResultBlockParam: BetaToolSearchToolSearchResultBlockParam + ): 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 bestMatches = + sequenceOf( + tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + Content(betaToolSearchToolResultErrorParam = it, _json = json) + }, + tryDeserialize( + node, + jacksonTypeRef(), + ) + ?.let { + Content( + betaToolSearchToolSearchResultBlockParam = 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 -> Content(_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(Content::class) { + + override fun serialize( + value: Content, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.betaToolSearchToolResultErrorParam != null -> + generator.writeObject(value.betaToolSearchToolResultErrorParam) + value.betaToolSearchToolSearchResultBlockParam != null -> + generator.writeObject(value.betaToolSearchToolSearchResultBlockParam) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Content") + } + } + } + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaToolSearchToolResultBlockParam && + content == other.content && + toolUseId == other.toolUseId && + type == other.type && + cacheControl == other.cacheControl && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(content, toolUseId, type, cacheControl, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaToolSearchToolResultBlockParam{content=$content, toolUseId=$toolUseId, type=$type, cacheControl=$cacheControl, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolResultError.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolResultError.kt new file mode 100644 index 000000000..47df9e2c3 --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolResultError.kt @@ -0,0 +1,409 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 + +class BetaToolSearchToolResultError +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val errorCode: JsonField, + private val errorMessage: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("error_code") + @ExcludeMissing + errorCode: JsonField = JsonMissing.of(), + @JsonProperty("error_message") + @ExcludeMissing + errorMessage: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(errorCode, errorMessage, type, mutableMapOf()) + + fun toParam(): BetaToolSearchToolResultErrorParam = + BetaToolSearchToolResultErrorParam.builder() + .errorCode( + _errorCode().map { BetaToolSearchToolResultErrorParam.ErrorCode.of(it.toString()) } + ) + .build() + + /** + * @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 errorCode(): ErrorCode = errorCode.getRequired("error_code") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun errorMessage(): Optional = errorMessage.getOptional("error_message") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("tool_search_tool_result_error") + * ``` + * + * 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 [errorCode]. + * + * Unlike [errorCode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("error_code") @ExcludeMissing fun _errorCode(): JsonField = errorCode + + /** + * Returns the raw JSON value of [errorMessage]. + * + * Unlike [errorMessage], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("error_message") + @ExcludeMissing + fun _errorMessage(): JsonField = errorMessage + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [BetaToolSearchToolResultError]. + * + * The following fields are required: + * ```java + * .errorCode() + * .errorMessage() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaToolSearchToolResultError]. */ + class Builder internal constructor() { + + private var errorCode: JsonField? = null + private var errorMessage: JsonField? = null + private var type: JsonValue = JsonValue.from("tool_search_tool_result_error") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaToolSearchToolResultError: BetaToolSearchToolResultError) = apply { + errorCode = betaToolSearchToolResultError.errorCode + errorMessage = betaToolSearchToolResultError.errorMessage + type = betaToolSearchToolResultError.type + additionalProperties = betaToolSearchToolResultError.additionalProperties.toMutableMap() + } + + fun errorCode(errorCode: ErrorCode) = errorCode(JsonField.of(errorCode)) + + /** + * Sets [Builder.errorCode] to an arbitrary JSON value. + * + * You should usually call [Builder.errorCode] with a well-typed [ErrorCode] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun errorCode(errorCode: JsonField) = apply { this.errorCode = errorCode } + + fun errorMessage(errorMessage: String?) = errorMessage(JsonField.ofNullable(errorMessage)) + + /** Alias for calling [Builder.errorMessage] with `errorMessage.orElse(null)`. */ + fun errorMessage(errorMessage: Optional) = errorMessage(errorMessage.getOrNull()) + + /** + * Sets [Builder.errorMessage] to an arbitrary JSON value. + * + * You should usually call [Builder.errorMessage] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun errorMessage(errorMessage: JsonField) = apply { + this.errorMessage = errorMessage + } + + /** + * 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("tool_search_tool_result_error") + * ``` + * + * 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 [BetaToolSearchToolResultError]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .errorCode() + * .errorMessage() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaToolSearchToolResultError = + BetaToolSearchToolResultError( + checkRequired("errorCode", errorCode), + checkRequired("errorMessage", errorMessage), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BetaToolSearchToolResultError = apply { + if (validated) { + return@apply + } + + errorCode().validate() + errorMessage() + _type().let { + if (it != JsonValue.from("tool_search_tool_result_error")) { + 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 = + (errorCode.asKnown().getOrNull()?.validity() ?: 0) + + (if (errorMessage.asKnown().isPresent) 1 else 0) + + type.let { if (it == JsonValue.from("tool_search_tool_result_error")) 1 else 0 } + + class ErrorCode @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 INVALID_TOOL_INPUT = of("invalid_tool_input") + + @JvmField val UNAVAILABLE = of("unavailable") + + @JvmField val TOO_MANY_REQUESTS = of("too_many_requests") + + @JvmField val EXECUTION_TIME_EXCEEDED = of("execution_time_exceeded") + + @JvmStatic fun of(value: String) = ErrorCode(JsonField.of(value)) + } + + /** An enum containing [ErrorCode]'s known values. */ + enum class Known { + INVALID_TOOL_INPUT, + UNAVAILABLE, + TOO_MANY_REQUESTS, + EXECUTION_TIME_EXCEEDED, + } + + /** + * An enum containing [ErrorCode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [ErrorCode] 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 { + INVALID_TOOL_INPUT, + UNAVAILABLE, + TOO_MANY_REQUESTS, + EXECUTION_TIME_EXCEEDED, + /** + * An enum member indicating that [ErrorCode] 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) { + INVALID_TOOL_INPUT -> Value.INVALID_TOOL_INPUT + UNAVAILABLE -> Value.UNAVAILABLE + TOO_MANY_REQUESTS -> Value.TOO_MANY_REQUESTS + EXECUTION_TIME_EXCEEDED -> Value.EXECUTION_TIME_EXCEEDED + 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) { + INVALID_TOOL_INPUT -> Known.INVALID_TOOL_INPUT + UNAVAILABLE -> Known.UNAVAILABLE + TOO_MANY_REQUESTS -> Known.TOO_MANY_REQUESTS + EXECUTION_TIME_EXCEEDED -> Known.EXECUTION_TIME_EXCEEDED + else -> throw AnthropicInvalidDataException("Unknown ErrorCode: $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 + + fun validate(): ErrorCode = 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 ErrorCode && 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 BetaToolSearchToolResultError && + errorCode == other.errorCode && + errorMessage == other.errorMessage && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(errorCode, errorMessage, type, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaToolSearchToolResultError{errorCode=$errorCode, errorMessage=$errorMessage, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolResultErrorParam.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolResultErrorParam.kt new file mode 100644 index 000000000..f0794876c --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolResultErrorParam.kt @@ -0,0 +1,358 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 + +class BetaToolSearchToolResultErrorParam +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val errorCode: JsonField, + private val type: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("error_code") + @ExcludeMissing + errorCode: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(errorCode, 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 errorCode(): ErrorCode = errorCode.getRequired("error_code") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("tool_search_tool_result_error") + * ``` + * + * 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 [errorCode]. + * + * Unlike [errorCode], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("error_code") @ExcludeMissing fun _errorCode(): JsonField = errorCode + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [BetaToolSearchToolResultErrorParam]. + * + * The following fields are required: + * ```java + * .errorCode() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaToolSearchToolResultErrorParam]. */ + class Builder internal constructor() { + + private var errorCode: JsonField? = null + private var type: JsonValue = JsonValue.from("tool_search_tool_result_error") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(betaToolSearchToolResultErrorParam: BetaToolSearchToolResultErrorParam) = + apply { + errorCode = betaToolSearchToolResultErrorParam.errorCode + type = betaToolSearchToolResultErrorParam.type + additionalProperties = + betaToolSearchToolResultErrorParam.additionalProperties.toMutableMap() + } + + fun errorCode(errorCode: ErrorCode) = errorCode(JsonField.of(errorCode)) + + /** + * Sets [Builder.errorCode] to an arbitrary JSON value. + * + * You should usually call [Builder.errorCode] with a well-typed [ErrorCode] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun errorCode(errorCode: JsonField) = apply { this.errorCode = errorCode } + + /** + * 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("tool_search_tool_result_error") + * ``` + * + * 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 [BetaToolSearchToolResultErrorParam]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .errorCode() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaToolSearchToolResultErrorParam = + BetaToolSearchToolResultErrorParam( + checkRequired("errorCode", errorCode), + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BetaToolSearchToolResultErrorParam = apply { + if (validated) { + return@apply + } + + errorCode().validate() + _type().let { + if (it != JsonValue.from("tool_search_tool_result_error")) { + 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 = + (errorCode.asKnown().getOrNull()?.validity() ?: 0) + + type.let { if (it == JsonValue.from("tool_search_tool_result_error")) 1 else 0 } + + class ErrorCode @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 INVALID_TOOL_INPUT = of("invalid_tool_input") + + @JvmField val UNAVAILABLE = of("unavailable") + + @JvmField val TOO_MANY_REQUESTS = of("too_many_requests") + + @JvmField val EXECUTION_TIME_EXCEEDED = of("execution_time_exceeded") + + @JvmStatic fun of(value: String) = ErrorCode(JsonField.of(value)) + } + + /** An enum containing [ErrorCode]'s known values. */ + enum class Known { + INVALID_TOOL_INPUT, + UNAVAILABLE, + TOO_MANY_REQUESTS, + EXECUTION_TIME_EXCEEDED, + } + + /** + * An enum containing [ErrorCode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [ErrorCode] 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 { + INVALID_TOOL_INPUT, + UNAVAILABLE, + TOO_MANY_REQUESTS, + EXECUTION_TIME_EXCEEDED, + /** + * An enum member indicating that [ErrorCode] 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) { + INVALID_TOOL_INPUT -> Value.INVALID_TOOL_INPUT + UNAVAILABLE -> Value.UNAVAILABLE + TOO_MANY_REQUESTS -> Value.TOO_MANY_REQUESTS + EXECUTION_TIME_EXCEEDED -> Value.EXECUTION_TIME_EXCEEDED + 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) { + INVALID_TOOL_INPUT -> Known.INVALID_TOOL_INPUT + UNAVAILABLE -> Known.UNAVAILABLE + TOO_MANY_REQUESTS -> Known.TOO_MANY_REQUESTS + EXECUTION_TIME_EXCEEDED -> Known.EXECUTION_TIME_EXCEEDED + else -> throw AnthropicInvalidDataException("Unknown ErrorCode: $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 + + fun validate(): ErrorCode = 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 ErrorCode && 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 BetaToolSearchToolResultErrorParam && + errorCode == other.errorCode && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(errorCode, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaToolSearchToolResultErrorParam{errorCode=$errorCode, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolSearchResultBlock.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolSearchResultBlock.kt new file mode 100644 index 000000000..0332daeea --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolSearchResultBlock.kt @@ -0,0 +1,243 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 + +class BetaToolSearchToolSearchResultBlock +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val toolReferences: JsonField>, + private val type: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("tool_references") + @ExcludeMissing + toolReferences: JsonField> = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(toolReferences, type, mutableMapOf()) + + fun toParam(): BetaToolSearchToolSearchResultBlockParam = + BetaToolSearchToolSearchResultBlockParam.builder() + .toolReferences(_toolReferences().map { it.map { it.toParam() } }) + .build() + + /** + * @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 toolReferences(): List = + toolReferences.getRequired("tool_references") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("tool_search_tool_search_result") + * ``` + * + * 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 [toolReferences]. + * + * Unlike [toolReferences], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tool_references") + @ExcludeMissing + fun _toolReferences(): JsonField> = toolReferences + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [BetaToolSearchToolSearchResultBlock]. + * + * The following fields are required: + * ```java + * .toolReferences() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaToolSearchToolSearchResultBlock]. */ + class Builder internal constructor() { + + private var toolReferences: JsonField>? = null + private var type: JsonValue = JsonValue.from("tool_search_tool_search_result") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaToolSearchToolSearchResultBlock: BetaToolSearchToolSearchResultBlock + ) = apply { + toolReferences = + betaToolSearchToolSearchResultBlock.toolReferences.map { it.toMutableList() } + type = betaToolSearchToolSearchResultBlock.type + additionalProperties = + betaToolSearchToolSearchResultBlock.additionalProperties.toMutableMap() + } + + fun toolReferences(toolReferences: List) = + toolReferences(JsonField.of(toolReferences)) + + /** + * Sets [Builder.toolReferences] to an arbitrary JSON value. + * + * You should usually call [Builder.toolReferences] with a well-typed + * `List` value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun toolReferences(toolReferences: JsonField>) = apply { + this.toolReferences = toolReferences.map { it.toMutableList() } + } + + /** + * Adds a single [BetaToolReferenceBlock] to [toolReferences]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addToolReference(toolReference: BetaToolReferenceBlock) = apply { + toolReferences = + (toolReferences ?: JsonField.of(mutableListOf())).also { + checkKnown("toolReferences", it).add(toolReference) + } + } + + /** + * 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("tool_search_tool_search_result") + * ``` + * + * 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 [BetaToolSearchToolSearchResultBlock]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .toolReferences() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaToolSearchToolSearchResultBlock = + BetaToolSearchToolSearchResultBlock( + checkRequired("toolReferences", toolReferences).map { it.toImmutable() }, + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BetaToolSearchToolSearchResultBlock = apply { + if (validated) { + return@apply + } + + toolReferences().forEach { it.validate() } + _type().let { + if (it != JsonValue.from("tool_search_tool_search_result")) { + 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 = + (toolReferences.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + type.let { if (it == JsonValue.from("tool_search_tool_search_result")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaToolSearchToolSearchResultBlock && + toolReferences == other.toolReferences && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(toolReferences, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaToolSearchToolSearchResultBlock{toolReferences=$toolReferences, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolSearchResultBlockParam.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolSearchResultBlockParam.kt new file mode 100644 index 000000000..52b5b101d --- /dev/null +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolSearchResultBlockParam.kt @@ -0,0 +1,242 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 + +class BetaToolSearchToolSearchResultBlockParam +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val toolReferences: JsonField>, + private val type: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("tool_references") + @ExcludeMissing + toolReferences: JsonField> = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + ) : this(toolReferences, 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 toolReferences(): List = + toolReferences.getRequired("tool_references") + + /** + * Expected to always return the following: + * ```java + * JsonValue.from("tool_search_tool_search_result") + * ``` + * + * 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 [toolReferences]. + * + * Unlike [toolReferences], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("tool_references") + @ExcludeMissing + fun _toolReferences(): JsonField> = toolReferences + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of + * [BetaToolSearchToolSearchResultBlockParam]. + * + * The following fields are required: + * ```java + * .toolReferences() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BetaToolSearchToolSearchResultBlockParam]. */ + class Builder internal constructor() { + + private var toolReferences: JsonField>? = null + private var type: JsonValue = JsonValue.from("tool_search_tool_search_result") + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from( + betaToolSearchToolSearchResultBlockParam: BetaToolSearchToolSearchResultBlockParam + ) = apply { + toolReferences = + betaToolSearchToolSearchResultBlockParam.toolReferences.map { it.toMutableList() } + type = betaToolSearchToolSearchResultBlockParam.type + additionalProperties = + betaToolSearchToolSearchResultBlockParam.additionalProperties.toMutableMap() + } + + fun toolReferences(toolReferences: List) = + toolReferences(JsonField.of(toolReferences)) + + /** + * Sets [Builder.toolReferences] to an arbitrary JSON value. + * + * You should usually call [Builder.toolReferences] with a well-typed + * `List` value instead. This method is primarily for setting + * the field to an undocumented or not yet supported value. + */ + fun toolReferences(toolReferences: JsonField>) = apply { + this.toolReferences = toolReferences.map { it.toMutableList() } + } + + /** + * Adds a single [BetaToolReferenceBlockParam] to [toolReferences]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addToolReference(toolReference: BetaToolReferenceBlockParam) = apply { + toolReferences = + (toolReferences ?: JsonField.of(mutableListOf())).also { + checkKnown("toolReferences", it).add(toolReference) + } + } + + /** Alias for calling [addToolReference] with `toolReference.toParam()`. */ + fun addToolReference(toolReference: BetaToolReferenceBlock) = + addToolReference(toolReference.toParam()) + + /** + * 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("tool_search_tool_search_result") + * ``` + * + * 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 [BetaToolSearchToolSearchResultBlockParam]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .toolReferences() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BetaToolSearchToolSearchResultBlockParam = + BetaToolSearchToolSearchResultBlockParam( + checkRequired("toolReferences", toolReferences).map { it.toImmutable() }, + type, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): BetaToolSearchToolSearchResultBlockParam = apply { + if (validated) { + return@apply + } + + toolReferences().forEach { it.validate() } + _type().let { + if (it != JsonValue.from("tool_search_tool_search_result")) { + 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 = + (toolReferences.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + type.let { if (it == JsonValue.from("tool_search_tool_search_result")) 1 else 0 } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BetaToolSearchToolSearchResultBlockParam && + toolReferences == other.toolReferences && + type == other.type && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(toolReferences, type, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BetaToolSearchToolSearchResultBlockParam{toolReferences=$toolReferences, type=$type, additionalProperties=$additionalProperties}" +} diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20241022.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20241022.kt index 7bca63f57..c4990789d 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20241022.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20241022.kt @@ -2,10 +2,13 @@ package com.anthropic.models.beta.messages +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.toImmutable import com.anthropic.errors.AnthropicInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -21,7 +24,10 @@ class BetaToolTextEditor20241022 private constructor( private val name: JsonValue, private val type: JsonValue, + private val allowedCallers: JsonField>, private val cacheControl: JsonField, + private val deferLoading: JsonField, + private val inputExamples: JsonField>, private val strict: JsonField, private val additionalProperties: MutableMap, ) { @@ -30,11 +36,29 @@ private constructor( private constructor( @JsonProperty("name") @ExcludeMissing name: JsonValue = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("allowed_callers") + @ExcludeMissing + allowedCallers: JsonField> = JsonMissing.of(), @JsonProperty("cache_control") @ExcludeMissing cacheControl: JsonField = JsonMissing.of(), + @JsonProperty("defer_loading") + @ExcludeMissing + deferLoading: JsonField = JsonMissing.of(), + @JsonProperty("input_examples") + @ExcludeMissing + inputExamples: JsonField> = JsonMissing.of(), @JsonProperty("strict") @ExcludeMissing strict: JsonField = JsonMissing.of(), - ) : this(name, type, cacheControl, strict, mutableMapOf()) + ) : this( + name, + type, + allowedCallers, + cacheControl, + deferLoading, + inputExamples, + strict, + mutableMapOf(), + ) /** * Name of the tool. @@ -62,6 +86,13 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun allowedCallers(): Optional> = + allowedCallers.getOptional("allowed_callers") + /** * Create a cache control breakpoint at this content block. * @@ -71,12 +102,36 @@ private constructor( fun cacheControl(): Optional = cacheControl.getOptional("cache_control") + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned via + * tool_reference from tool search. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun deferLoading(): Optional = deferLoading.getOptional("defer_loading") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun inputExamples(): Optional> = inputExamples.getOptional("input_examples") + /** * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ fun strict(): Optional = strict.getOptional("strict") + /** + * Returns the raw JSON value of [allowedCallers]. + * + * Unlike [allowedCallers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("allowed_callers") + @ExcludeMissing + fun _allowedCallers(): JsonField> = allowedCallers + /** * Returns the raw JSON value of [cacheControl]. * @@ -86,6 +141,24 @@ private constructor( @ExcludeMissing fun _cacheControl(): JsonField = cacheControl + /** + * Returns the raw JSON value of [deferLoading]. + * + * Unlike [deferLoading], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("defer_loading") + @ExcludeMissing + fun _deferLoading(): JsonField = deferLoading + + /** + * Returns the raw JSON value of [inputExamples]. + * + * Unlike [inputExamples], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("input_examples") + @ExcludeMissing + fun _inputExamples(): JsonField> = inputExamples + /** * Returns the raw JSON value of [strict]. * @@ -118,7 +191,10 @@ private constructor( private var name: JsonValue = JsonValue.from("str_replace_editor") private var type: JsonValue = JsonValue.from("text_editor_20241022") + private var allowedCallers: JsonField>? = null private var cacheControl: JsonField = JsonMissing.of() + private var deferLoading: JsonField = JsonMissing.of() + private var inputExamples: JsonField>? = null private var strict: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -126,7 +202,10 @@ private constructor( internal fun from(betaToolTextEditor20241022: BetaToolTextEditor20241022) = apply { name = betaToolTextEditor20241022.name type = betaToolTextEditor20241022.type + allowedCallers = betaToolTextEditor20241022.allowedCallers.map { it.toMutableList() } cacheControl = betaToolTextEditor20241022.cacheControl + deferLoading = betaToolTextEditor20241022.deferLoading + inputExamples = betaToolTextEditor20241022.inputExamples.map { it.toMutableList() } strict = betaToolTextEditor20241022.strict additionalProperties = betaToolTextEditor20241022.additionalProperties.toMutableMap() } @@ -159,6 +238,32 @@ private constructor( */ fun type(type: JsonValue) = apply { this.type = type } + fun allowedCallers(allowedCallers: List) = + allowedCallers(JsonField.of(allowedCallers)) + + /** + * Sets [Builder.allowedCallers] to an arbitrary JSON value. + * + * You should usually call [Builder.allowedCallers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun allowedCallers(allowedCallers: JsonField>) = apply { + this.allowedCallers = allowedCallers.map { it.toMutableList() } + } + + /** + * Adds a single [AllowedCaller] to [allowedCallers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAllowedCaller(allowedCaller: AllowedCaller) = apply { + allowedCallers = + (allowedCallers ?: JsonField.of(mutableListOf())).also { + checkKnown("allowedCallers", it).add(allowedCaller) + } + } + /** Create a cache control breakpoint at this content block. */ fun cacheControl(cacheControl: BetaCacheControlEphemeral?) = cacheControl(JsonField.ofNullable(cacheControl)) @@ -178,6 +283,49 @@ private constructor( this.cacheControl = cacheControl } + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned + * via tool_reference from tool search. + */ + fun deferLoading(deferLoading: Boolean) = deferLoading(JsonField.of(deferLoading)) + + /** + * Sets [Builder.deferLoading] to an arbitrary JSON value. + * + * You should usually call [Builder.deferLoading] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun deferLoading(deferLoading: JsonField) = apply { + this.deferLoading = deferLoading + } + + fun inputExamples(inputExamples: List) = + inputExamples(JsonField.of(inputExamples)) + + /** + * Sets [Builder.inputExamples] to an arbitrary JSON value. + * + * You should usually call [Builder.inputExamples] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun inputExamples(inputExamples: JsonField>) = apply { + this.inputExamples = inputExamples.map { it.toMutableList() } + } + + /** + * Adds a single [InputExample] to [inputExamples]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addInputExample(inputExample: InputExample) = apply { + inputExamples = + (inputExamples ?: JsonField.of(mutableListOf())).also { + checkKnown("inputExamples", it).add(inputExample) + } + } + fun strict(strict: Boolean) = strict(JsonField.of(strict)) /** @@ -216,7 +364,10 @@ private constructor( BetaToolTextEditor20241022( name, type, + (allowedCallers ?: JsonMissing.of()).map { it.toImmutable() }, cacheControl, + deferLoading, + (inputExamples ?: JsonMissing.of()).map { it.toImmutable() }, strict, additionalProperties.toMutableMap(), ) @@ -239,7 +390,10 @@ private constructor( throw AnthropicInvalidDataException("'type' is invalid, received $it") } } + allowedCallers().ifPresent { it.forEach { it.validate() } } cacheControl().ifPresent { it.validate() } + deferLoading() + inputExamples().ifPresent { it.forEach { it.validate() } } strict() validated = true } @@ -261,9 +415,242 @@ private constructor( internal fun validity(): Int = name.let { if (it == JsonValue.from("str_replace_editor")) 1 else 0 } + type.let { if (it == JsonValue.from("text_editor_20241022")) 1 else 0 } + + (allowedCallers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (cacheControl.asKnown().getOrNull()?.validity() ?: 0) + + (if (deferLoading.asKnown().isPresent) 1 else 0) + + (inputExamples.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (strict.asKnown().isPresent) 1 else 0) + class AllowedCaller @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 DIRECT = of("direct") + + @JvmField val CODE_EXECUTION_20250825 = of("code_execution_20250825") + + @JvmStatic fun of(value: String) = AllowedCaller(JsonField.of(value)) + } + + /** An enum containing [AllowedCaller]'s known values. */ + enum class Known { + DIRECT, + CODE_EXECUTION_20250825, + } + + /** + * An enum containing [AllowedCaller]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [AllowedCaller] 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 { + DIRECT, + CODE_EXECUTION_20250825, + /** + * An enum member indicating that [AllowedCaller] 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) { + DIRECT -> Value.DIRECT + CODE_EXECUTION_20250825 -> Value.CODE_EXECUTION_20250825 + 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) { + DIRECT -> Known.DIRECT + CODE_EXECUTION_20250825 -> Known.CODE_EXECUTION_20250825 + else -> throw AnthropicInvalidDataException("Unknown AllowedCaller: $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 + + fun validate(): AllowedCaller = 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 AllowedCaller && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class InputExample + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [InputExample]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InputExample]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(inputExample: InputExample) = apply { + additionalProperties = inputExample.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [InputExample]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): InputExample = InputExample(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): InputExample = apply { + if (validated) { + return@apply + } + + 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 = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InputExample && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "InputExample{additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -272,17 +659,29 @@ private constructor( return other is BetaToolTextEditor20241022 && name == other.name && type == other.type && + allowedCallers == other.allowedCallers && cacheControl == other.cacheControl && + deferLoading == other.deferLoading && + inputExamples == other.inputExamples && strict == other.strict && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(name, type, cacheControl, strict, additionalProperties) + Objects.hash( + name, + type, + allowedCallers, + cacheControl, + deferLoading, + inputExamples, + strict, + additionalProperties, + ) } override fun hashCode(): Int = hashCode override fun toString() = - "BetaToolTextEditor20241022{name=$name, type=$type, cacheControl=$cacheControl, strict=$strict, additionalProperties=$additionalProperties}" + "BetaToolTextEditor20241022{name=$name, type=$type, allowedCallers=$allowedCallers, cacheControl=$cacheControl, deferLoading=$deferLoading, inputExamples=$inputExamples, strict=$strict, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20250124.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20250124.kt index cdc99caf4..0cdb91af5 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20250124.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20250124.kt @@ -2,10 +2,13 @@ package com.anthropic.models.beta.messages +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.toImmutable import com.anthropic.errors.AnthropicInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -21,7 +24,10 @@ class BetaToolTextEditor20250124 private constructor( private val name: JsonValue, private val type: JsonValue, + private val allowedCallers: JsonField>, private val cacheControl: JsonField, + private val deferLoading: JsonField, + private val inputExamples: JsonField>, private val strict: JsonField, private val additionalProperties: MutableMap, ) { @@ -30,11 +36,29 @@ private constructor( private constructor( @JsonProperty("name") @ExcludeMissing name: JsonValue = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("allowed_callers") + @ExcludeMissing + allowedCallers: JsonField> = JsonMissing.of(), @JsonProperty("cache_control") @ExcludeMissing cacheControl: JsonField = JsonMissing.of(), + @JsonProperty("defer_loading") + @ExcludeMissing + deferLoading: JsonField = JsonMissing.of(), + @JsonProperty("input_examples") + @ExcludeMissing + inputExamples: JsonField> = JsonMissing.of(), @JsonProperty("strict") @ExcludeMissing strict: JsonField = JsonMissing.of(), - ) : this(name, type, cacheControl, strict, mutableMapOf()) + ) : this( + name, + type, + allowedCallers, + cacheControl, + deferLoading, + inputExamples, + strict, + mutableMapOf(), + ) /** * Name of the tool. @@ -62,6 +86,13 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun allowedCallers(): Optional> = + allowedCallers.getOptional("allowed_callers") + /** * Create a cache control breakpoint at this content block. * @@ -71,12 +102,36 @@ private constructor( fun cacheControl(): Optional = cacheControl.getOptional("cache_control") + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned via + * tool_reference from tool search. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun deferLoading(): Optional = deferLoading.getOptional("defer_loading") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun inputExamples(): Optional> = inputExamples.getOptional("input_examples") + /** * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ fun strict(): Optional = strict.getOptional("strict") + /** + * Returns the raw JSON value of [allowedCallers]. + * + * Unlike [allowedCallers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("allowed_callers") + @ExcludeMissing + fun _allowedCallers(): JsonField> = allowedCallers + /** * Returns the raw JSON value of [cacheControl]. * @@ -86,6 +141,24 @@ private constructor( @ExcludeMissing fun _cacheControl(): JsonField = cacheControl + /** + * Returns the raw JSON value of [deferLoading]. + * + * Unlike [deferLoading], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("defer_loading") + @ExcludeMissing + fun _deferLoading(): JsonField = deferLoading + + /** + * Returns the raw JSON value of [inputExamples]. + * + * Unlike [inputExamples], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("input_examples") + @ExcludeMissing + fun _inputExamples(): JsonField> = inputExamples + /** * Returns the raw JSON value of [strict]. * @@ -118,7 +191,10 @@ private constructor( private var name: JsonValue = JsonValue.from("str_replace_editor") private var type: JsonValue = JsonValue.from("text_editor_20250124") + private var allowedCallers: JsonField>? = null private var cacheControl: JsonField = JsonMissing.of() + private var deferLoading: JsonField = JsonMissing.of() + private var inputExamples: JsonField>? = null private var strict: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -126,7 +202,10 @@ private constructor( internal fun from(betaToolTextEditor20250124: BetaToolTextEditor20250124) = apply { name = betaToolTextEditor20250124.name type = betaToolTextEditor20250124.type + allowedCallers = betaToolTextEditor20250124.allowedCallers.map { it.toMutableList() } cacheControl = betaToolTextEditor20250124.cacheControl + deferLoading = betaToolTextEditor20250124.deferLoading + inputExamples = betaToolTextEditor20250124.inputExamples.map { it.toMutableList() } strict = betaToolTextEditor20250124.strict additionalProperties = betaToolTextEditor20250124.additionalProperties.toMutableMap() } @@ -159,6 +238,32 @@ private constructor( */ fun type(type: JsonValue) = apply { this.type = type } + fun allowedCallers(allowedCallers: List) = + allowedCallers(JsonField.of(allowedCallers)) + + /** + * Sets [Builder.allowedCallers] to an arbitrary JSON value. + * + * You should usually call [Builder.allowedCallers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun allowedCallers(allowedCallers: JsonField>) = apply { + this.allowedCallers = allowedCallers.map { it.toMutableList() } + } + + /** + * Adds a single [AllowedCaller] to [allowedCallers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAllowedCaller(allowedCaller: AllowedCaller) = apply { + allowedCallers = + (allowedCallers ?: JsonField.of(mutableListOf())).also { + checkKnown("allowedCallers", it).add(allowedCaller) + } + } + /** Create a cache control breakpoint at this content block. */ fun cacheControl(cacheControl: BetaCacheControlEphemeral?) = cacheControl(JsonField.ofNullable(cacheControl)) @@ -178,6 +283,49 @@ private constructor( this.cacheControl = cacheControl } + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned + * via tool_reference from tool search. + */ + fun deferLoading(deferLoading: Boolean) = deferLoading(JsonField.of(deferLoading)) + + /** + * Sets [Builder.deferLoading] to an arbitrary JSON value. + * + * You should usually call [Builder.deferLoading] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun deferLoading(deferLoading: JsonField) = apply { + this.deferLoading = deferLoading + } + + fun inputExamples(inputExamples: List) = + inputExamples(JsonField.of(inputExamples)) + + /** + * Sets [Builder.inputExamples] to an arbitrary JSON value. + * + * You should usually call [Builder.inputExamples] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun inputExamples(inputExamples: JsonField>) = apply { + this.inputExamples = inputExamples.map { it.toMutableList() } + } + + /** + * Adds a single [InputExample] to [inputExamples]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addInputExample(inputExample: InputExample) = apply { + inputExamples = + (inputExamples ?: JsonField.of(mutableListOf())).also { + checkKnown("inputExamples", it).add(inputExample) + } + } + fun strict(strict: Boolean) = strict(JsonField.of(strict)) /** @@ -216,7 +364,10 @@ private constructor( BetaToolTextEditor20250124( name, type, + (allowedCallers ?: JsonMissing.of()).map { it.toImmutable() }, cacheControl, + deferLoading, + (inputExamples ?: JsonMissing.of()).map { it.toImmutable() }, strict, additionalProperties.toMutableMap(), ) @@ -239,7 +390,10 @@ private constructor( throw AnthropicInvalidDataException("'type' is invalid, received $it") } } + allowedCallers().ifPresent { it.forEach { it.validate() } } cacheControl().ifPresent { it.validate() } + deferLoading() + inputExamples().ifPresent { it.forEach { it.validate() } } strict() validated = true } @@ -261,9 +415,242 @@ private constructor( internal fun validity(): Int = name.let { if (it == JsonValue.from("str_replace_editor")) 1 else 0 } + type.let { if (it == JsonValue.from("text_editor_20250124")) 1 else 0 } + + (allowedCallers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (cacheControl.asKnown().getOrNull()?.validity() ?: 0) + + (if (deferLoading.asKnown().isPresent) 1 else 0) + + (inputExamples.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (strict.asKnown().isPresent) 1 else 0) + class AllowedCaller @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 DIRECT = of("direct") + + @JvmField val CODE_EXECUTION_20250825 = of("code_execution_20250825") + + @JvmStatic fun of(value: String) = AllowedCaller(JsonField.of(value)) + } + + /** An enum containing [AllowedCaller]'s known values. */ + enum class Known { + DIRECT, + CODE_EXECUTION_20250825, + } + + /** + * An enum containing [AllowedCaller]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [AllowedCaller] 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 { + DIRECT, + CODE_EXECUTION_20250825, + /** + * An enum member indicating that [AllowedCaller] 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) { + DIRECT -> Value.DIRECT + CODE_EXECUTION_20250825 -> Value.CODE_EXECUTION_20250825 + 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) { + DIRECT -> Known.DIRECT + CODE_EXECUTION_20250825 -> Known.CODE_EXECUTION_20250825 + else -> throw AnthropicInvalidDataException("Unknown AllowedCaller: $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 + + fun validate(): AllowedCaller = 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 AllowedCaller && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class InputExample + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [InputExample]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InputExample]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(inputExample: InputExample) = apply { + additionalProperties = inputExample.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [InputExample]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): InputExample = InputExample(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): InputExample = apply { + if (validated) { + return@apply + } + + 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 = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InputExample && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "InputExample{additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -272,17 +659,29 @@ private constructor( return other is BetaToolTextEditor20250124 && name == other.name && type == other.type && + allowedCallers == other.allowedCallers && cacheControl == other.cacheControl && + deferLoading == other.deferLoading && + inputExamples == other.inputExamples && strict == other.strict && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(name, type, cacheControl, strict, additionalProperties) + Objects.hash( + name, + type, + allowedCallers, + cacheControl, + deferLoading, + inputExamples, + strict, + additionalProperties, + ) } override fun hashCode(): Int = hashCode override fun toString() = - "BetaToolTextEditor20250124{name=$name, type=$type, cacheControl=$cacheControl, strict=$strict, additionalProperties=$additionalProperties}" + "BetaToolTextEditor20250124{name=$name, type=$type, allowedCallers=$allowedCallers, cacheControl=$cacheControl, deferLoading=$deferLoading, inputExamples=$inputExamples, strict=$strict, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20250429.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20250429.kt index e4645b014..b646f8188 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20250429.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20250429.kt @@ -2,10 +2,13 @@ package com.anthropic.models.beta.messages +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.toImmutable import com.anthropic.errors.AnthropicInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -21,7 +24,10 @@ class BetaToolTextEditor20250429 private constructor( private val name: JsonValue, private val type: JsonValue, + private val allowedCallers: JsonField>, private val cacheControl: JsonField, + private val deferLoading: JsonField, + private val inputExamples: JsonField>, private val strict: JsonField, private val additionalProperties: MutableMap, ) { @@ -30,11 +36,29 @@ private constructor( private constructor( @JsonProperty("name") @ExcludeMissing name: JsonValue = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("allowed_callers") + @ExcludeMissing + allowedCallers: JsonField> = JsonMissing.of(), @JsonProperty("cache_control") @ExcludeMissing cacheControl: JsonField = JsonMissing.of(), + @JsonProperty("defer_loading") + @ExcludeMissing + deferLoading: JsonField = JsonMissing.of(), + @JsonProperty("input_examples") + @ExcludeMissing + inputExamples: JsonField> = JsonMissing.of(), @JsonProperty("strict") @ExcludeMissing strict: JsonField = JsonMissing.of(), - ) : this(name, type, cacheControl, strict, mutableMapOf()) + ) : this( + name, + type, + allowedCallers, + cacheControl, + deferLoading, + inputExamples, + strict, + mutableMapOf(), + ) /** * Name of the tool. @@ -62,6 +86,13 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun allowedCallers(): Optional> = + allowedCallers.getOptional("allowed_callers") + /** * Create a cache control breakpoint at this content block. * @@ -71,12 +102,36 @@ private constructor( fun cacheControl(): Optional = cacheControl.getOptional("cache_control") + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned via + * tool_reference from tool search. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun deferLoading(): Optional = deferLoading.getOptional("defer_loading") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun inputExamples(): Optional> = inputExamples.getOptional("input_examples") + /** * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ fun strict(): Optional = strict.getOptional("strict") + /** + * Returns the raw JSON value of [allowedCallers]. + * + * Unlike [allowedCallers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("allowed_callers") + @ExcludeMissing + fun _allowedCallers(): JsonField> = allowedCallers + /** * Returns the raw JSON value of [cacheControl]. * @@ -86,6 +141,24 @@ private constructor( @ExcludeMissing fun _cacheControl(): JsonField = cacheControl + /** + * Returns the raw JSON value of [deferLoading]. + * + * Unlike [deferLoading], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("defer_loading") + @ExcludeMissing + fun _deferLoading(): JsonField = deferLoading + + /** + * Returns the raw JSON value of [inputExamples]. + * + * Unlike [inputExamples], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("input_examples") + @ExcludeMissing + fun _inputExamples(): JsonField> = inputExamples + /** * Returns the raw JSON value of [strict]. * @@ -118,7 +191,10 @@ private constructor( private var name: JsonValue = JsonValue.from("str_replace_based_edit_tool") private var type: JsonValue = JsonValue.from("text_editor_20250429") + private var allowedCallers: JsonField>? = null private var cacheControl: JsonField = JsonMissing.of() + private var deferLoading: JsonField = JsonMissing.of() + private var inputExamples: JsonField>? = null private var strict: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -126,7 +202,10 @@ private constructor( internal fun from(betaToolTextEditor20250429: BetaToolTextEditor20250429) = apply { name = betaToolTextEditor20250429.name type = betaToolTextEditor20250429.type + allowedCallers = betaToolTextEditor20250429.allowedCallers.map { it.toMutableList() } cacheControl = betaToolTextEditor20250429.cacheControl + deferLoading = betaToolTextEditor20250429.deferLoading + inputExamples = betaToolTextEditor20250429.inputExamples.map { it.toMutableList() } strict = betaToolTextEditor20250429.strict additionalProperties = betaToolTextEditor20250429.additionalProperties.toMutableMap() } @@ -159,6 +238,32 @@ private constructor( */ fun type(type: JsonValue) = apply { this.type = type } + fun allowedCallers(allowedCallers: List) = + allowedCallers(JsonField.of(allowedCallers)) + + /** + * Sets [Builder.allowedCallers] to an arbitrary JSON value. + * + * You should usually call [Builder.allowedCallers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun allowedCallers(allowedCallers: JsonField>) = apply { + this.allowedCallers = allowedCallers.map { it.toMutableList() } + } + + /** + * Adds a single [AllowedCaller] to [allowedCallers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAllowedCaller(allowedCaller: AllowedCaller) = apply { + allowedCallers = + (allowedCallers ?: JsonField.of(mutableListOf())).also { + checkKnown("allowedCallers", it).add(allowedCaller) + } + } + /** Create a cache control breakpoint at this content block. */ fun cacheControl(cacheControl: BetaCacheControlEphemeral?) = cacheControl(JsonField.ofNullable(cacheControl)) @@ -178,6 +283,49 @@ private constructor( this.cacheControl = cacheControl } + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned + * via tool_reference from tool search. + */ + fun deferLoading(deferLoading: Boolean) = deferLoading(JsonField.of(deferLoading)) + + /** + * Sets [Builder.deferLoading] to an arbitrary JSON value. + * + * You should usually call [Builder.deferLoading] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun deferLoading(deferLoading: JsonField) = apply { + this.deferLoading = deferLoading + } + + fun inputExamples(inputExamples: List) = + inputExamples(JsonField.of(inputExamples)) + + /** + * Sets [Builder.inputExamples] to an arbitrary JSON value. + * + * You should usually call [Builder.inputExamples] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun inputExamples(inputExamples: JsonField>) = apply { + this.inputExamples = inputExamples.map { it.toMutableList() } + } + + /** + * Adds a single [InputExample] to [inputExamples]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addInputExample(inputExample: InputExample) = apply { + inputExamples = + (inputExamples ?: JsonField.of(mutableListOf())).also { + checkKnown("inputExamples", it).add(inputExample) + } + } + fun strict(strict: Boolean) = strict(JsonField.of(strict)) /** @@ -216,7 +364,10 @@ private constructor( BetaToolTextEditor20250429( name, type, + (allowedCallers ?: JsonMissing.of()).map { it.toImmutable() }, cacheControl, + deferLoading, + (inputExamples ?: JsonMissing.of()).map { it.toImmutable() }, strict, additionalProperties.toMutableMap(), ) @@ -239,7 +390,10 @@ private constructor( throw AnthropicInvalidDataException("'type' is invalid, received $it") } } + allowedCallers().ifPresent { it.forEach { it.validate() } } cacheControl().ifPresent { it.validate() } + deferLoading() + inputExamples().ifPresent { it.forEach { it.validate() } } strict() validated = true } @@ -261,9 +415,242 @@ private constructor( internal fun validity(): Int = name.let { if (it == JsonValue.from("str_replace_based_edit_tool")) 1 else 0 } + type.let { if (it == JsonValue.from("text_editor_20250429")) 1 else 0 } + + (allowedCallers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (cacheControl.asKnown().getOrNull()?.validity() ?: 0) + + (if (deferLoading.asKnown().isPresent) 1 else 0) + + (inputExamples.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (strict.asKnown().isPresent) 1 else 0) + class AllowedCaller @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 DIRECT = of("direct") + + @JvmField val CODE_EXECUTION_20250825 = of("code_execution_20250825") + + @JvmStatic fun of(value: String) = AllowedCaller(JsonField.of(value)) + } + + /** An enum containing [AllowedCaller]'s known values. */ + enum class Known { + DIRECT, + CODE_EXECUTION_20250825, + } + + /** + * An enum containing [AllowedCaller]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [AllowedCaller] 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 { + DIRECT, + CODE_EXECUTION_20250825, + /** + * An enum member indicating that [AllowedCaller] 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) { + DIRECT -> Value.DIRECT + CODE_EXECUTION_20250825 -> Value.CODE_EXECUTION_20250825 + 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) { + DIRECT -> Known.DIRECT + CODE_EXECUTION_20250825 -> Known.CODE_EXECUTION_20250825 + else -> throw AnthropicInvalidDataException("Unknown AllowedCaller: $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 + + fun validate(): AllowedCaller = 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 AllowedCaller && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class InputExample + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [InputExample]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InputExample]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(inputExample: InputExample) = apply { + additionalProperties = inputExample.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [InputExample]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): InputExample = InputExample(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): InputExample = apply { + if (validated) { + return@apply + } + + 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 = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InputExample && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "InputExample{additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -272,17 +659,29 @@ private constructor( return other is BetaToolTextEditor20250429 && name == other.name && type == other.type && + allowedCallers == other.allowedCallers && cacheControl == other.cacheControl && + deferLoading == other.deferLoading && + inputExamples == other.inputExamples && strict == other.strict && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(name, type, cacheControl, strict, additionalProperties) + Objects.hash( + name, + type, + allowedCallers, + cacheControl, + deferLoading, + inputExamples, + strict, + additionalProperties, + ) } override fun hashCode(): Int = hashCode override fun toString() = - "BetaToolTextEditor20250429{name=$name, type=$type, cacheControl=$cacheControl, strict=$strict, additionalProperties=$additionalProperties}" + "BetaToolTextEditor20250429{name=$name, type=$type, allowedCallers=$allowedCallers, cacheControl=$cacheControl, deferLoading=$deferLoading, inputExamples=$inputExamples, strict=$strict, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20250728.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20250728.kt index fe440931f..40458cd17 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20250728.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20250728.kt @@ -2,10 +2,13 @@ package com.anthropic.models.beta.messages +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.toImmutable import com.anthropic.errors.AnthropicInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter @@ -21,7 +24,10 @@ class BetaToolTextEditor20250728 private constructor( private val name: JsonValue, private val type: JsonValue, + private val allowedCallers: JsonField>, private val cacheControl: JsonField, + private val deferLoading: JsonField, + private val inputExamples: JsonField>, private val maxCharacters: JsonField, private val strict: JsonField, private val additionalProperties: MutableMap, @@ -31,14 +37,33 @@ private constructor( private constructor( @JsonProperty("name") @ExcludeMissing name: JsonValue = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("allowed_callers") + @ExcludeMissing + allowedCallers: JsonField> = JsonMissing.of(), @JsonProperty("cache_control") @ExcludeMissing cacheControl: JsonField = JsonMissing.of(), + @JsonProperty("defer_loading") + @ExcludeMissing + deferLoading: JsonField = JsonMissing.of(), + @JsonProperty("input_examples") + @ExcludeMissing + inputExamples: JsonField> = JsonMissing.of(), @JsonProperty("max_characters") @ExcludeMissing maxCharacters: JsonField = JsonMissing.of(), @JsonProperty("strict") @ExcludeMissing strict: JsonField = JsonMissing.of(), - ) : this(name, type, cacheControl, maxCharacters, strict, mutableMapOf()) + ) : this( + name, + type, + allowedCallers, + cacheControl, + deferLoading, + inputExamples, + maxCharacters, + strict, + mutableMapOf(), + ) /** * Name of the tool. @@ -66,6 +91,13 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun allowedCallers(): Optional> = + allowedCallers.getOptional("allowed_callers") + /** * Create a cache control breakpoint at this content block. * @@ -75,6 +107,21 @@ private constructor( fun cacheControl(): Optional = cacheControl.getOptional("cache_control") + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned via + * tool_reference from tool search. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun deferLoading(): Optional = deferLoading.getOptional("defer_loading") + + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun inputExamples(): Optional> = inputExamples.getOptional("input_examples") + /** * Maximum number of characters to display when viewing a file. If not specified, defaults to * displaying the full file. @@ -90,6 +137,15 @@ private constructor( */ fun strict(): Optional = strict.getOptional("strict") + /** + * Returns the raw JSON value of [allowedCallers]. + * + * Unlike [allowedCallers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("allowed_callers") + @ExcludeMissing + fun _allowedCallers(): JsonField> = allowedCallers + /** * Returns the raw JSON value of [cacheControl]. * @@ -99,6 +155,24 @@ private constructor( @ExcludeMissing fun _cacheControl(): JsonField = cacheControl + /** + * Returns the raw JSON value of [deferLoading]. + * + * Unlike [deferLoading], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("defer_loading") + @ExcludeMissing + fun _deferLoading(): JsonField = deferLoading + + /** + * Returns the raw JSON value of [inputExamples]. + * + * Unlike [inputExamples], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("input_examples") + @ExcludeMissing + fun _inputExamples(): JsonField> = inputExamples + /** * Returns the raw JSON value of [maxCharacters]. * @@ -140,7 +214,10 @@ private constructor( private var name: JsonValue = JsonValue.from("str_replace_based_edit_tool") private var type: JsonValue = JsonValue.from("text_editor_20250728") + private var allowedCallers: JsonField>? = null private var cacheControl: JsonField = JsonMissing.of() + private var deferLoading: JsonField = JsonMissing.of() + private var inputExamples: JsonField>? = null private var maxCharacters: JsonField = JsonMissing.of() private var strict: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -149,7 +226,10 @@ private constructor( internal fun from(betaToolTextEditor20250728: BetaToolTextEditor20250728) = apply { name = betaToolTextEditor20250728.name type = betaToolTextEditor20250728.type + allowedCallers = betaToolTextEditor20250728.allowedCallers.map { it.toMutableList() } cacheControl = betaToolTextEditor20250728.cacheControl + deferLoading = betaToolTextEditor20250728.deferLoading + inputExamples = betaToolTextEditor20250728.inputExamples.map { it.toMutableList() } maxCharacters = betaToolTextEditor20250728.maxCharacters strict = betaToolTextEditor20250728.strict additionalProperties = betaToolTextEditor20250728.additionalProperties.toMutableMap() @@ -183,6 +263,32 @@ private constructor( */ fun type(type: JsonValue) = apply { this.type = type } + fun allowedCallers(allowedCallers: List) = + allowedCallers(JsonField.of(allowedCallers)) + + /** + * Sets [Builder.allowedCallers] to an arbitrary JSON value. + * + * You should usually call [Builder.allowedCallers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun allowedCallers(allowedCallers: JsonField>) = apply { + this.allowedCallers = allowedCallers.map { it.toMutableList() } + } + + /** + * Adds a single [AllowedCaller] to [allowedCallers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAllowedCaller(allowedCaller: AllowedCaller) = apply { + allowedCallers = + (allowedCallers ?: JsonField.of(mutableListOf())).also { + checkKnown("allowedCallers", it).add(allowedCaller) + } + } + /** Create a cache control breakpoint at this content block. */ fun cacheControl(cacheControl: BetaCacheControlEphemeral?) = cacheControl(JsonField.ofNullable(cacheControl)) @@ -202,6 +308,49 @@ private constructor( this.cacheControl = cacheControl } + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned + * via tool_reference from tool search. + */ + fun deferLoading(deferLoading: Boolean) = deferLoading(JsonField.of(deferLoading)) + + /** + * Sets [Builder.deferLoading] to an arbitrary JSON value. + * + * You should usually call [Builder.deferLoading] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun deferLoading(deferLoading: JsonField) = apply { + this.deferLoading = deferLoading + } + + fun inputExamples(inputExamples: List) = + inputExamples(JsonField.of(inputExamples)) + + /** + * Sets [Builder.inputExamples] to an arbitrary JSON value. + * + * You should usually call [Builder.inputExamples] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun inputExamples(inputExamples: JsonField>) = apply { + this.inputExamples = inputExamples.map { it.toMutableList() } + } + + /** + * Adds a single [InputExample] to [inputExamples]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addInputExample(inputExample: InputExample) = apply { + inputExamples = + (inputExamples ?: JsonField.of(mutableListOf())).also { + checkKnown("inputExamples", it).add(inputExample) + } + } + /** * Maximum number of characters to display when viewing a file. If not specified, defaults * to displaying the full file. @@ -267,7 +416,10 @@ private constructor( BetaToolTextEditor20250728( name, type, + (allowedCallers ?: JsonMissing.of()).map { it.toImmutable() }, cacheControl, + deferLoading, + (inputExamples ?: JsonMissing.of()).map { it.toImmutable() }, maxCharacters, strict, additionalProperties.toMutableMap(), @@ -291,7 +443,10 @@ private constructor( throw AnthropicInvalidDataException("'type' is invalid, received $it") } } + allowedCallers().ifPresent { it.forEach { it.validate() } } cacheControl().ifPresent { it.validate() } + deferLoading() + inputExamples().ifPresent { it.forEach { it.validate() } } maxCharacters() strict() validated = true @@ -314,10 +469,243 @@ private constructor( internal fun validity(): Int = name.let { if (it == JsonValue.from("str_replace_based_edit_tool")) 1 else 0 } + type.let { if (it == JsonValue.from("text_editor_20250728")) 1 else 0 } + + (allowedCallers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (cacheControl.asKnown().getOrNull()?.validity() ?: 0) + + (if (deferLoading.asKnown().isPresent) 1 else 0) + + (inputExamples.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (if (maxCharacters.asKnown().isPresent) 1 else 0) + (if (strict.asKnown().isPresent) 1 else 0) + class AllowedCaller @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 DIRECT = of("direct") + + @JvmField val CODE_EXECUTION_20250825 = of("code_execution_20250825") + + @JvmStatic fun of(value: String) = AllowedCaller(JsonField.of(value)) + } + + /** An enum containing [AllowedCaller]'s known values. */ + enum class Known { + DIRECT, + CODE_EXECUTION_20250825, + } + + /** + * An enum containing [AllowedCaller]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [AllowedCaller] 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 { + DIRECT, + CODE_EXECUTION_20250825, + /** + * An enum member indicating that [AllowedCaller] 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) { + DIRECT -> Value.DIRECT + CODE_EXECUTION_20250825 -> Value.CODE_EXECUTION_20250825 + 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) { + DIRECT -> Known.DIRECT + CODE_EXECUTION_20250825 -> Known.CODE_EXECUTION_20250825 + else -> throw AnthropicInvalidDataException("Unknown AllowedCaller: $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 + + fun validate(): AllowedCaller = 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 AllowedCaller && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class InputExample + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [InputExample]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [InputExample]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(inputExample: InputExample) = apply { + additionalProperties = inputExample.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [InputExample]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): InputExample = InputExample(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): InputExample = apply { + if (validated) { + return@apply + } + + 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 = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is InputExample && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "InputExample{additionalProperties=$additionalProperties}" + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -326,18 +714,31 @@ private constructor( return other is BetaToolTextEditor20250728 && name == other.name && type == other.type && + allowedCallers == other.allowedCallers && cacheControl == other.cacheControl && + deferLoading == other.deferLoading && + inputExamples == other.inputExamples && maxCharacters == other.maxCharacters && strict == other.strict && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(name, type, cacheControl, maxCharacters, strict, additionalProperties) + Objects.hash( + name, + type, + allowedCallers, + cacheControl, + deferLoading, + inputExamples, + maxCharacters, + strict, + additionalProperties, + ) } override fun hashCode(): Int = hashCode override fun toString() = - "BetaToolTextEditor20250728{name=$name, type=$type, cacheControl=$cacheControl, maxCharacters=$maxCharacters, strict=$strict, additionalProperties=$additionalProperties}" + "BetaToolTextEditor20250728{name=$name, type=$type, allowedCallers=$allowedCallers, cacheControl=$cacheControl, deferLoading=$deferLoading, inputExamples=$inputExamples, maxCharacters=$maxCharacters, strict=$strict, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolUnion.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolUnion.kt index abb761682..0b09396fc 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolUnion.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolUnion.kt @@ -18,6 +18,12 @@ import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.util.Objects import java.util.Optional +/** + * Configuration for a group of tools from an MCP server. + * + * Allows configuring enabled status and defer_loading for all tools from an MCP server, with + * optional per-tool overrides. + */ @JsonDeserialize(using = BetaToolUnion.Deserializer::class) @JsonSerialize(using = BetaToolUnion.Serializer::class) class BetaToolUnion @@ -31,11 +37,15 @@ private constructor( private val memoryTool20250818: BetaMemoryTool20250818? = null, private val computerUse20250124: BetaToolComputerUse20250124? = null, private val textEditor20241022: BetaToolTextEditor20241022? = null, + private val computerUse20251124: BetaToolComputerUse20251124? = null, private val textEditor20250124: BetaToolTextEditor20250124? = null, private val textEditor20250429: BetaToolTextEditor20250429? = null, private val textEditor20250728: BetaToolTextEditor20250728? = null, private val webSearchTool20250305: BetaWebSearchTool20250305? = null, private val webFetchTool20250910: BetaWebFetchTool20250910? = null, + private val searchToolBm25_20251119: BetaToolSearchToolBm25_20251119? = null, + private val searchToolRegex20251119: BetaToolSearchToolRegex20251119? = null, + private val mcpToolset: BetaMcpToolset? = null, private val _json: JsonValue? = null, ) { @@ -63,6 +73,9 @@ private constructor( fun textEditor20241022(): Optional = Optional.ofNullable(textEditor20241022) + fun computerUse20251124(): Optional = + Optional.ofNullable(computerUse20251124) + fun textEditor20250124(): Optional = Optional.ofNullable(textEditor20250124) @@ -78,6 +91,20 @@ private constructor( fun webFetchTool20250910(): Optional = Optional.ofNullable(webFetchTool20250910) + fun searchToolBm25_20251119(): Optional = + Optional.ofNullable(searchToolBm25_20251119) + + fun searchToolRegex20251119(): Optional = + Optional.ofNullable(searchToolRegex20251119) + + /** + * Configuration for a group of tools from an MCP server. + * + * Allows configuring enabled status and defer_loading for all tools from an MCP server, with + * optional per-tool overrides. + */ + fun mcpToolset(): Optional = Optional.ofNullable(mcpToolset) + fun isBetaTool(): Boolean = betaTool != null fun isBash20241022(): Boolean = bash20241022 != null @@ -96,6 +123,8 @@ private constructor( fun isTextEditor20241022(): Boolean = textEditor20241022 != null + fun isComputerUse20251124(): Boolean = computerUse20251124 != null + fun isTextEditor20250124(): Boolean = textEditor20250124 != null fun isTextEditor20250429(): Boolean = textEditor20250429 != null @@ -106,6 +135,12 @@ private constructor( fun isWebFetchTool20250910(): Boolean = webFetchTool20250910 != null + fun isSearchToolBm25_20251119(): Boolean = searchToolBm25_20251119 != null + + fun isSearchToolRegex20251119(): Boolean = searchToolRegex20251119 != null + + fun isMcpToolset(): Boolean = mcpToolset != null + fun asBetaTool(): BetaTool = betaTool.getOrThrow("betaTool") fun asBash20241022(): BetaToolBash20241022 = bash20241022.getOrThrow("bash20241022") @@ -130,6 +165,9 @@ private constructor( fun asTextEditor20241022(): BetaToolTextEditor20241022 = textEditor20241022.getOrThrow("textEditor20241022") + fun asComputerUse20251124(): BetaToolComputerUse20251124 = + computerUse20251124.getOrThrow("computerUse20251124") + fun asTextEditor20250124(): BetaToolTextEditor20250124 = textEditor20250124.getOrThrow("textEditor20250124") @@ -145,6 +183,20 @@ private constructor( fun asWebFetchTool20250910(): BetaWebFetchTool20250910 = webFetchTool20250910.getOrThrow("webFetchTool20250910") + fun asSearchToolBm25_20251119(): BetaToolSearchToolBm25_20251119 = + searchToolBm25_20251119.getOrThrow("searchToolBm25_20251119") + + fun asSearchToolRegex20251119(): BetaToolSearchToolRegex20251119 = + searchToolRegex20251119.getOrThrow("searchToolRegex20251119") + + /** + * Configuration for a group of tools from an MCP server. + * + * Allows configuring enabled status and defer_loading for all tools from an MCP server, with + * optional per-tool overrides. + */ + fun asMcpToolset(): BetaMcpToolset = mcpToolset.getOrThrow("mcpToolset") + fun _json(): Optional = Optional.ofNullable(_json) fun accept(visitor: Visitor): T = @@ -160,12 +212,18 @@ private constructor( memoryTool20250818 != null -> visitor.visitMemoryTool20250818(memoryTool20250818) computerUse20250124 != null -> visitor.visitComputerUse20250124(computerUse20250124) textEditor20241022 != null -> visitor.visitTextEditor20241022(textEditor20241022) + computerUse20251124 != null -> visitor.visitComputerUse20251124(computerUse20251124) textEditor20250124 != null -> visitor.visitTextEditor20250124(textEditor20250124) textEditor20250429 != null -> visitor.visitTextEditor20250429(textEditor20250429) textEditor20250728 != null -> visitor.visitTextEditor20250728(textEditor20250728) webSearchTool20250305 != null -> visitor.visitWebSearchTool20250305(webSearchTool20250305) webFetchTool20250910 != null -> visitor.visitWebFetchTool20250910(webFetchTool20250910) + searchToolBm25_20251119 != null -> + visitor.visitSearchToolBm25_20251119(searchToolBm25_20251119) + searchToolRegex20251119 != null -> + visitor.visitSearchToolRegex20251119(searchToolRegex20251119) + mcpToolset != null -> visitor.visitMcpToolset(mcpToolset) else -> visitor.unknown(_json) } @@ -224,6 +282,12 @@ private constructor( textEditor20241022.validate() } + override fun visitComputerUse20251124( + computerUse20251124: BetaToolComputerUse20251124 + ) { + computerUse20251124.validate() + } + override fun visitTextEditor20250124( textEditor20250124: BetaToolTextEditor20250124 ) { @@ -253,6 +317,22 @@ private constructor( ) { webFetchTool20250910.validate() } + + override fun visitSearchToolBm25_20251119( + searchToolBm25_20251119: BetaToolSearchToolBm25_20251119 + ) { + searchToolBm25_20251119.validate() + } + + override fun visitSearchToolRegex20251119( + searchToolRegex20251119: BetaToolSearchToolRegex20251119 + ) { + searchToolRegex20251119.validate() + } + + override fun visitMcpToolset(mcpToolset: BetaMcpToolset) { + mcpToolset.validate() + } } ) validated = true @@ -306,6 +386,10 @@ private constructor( textEditor20241022: BetaToolTextEditor20241022 ) = textEditor20241022.validity() + override fun visitComputerUse20251124( + computerUse20251124: BetaToolComputerUse20251124 + ) = computerUse20251124.validity() + override fun visitTextEditor20250124( textEditor20250124: BetaToolTextEditor20250124 ) = textEditor20250124.validity() @@ -326,6 +410,16 @@ private constructor( webFetchTool20250910: BetaWebFetchTool20250910 ) = webFetchTool20250910.validity() + override fun visitSearchToolBm25_20251119( + searchToolBm25_20251119: BetaToolSearchToolBm25_20251119 + ) = searchToolBm25_20251119.validity() + + override fun visitSearchToolRegex20251119( + searchToolRegex20251119: BetaToolSearchToolRegex20251119 + ) = searchToolRegex20251119.validity() + + override fun visitMcpToolset(mcpToolset: BetaMcpToolset) = mcpToolset.validity() + override fun unknown(json: JsonValue?) = 0 } ) @@ -345,11 +439,15 @@ private constructor( memoryTool20250818 == other.memoryTool20250818 && computerUse20250124 == other.computerUse20250124 && textEditor20241022 == other.textEditor20241022 && + computerUse20251124 == other.computerUse20251124 && textEditor20250124 == other.textEditor20250124 && textEditor20250429 == other.textEditor20250429 && textEditor20250728 == other.textEditor20250728 && webSearchTool20250305 == other.webSearchTool20250305 && - webFetchTool20250910 == other.webFetchTool20250910 + webFetchTool20250910 == other.webFetchTool20250910 && + searchToolBm25_20251119 == other.searchToolBm25_20251119 && + searchToolRegex20251119 == other.searchToolRegex20251119 && + mcpToolset == other.mcpToolset } override fun hashCode(): Int = @@ -363,11 +461,15 @@ private constructor( memoryTool20250818, computerUse20250124, textEditor20241022, + computerUse20251124, textEditor20250124, textEditor20250429, textEditor20250728, webSearchTool20250305, webFetchTool20250910, + searchToolBm25_20251119, + searchToolRegex20251119, + mcpToolset, ) override fun toString(): String = @@ -383,6 +485,7 @@ private constructor( memoryTool20250818 != null -> "BetaToolUnion{memoryTool20250818=$memoryTool20250818}" computerUse20250124 != null -> "BetaToolUnion{computerUse20250124=$computerUse20250124}" textEditor20241022 != null -> "BetaToolUnion{textEditor20241022=$textEditor20241022}" + computerUse20251124 != null -> "BetaToolUnion{computerUse20251124=$computerUse20251124}" textEditor20250124 != null -> "BetaToolUnion{textEditor20250124=$textEditor20250124}" textEditor20250429 != null -> "BetaToolUnion{textEditor20250429=$textEditor20250429}" textEditor20250728 != null -> "BetaToolUnion{textEditor20250728=$textEditor20250728}" @@ -390,6 +493,11 @@ private constructor( "BetaToolUnion{webSearchTool20250305=$webSearchTool20250305}" webFetchTool20250910 != null -> "BetaToolUnion{webFetchTool20250910=$webFetchTool20250910}" + searchToolBm25_20251119 != null -> + "BetaToolUnion{searchToolBm25_20251119=$searchToolBm25_20251119}" + searchToolRegex20251119 != null -> + "BetaToolUnion{searchToolRegex20251119=$searchToolRegex20251119}" + mcpToolset != null -> "BetaToolUnion{mcpToolset=$mcpToolset}" _json != null -> "BetaToolUnion{_unknown=$_json}" else -> throw IllegalStateException("Invalid BetaToolUnion") } @@ -430,6 +538,10 @@ private constructor( fun ofTextEditor20241022(textEditor20241022: BetaToolTextEditor20241022) = BetaToolUnion(textEditor20241022 = textEditor20241022) + @JvmStatic + fun ofComputerUse20251124(computerUse20251124: BetaToolComputerUse20251124) = + BetaToolUnion(computerUse20251124 = computerUse20251124) + @JvmStatic fun ofTextEditor20250124(textEditor20250124: BetaToolTextEditor20250124) = BetaToolUnion(textEditor20250124 = textEditor20250124) @@ -449,6 +561,23 @@ private constructor( @JvmStatic fun ofWebFetchTool20250910(webFetchTool20250910: BetaWebFetchTool20250910) = BetaToolUnion(webFetchTool20250910 = webFetchTool20250910) + + @JvmStatic + fun ofSearchToolBm25_20251119(searchToolBm25_20251119: BetaToolSearchToolBm25_20251119) = + BetaToolUnion(searchToolBm25_20251119 = searchToolBm25_20251119) + + @JvmStatic + fun ofSearchToolRegex20251119(searchToolRegex20251119: BetaToolSearchToolRegex20251119) = + BetaToolUnion(searchToolRegex20251119 = searchToolRegex20251119) + + /** + * Configuration for a group of tools from an MCP server. + * + * Allows configuring enabled status and defer_loading for all tools from an MCP server, + * with optional per-tool overrides. + */ + @JvmStatic + fun ofMcpToolset(mcpToolset: BetaMcpToolset) = BetaToolUnion(mcpToolset = mcpToolset) } /** @@ -478,6 +607,8 @@ private constructor( fun visitTextEditor20241022(textEditor20241022: BetaToolTextEditor20241022): T + fun visitComputerUse20251124(computerUse20251124: BetaToolComputerUse20251124): T + fun visitTextEditor20250124(textEditor20250124: BetaToolTextEditor20250124): T fun visitTextEditor20250429(textEditor20250429: BetaToolTextEditor20250429): T @@ -488,6 +619,22 @@ private constructor( fun visitWebFetchTool20250910(webFetchTool20250910: BetaWebFetchTool20250910): T + fun visitSearchToolBm25_20251119( + searchToolBm25_20251119: BetaToolSearchToolBm25_20251119 + ): T + + fun visitSearchToolRegex20251119( + searchToolRegex20251119: BetaToolSearchToolRegex20251119 + ): T + + /** + * Configuration for a group of tools from an MCP server. + * + * Allows configuring enabled status and defer_loading for all tools from an MCP server, + * with optional per-tool overrides. + */ + fun visitMcpToolset(mcpToolset: BetaMcpToolset): T + /** * Maps an unknown variant of [BetaToolUnion] to a value of type [T]. * @@ -536,6 +683,9 @@ private constructor( tryDeserialize(node, jacksonTypeRef())?.let { BetaToolUnion(textEditor20241022 = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef())?.let { + BetaToolUnion(computerUse20251124 = it, _json = json) + }, tryDeserialize(node, jacksonTypeRef())?.let { BetaToolUnion(textEditor20250124 = it, _json = json) }, @@ -551,6 +701,13 @@ private constructor( tryDeserialize(node, jacksonTypeRef())?.let { BetaToolUnion(webFetchTool20250910 = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { BetaToolUnion(searchToolBm25_20251119 = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { BetaToolUnion(searchToolRegex20251119 = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef())?.let { + BetaToolUnion(mcpToolset = it, _json = json) + }, ) .filterNotNull() .allMaxBy { it.validity() } @@ -588,6 +745,8 @@ private constructor( value.computerUse20250124 != null -> generator.writeObject(value.computerUse20250124) value.textEditor20241022 != null -> generator.writeObject(value.textEditor20241022) + value.computerUse20251124 != null -> + generator.writeObject(value.computerUse20251124) value.textEditor20250124 != null -> generator.writeObject(value.textEditor20250124) value.textEditor20250429 != null -> generator.writeObject(value.textEditor20250429) value.textEditor20250728 != null -> generator.writeObject(value.textEditor20250728) @@ -595,6 +754,11 @@ private constructor( generator.writeObject(value.webSearchTool20250305) value.webFetchTool20250910 != null -> generator.writeObject(value.webFetchTool20250910) + value.searchToolBm25_20251119 != null -> + generator.writeObject(value.searchToolBm25_20251119) + value.searchToolRegex20251119 != null -> + generator.writeObject(value.searchToolRegex20251119) + value.mcpToolset != null -> generator.writeObject(value.mcpToolset) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid BetaToolUnion") } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolUseBlock.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolUseBlock.kt index a771ba6fe..13b1a7f9f 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolUseBlock.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolUseBlock.kt @@ -2,11 +2,14 @@ package com.anthropic.models.beta.messages +import com.anthropic.core.BaseDeserializer +import com.anthropic.core.BaseSerializer 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.core.outputTypeFromJson import com.anthropic.core.toJsonString import com.anthropic.errors.AnthropicInvalidDataException @@ -14,8 +17,17 @@ 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 class BetaToolUseBlock @JsonCreator(mode = JsonCreator.Mode.DISABLED) @@ -24,6 +36,7 @@ private constructor( private val input: JsonValue, private val name: JsonField, private val type: JsonValue, + private val caller: JsonField, private val additionalProperties: MutableMap, ) { @@ -33,10 +46,34 @@ private constructor( @JsonProperty("input") @ExcludeMissing input: JsonValue = JsonMissing.of(), @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), - ) : this(id, input, name, type, mutableMapOf()) + @JsonProperty("caller") @ExcludeMissing caller: JsonField = JsonMissing.of(), + ) : this(id, input, name, type, caller, mutableMapOf()) fun toParam(): BetaToolUseBlockParam = - BetaToolUseBlockParam.builder().id(_id()).input(_input()).name(_name()).build() + BetaToolUseBlockParam.builder() + .id(_id()) + .input(_input()) + .name(_name()) + .caller( + _caller().map { + it.accept( + object : BetaToolUseBlock.Caller.Visitor { + override fun visitDirect( + direct: BetaDirectCaller + ): BetaToolUseBlockParam.Caller = + BetaToolUseBlockParam.Caller.ofDirect(direct) + + override fun visitCodeExecution20250825( + codeExecution20250825: BetaServerToolCaller + ): BetaToolUseBlockParam.Caller = + BetaToolUseBlockParam.Caller.ofDirect( + BetaDirectCaller.builder().build() + ) + } + ) + } + ) + .build() /** * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is @@ -79,6 +116,14 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + /** + * Tool invocation directly from the model. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun caller(): Optional = caller.getOptional("caller") + /** * Returns the raw JSON value of [id]. * @@ -93,6 +138,13 @@ private constructor( */ @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + /** + * Returns the raw JSON value of [caller]. + * + * Unlike [caller], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("caller") @ExcludeMissing fun _caller(): JsonField = caller + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -127,6 +179,7 @@ private constructor( private var input: JsonValue? = null private var name: JsonField? = null private var type: JsonValue = JsonValue.from("tool_use") + private var caller: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -135,6 +188,7 @@ private constructor( input = betaToolUseBlock.input name = betaToolUseBlock.name type = betaToolUseBlock.type + caller = betaToolUseBlock.caller additionalProperties = betaToolUseBlock.additionalProperties.toMutableMap() } @@ -174,6 +228,37 @@ private constructor( */ fun type(type: JsonValue) = apply { this.type = type } + /** Tool invocation directly from the model. */ + fun caller(caller: Caller) = caller(JsonField.of(caller)) + + /** + * Sets [Builder.caller] to an arbitrary JSON value. + * + * You should usually call [Builder.caller] with a well-typed [Caller] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun caller(caller: JsonField) = apply { this.caller = caller } + + /** Alias for calling [caller] with `Caller.ofDirect(direct)`. */ + fun caller(direct: BetaDirectCaller) = caller(Caller.ofDirect(direct)) + + /** + * Alias for calling [caller] with `Caller.ofCodeExecution20250825(codeExecution20250825)`. + */ + fun caller(codeExecution20250825: BetaServerToolCaller) = + caller(Caller.ofCodeExecution20250825(codeExecution20250825)) + + /** + * Alias for calling [caller] with the following: + * ```java + * BetaServerToolCaller.builder() + * .toolId(toolId) + * .build() + * ``` + */ + fun codeExecution20250825Caller(toolId: String) = + caller(BetaServerToolCaller.builder().toolId(toolId).build()) + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -213,6 +298,7 @@ private constructor( checkRequired("input", input), checkRequired("name", name), type, + caller, additionalProperties.toMutableMap(), ) } @@ -231,6 +317,7 @@ private constructor( throw AnthropicInvalidDataException("'type' is invalid, received $it") } } + caller().ifPresent { it.validate() } validated = true } @@ -251,7 +338,194 @@ private constructor( internal fun validity(): Int = (if (id.asKnown().isPresent) 1 else 0) + (if (name.asKnown().isPresent) 1 else 0) + - type.let { if (it == JsonValue.from("tool_use")) 1 else 0 } + type.let { if (it == JsonValue.from("tool_use")) 1 else 0 } + + (caller.asKnown().getOrNull()?.validity() ?: 0) + + /** Tool invocation directly from the model. */ + @JsonDeserialize(using = Caller.Deserializer::class) + @JsonSerialize(using = Caller.Serializer::class) + class Caller + private constructor( + private val direct: BetaDirectCaller? = null, + private val codeExecution20250825: BetaServerToolCaller? = null, + private val _json: JsonValue? = null, + ) { + + /** Tool invocation directly from the model. */ + fun direct(): Optional = Optional.ofNullable(direct) + + /** Tool invocation generated by a server-side tool. */ + fun codeExecution20250825(): Optional = + Optional.ofNullable(codeExecution20250825) + + fun isDirect(): Boolean = direct != null + + fun isCodeExecution20250825(): Boolean = codeExecution20250825 != null + + /** Tool invocation directly from the model. */ + fun asDirect(): BetaDirectCaller = direct.getOrThrow("direct") + + /** Tool invocation generated by a server-side tool. */ + fun asCodeExecution20250825(): BetaServerToolCaller = + codeExecution20250825.getOrThrow("codeExecution20250825") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + direct != null -> visitor.visitDirect(direct) + codeExecution20250825 != null -> + visitor.visitCodeExecution20250825(codeExecution20250825) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Caller = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitDirect(direct: BetaDirectCaller) { + direct.validate() + } + + override fun visitCodeExecution20250825( + codeExecution20250825: BetaServerToolCaller + ) { + codeExecution20250825.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 visitDirect(direct: BetaDirectCaller) = direct.validity() + + override fun visitCodeExecution20250825( + codeExecution20250825: BetaServerToolCaller + ) = codeExecution20250825.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Caller && + direct == other.direct && + codeExecution20250825 == other.codeExecution20250825 + } + + override fun hashCode(): Int = Objects.hash(direct, codeExecution20250825) + + override fun toString(): String = + when { + direct != null -> "Caller{direct=$direct}" + codeExecution20250825 != null -> + "Caller{codeExecution20250825=$codeExecution20250825}" + _json != null -> "Caller{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Caller") + } + + companion object { + + /** Tool invocation directly from the model. */ + @JvmStatic fun ofDirect(direct: BetaDirectCaller) = Caller(direct = direct) + + /** Tool invocation generated by a server-side tool. */ + @JvmStatic + fun ofCodeExecution20250825(codeExecution20250825: BetaServerToolCaller) = + Caller(codeExecution20250825 = codeExecution20250825) + } + + /** An interface that defines how to map each variant of [Caller] to a value of type [T]. */ + interface Visitor { + + /** Tool invocation directly from the model. */ + fun visitDirect(direct: BetaDirectCaller): T + + /** Tool invocation generated by a server-side tool. */ + fun visitCodeExecution20250825(codeExecution20250825: BetaServerToolCaller): T + + /** + * Maps an unknown variant of [Caller] to a value of type [T]. + * + * An instance of [Caller] 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 Caller: $json") + } + } + + internal class Deserializer : BaseDeserializer(Caller::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Caller { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "direct" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Caller(direct = it, _json = json) + } ?: Caller(_json = json) + } + "code_execution_20250825" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Caller(codeExecution20250825 = it, _json = json) + } ?: Caller(_json = json) + } + } + + return Caller(_json = json) + } + } + + internal class Serializer : BaseSerializer(Caller::class) { + + override fun serialize( + value: Caller, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.direct != null -> generator.writeObject(value.direct) + value.codeExecution20250825 != null -> + generator.writeObject(value.codeExecution20250825) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Caller") + } + } + } + } override fun equals(other: Any?): Boolean { if (this === other) { @@ -263,13 +537,16 @@ private constructor( input == other.input && name == other.name && type == other.type && + caller == other.caller && additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { Objects.hash(id, input, name, type, additionalProperties) } + private val hashCode: Int by lazy { + Objects.hash(id, input, name, type, caller, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "BetaToolUseBlock{id=$id, input=$input, name=$name, type=$type, additionalProperties=$additionalProperties}" + "BetaToolUseBlock{id=$id, input=$input, name=$name, type=$type, caller=$caller, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolUseBlockParam.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolUseBlockParam.kt index 72ab7557f..eaab6745e 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolUseBlockParam.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolUseBlockParam.kt @@ -2,17 +2,27 @@ package com.anthropic.models.beta.messages +import com.anthropic.core.BaseDeserializer +import com.anthropic.core.BaseSerializer 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.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.util.Collections import java.util.Objects import java.util.Optional @@ -26,6 +36,7 @@ private constructor( private val name: JsonField, private val type: JsonValue, private val cacheControl: JsonField, + private val caller: JsonField, private val additionalProperties: MutableMap, ) { @@ -38,7 +49,8 @@ private constructor( @JsonProperty("cache_control") @ExcludeMissing cacheControl: JsonField = JsonMissing.of(), - ) : this(id, input, name, type, cacheControl, mutableMapOf()) + @JsonProperty("caller") @ExcludeMissing caller: JsonField = JsonMissing.of(), + ) : this(id, input, name, type, cacheControl, caller, mutableMapOf()) /** * @throws AnthropicInvalidDataException if the JSON field has an unexpected type or is @@ -78,6 +90,14 @@ private constructor( fun cacheControl(): Optional = cacheControl.getOptional("cache_control") + /** + * Tool invocation directly from the model. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun caller(): Optional = caller.getOptional("caller") + /** * Returns the raw JSON value of [id]. * @@ -108,6 +128,13 @@ private constructor( @ExcludeMissing fun _cacheControl(): JsonField = cacheControl + /** + * Returns the raw JSON value of [caller]. + * + * Unlike [caller], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("caller") @ExcludeMissing fun _caller(): JsonField = caller + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -143,6 +170,7 @@ private constructor( private var name: JsonField? = null private var type: JsonValue = JsonValue.from("tool_use") private var cacheControl: JsonField = JsonMissing.of() + private var caller: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -152,6 +180,7 @@ private constructor( name = betaToolUseBlockParam.name type = betaToolUseBlockParam.type cacheControl = betaToolUseBlockParam.cacheControl + caller = betaToolUseBlockParam.caller additionalProperties = betaToolUseBlockParam.additionalProperties.toMutableMap() } @@ -218,6 +247,37 @@ private constructor( this.cacheControl = cacheControl } + /** Tool invocation directly from the model. */ + fun caller(caller: Caller) = caller(JsonField.of(caller)) + + /** + * Sets [Builder.caller] to an arbitrary JSON value. + * + * You should usually call [Builder.caller] with a well-typed [Caller] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun caller(caller: JsonField) = apply { this.caller = caller } + + /** Alias for calling [caller] with `Caller.ofDirect(direct)`. */ + fun caller(direct: BetaDirectCaller) = caller(Caller.ofDirect(direct)) + + /** + * Alias for calling [caller] with `Caller.ofCodeExecution20250825(codeExecution20250825)`. + */ + fun caller(codeExecution20250825: BetaServerToolCaller) = + caller(Caller.ofCodeExecution20250825(codeExecution20250825)) + + /** + * Alias for calling [caller] with the following: + * ```java + * BetaServerToolCaller.builder() + * .toolId(toolId) + * .build() + * ``` + */ + fun codeExecution20250825Caller(toolId: String) = + caller(BetaServerToolCaller.builder().toolId(toolId).build()) + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -258,6 +318,7 @@ private constructor( checkRequired("name", name), type, cacheControl, + caller, additionalProperties.toMutableMap(), ) } @@ -278,6 +339,7 @@ private constructor( } } cacheControl().ifPresent { it.validate() } + caller().ifPresent { it.validate() } validated = true } @@ -300,7 +362,8 @@ private constructor( (input.asKnown().getOrNull()?.validity() ?: 0) + (if (name.asKnown().isPresent) 1 else 0) + type.let { if (it == JsonValue.from("tool_use")) 1 else 0 } + - (cacheControl.asKnown().getOrNull()?.validity() ?: 0) + (cacheControl.asKnown().getOrNull()?.validity() ?: 0) + + (caller.asKnown().getOrNull()?.validity() ?: 0) class Input @JsonCreator @@ -401,6 +464,192 @@ private constructor( override fun toString() = "Input{additionalProperties=$additionalProperties}" } + /** Tool invocation directly from the model. */ + @JsonDeserialize(using = Caller.Deserializer::class) + @JsonSerialize(using = Caller.Serializer::class) + class Caller + private constructor( + private val direct: BetaDirectCaller? = null, + private val codeExecution20250825: BetaServerToolCaller? = null, + private val _json: JsonValue? = null, + ) { + + /** Tool invocation directly from the model. */ + fun direct(): Optional = Optional.ofNullable(direct) + + /** Tool invocation generated by a server-side tool. */ + fun codeExecution20250825(): Optional = + Optional.ofNullable(codeExecution20250825) + + fun isDirect(): Boolean = direct != null + + fun isCodeExecution20250825(): Boolean = codeExecution20250825 != null + + /** Tool invocation directly from the model. */ + fun asDirect(): BetaDirectCaller = direct.getOrThrow("direct") + + /** Tool invocation generated by a server-side tool. */ + fun asCodeExecution20250825(): BetaServerToolCaller = + codeExecution20250825.getOrThrow("codeExecution20250825") + + fun _json(): Optional = Optional.ofNullable(_json) + + fun accept(visitor: Visitor): T = + when { + direct != null -> visitor.visitDirect(direct) + codeExecution20250825 != null -> + visitor.visitCodeExecution20250825(codeExecution20250825) + else -> visitor.unknown(_json) + } + + private var validated: Boolean = false + + fun validate(): Caller = apply { + if (validated) { + return@apply + } + + accept( + object : Visitor { + override fun visitDirect(direct: BetaDirectCaller) { + direct.validate() + } + + override fun visitCodeExecution20250825( + codeExecution20250825: BetaServerToolCaller + ) { + codeExecution20250825.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 visitDirect(direct: BetaDirectCaller) = direct.validity() + + override fun visitCodeExecution20250825( + codeExecution20250825: BetaServerToolCaller + ) = codeExecution20250825.validity() + + override fun unknown(json: JsonValue?) = 0 + } + ) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Caller && + direct == other.direct && + codeExecution20250825 == other.codeExecution20250825 + } + + override fun hashCode(): Int = Objects.hash(direct, codeExecution20250825) + + override fun toString(): String = + when { + direct != null -> "Caller{direct=$direct}" + codeExecution20250825 != null -> + "Caller{codeExecution20250825=$codeExecution20250825}" + _json != null -> "Caller{_unknown=$_json}" + else -> throw IllegalStateException("Invalid Caller") + } + + companion object { + + /** Tool invocation directly from the model. */ + @JvmStatic fun ofDirect(direct: BetaDirectCaller) = Caller(direct = direct) + + /** Tool invocation generated by a server-side tool. */ + @JvmStatic + fun ofCodeExecution20250825(codeExecution20250825: BetaServerToolCaller) = + Caller(codeExecution20250825 = codeExecution20250825) + } + + /** An interface that defines how to map each variant of [Caller] to a value of type [T]. */ + interface Visitor { + + /** Tool invocation directly from the model. */ + fun visitDirect(direct: BetaDirectCaller): T + + /** Tool invocation generated by a server-side tool. */ + fun visitCodeExecution20250825(codeExecution20250825: BetaServerToolCaller): T + + /** + * Maps an unknown variant of [Caller] to a value of type [T]. + * + * An instance of [Caller] 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 Caller: $json") + } + } + + internal class Deserializer : BaseDeserializer(Caller::class) { + + override fun ObjectCodec.deserialize(node: JsonNode): Caller { + val json = JsonValue.fromJsonNode(node) + val type = json.asObject().getOrNull()?.get("type")?.asString()?.getOrNull() + + when (type) { + "direct" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Caller(direct = it, _json = json) + } ?: Caller(_json = json) + } + "code_execution_20250825" -> { + return tryDeserialize(node, jacksonTypeRef())?.let { + Caller(codeExecution20250825 = it, _json = json) + } ?: Caller(_json = json) + } + } + + return Caller(_json = json) + } + } + + internal class Serializer : BaseSerializer(Caller::class) { + + override fun serialize( + value: Caller, + generator: JsonGenerator, + provider: SerializerProvider, + ) { + when { + value.direct != null -> generator.writeObject(value.direct) + value.codeExecution20250825 != null -> + generator.writeObject(value.codeExecution20250825) + value._json != null -> generator.writeObject(value._json) + else -> throw IllegalStateException("Invalid Caller") + } + } + } + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -412,15 +661,16 @@ private constructor( name == other.name && type == other.type && cacheControl == other.cacheControl && + caller == other.caller && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(id, input, name, type, cacheControl, additionalProperties) + Objects.hash(id, input, name, type, cacheControl, caller, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "BetaToolUseBlockParam{id=$id, input=$input, name=$name, type=$type, cacheControl=$cacheControl, additionalProperties=$additionalProperties}" + "BetaToolUseBlockParam{id=$id, input=$input, name=$name, type=$type, cacheControl=$cacheControl, caller=$caller, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaWebFetchTool20250910.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaWebFetchTool20250910.kt index 077db98cc..f0ce61081 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaWebFetchTool20250910.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaWebFetchTool20250910.kt @@ -2,6 +2,7 @@ package com.anthropic.models.beta.messages +import com.anthropic.core.Enum import com.anthropic.core.ExcludeMissing import com.anthropic.core.JsonField import com.anthropic.core.JsonMissing @@ -23,10 +24,12 @@ class BetaWebFetchTool20250910 private constructor( private val name: JsonValue, private val type: JsonValue, + private val allowedCallers: JsonField>, private val allowedDomains: JsonField>, private val blockedDomains: JsonField>, private val cacheControl: JsonField, private val citations: JsonField, + private val deferLoading: JsonField, private val maxContentTokens: JsonField, private val maxUses: JsonField, private val strict: JsonField, @@ -37,6 +40,9 @@ private constructor( private constructor( @JsonProperty("name") @ExcludeMissing name: JsonValue = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("allowed_callers") + @ExcludeMissing + allowedCallers: JsonField> = JsonMissing.of(), @JsonProperty("allowed_domains") @ExcludeMissing allowedDomains: JsonField> = JsonMissing.of(), @@ -49,6 +55,9 @@ private constructor( @JsonProperty("citations") @ExcludeMissing citations: JsonField = JsonMissing.of(), + @JsonProperty("defer_loading") + @ExcludeMissing + deferLoading: JsonField = JsonMissing.of(), @JsonProperty("max_content_tokens") @ExcludeMissing maxContentTokens: JsonField = JsonMissing.of(), @@ -57,10 +66,12 @@ private constructor( ) : this( name, type, + allowedCallers, allowedDomains, blockedDomains, cacheControl, citations, + deferLoading, maxContentTokens, maxUses, strict, @@ -93,6 +104,13 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun allowedCallers(): Optional> = + allowedCallers.getOptional("allowed_callers") + /** * List of domains to allow fetching from * @@ -126,6 +144,15 @@ private constructor( */ fun citations(): Optional = citations.getOptional("citations") + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned via + * tool_reference from tool search. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun deferLoading(): Optional = deferLoading.getOptional("defer_loading") + /** * Maximum number of tokens used by including web page text content in the context. The limit is * approximate and does not apply to binary content such as PDFs. @@ -149,6 +176,15 @@ private constructor( */ fun strict(): Optional = strict.getOptional("strict") + /** + * Returns the raw JSON value of [allowedCallers]. + * + * Unlike [allowedCallers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("allowed_callers") + @ExcludeMissing + fun _allowedCallers(): JsonField> = allowedCallers + /** * Returns the raw JSON value of [allowedDomains]. * @@ -185,6 +221,15 @@ private constructor( @ExcludeMissing fun _citations(): JsonField = citations + /** + * Returns the raw JSON value of [deferLoading]. + * + * Unlike [deferLoading], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("defer_loading") + @ExcludeMissing + fun _deferLoading(): JsonField = deferLoading + /** * Returns the raw JSON value of [maxContentTokens]. * @@ -232,10 +277,12 @@ private constructor( private var name: JsonValue = JsonValue.from("web_fetch") private var type: JsonValue = JsonValue.from("web_fetch_20250910") + private var allowedCallers: JsonField>? = null private var allowedDomains: JsonField>? = null private var blockedDomains: JsonField>? = null private var cacheControl: JsonField = JsonMissing.of() private var citations: JsonField = JsonMissing.of() + private var deferLoading: JsonField = JsonMissing.of() private var maxContentTokens: JsonField = JsonMissing.of() private var maxUses: JsonField = JsonMissing.of() private var strict: JsonField = JsonMissing.of() @@ -245,10 +292,12 @@ private constructor( internal fun from(betaWebFetchTool20250910: BetaWebFetchTool20250910) = apply { name = betaWebFetchTool20250910.name type = betaWebFetchTool20250910.type + allowedCallers = betaWebFetchTool20250910.allowedCallers.map { it.toMutableList() } allowedDomains = betaWebFetchTool20250910.allowedDomains.map { it.toMutableList() } blockedDomains = betaWebFetchTool20250910.blockedDomains.map { it.toMutableList() } cacheControl = betaWebFetchTool20250910.cacheControl citations = betaWebFetchTool20250910.citations + deferLoading = betaWebFetchTool20250910.deferLoading maxContentTokens = betaWebFetchTool20250910.maxContentTokens maxUses = betaWebFetchTool20250910.maxUses strict = betaWebFetchTool20250910.strict @@ -283,6 +332,32 @@ private constructor( */ fun type(type: JsonValue) = apply { this.type = type } + fun allowedCallers(allowedCallers: List) = + allowedCallers(JsonField.of(allowedCallers)) + + /** + * Sets [Builder.allowedCallers] to an arbitrary JSON value. + * + * You should usually call [Builder.allowedCallers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun allowedCallers(allowedCallers: JsonField>) = apply { + this.allowedCallers = allowedCallers.map { it.toMutableList() } + } + + /** + * Adds a single [AllowedCaller] to [allowedCallers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAllowedCaller(allowedCaller: AllowedCaller) = apply { + allowedCallers = + (allowedCallers ?: JsonField.of(mutableListOf())).also { + checkKnown("allowedCallers", it).add(allowedCaller) + } + } + /** List of domains to allow fetching from */ fun allowedDomains(allowedDomains: List?) = allowedDomains(JsonField.ofNullable(allowedDomains)) @@ -383,6 +458,23 @@ private constructor( this.citations = citations } + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned + * via tool_reference from tool search. + */ + fun deferLoading(deferLoading: Boolean) = deferLoading(JsonField.of(deferLoading)) + + /** + * Sets [Builder.deferLoading] to an arbitrary JSON value. + * + * You should usually call [Builder.deferLoading] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun deferLoading(deferLoading: JsonField) = apply { + this.deferLoading = deferLoading + } + /** * Maximum number of tokens used by including web page text content in the context. The * limit is approximate and does not apply to binary content such as PDFs. @@ -471,10 +563,12 @@ private constructor( BetaWebFetchTool20250910( name, type, + (allowedCallers ?: JsonMissing.of()).map { it.toImmutable() }, (allowedDomains ?: JsonMissing.of()).map { it.toImmutable() }, (blockedDomains ?: JsonMissing.of()).map { it.toImmutable() }, cacheControl, citations, + deferLoading, maxContentTokens, maxUses, strict, @@ -499,10 +593,12 @@ private constructor( throw AnthropicInvalidDataException("'type' is invalid, received $it") } } + allowedCallers().ifPresent { it.forEach { it.validate() } } allowedDomains() blockedDomains() cacheControl().ifPresent { it.validate() } citations().ifPresent { it.validate() } + deferLoading() maxContentTokens() maxUses() strict() @@ -526,14 +622,147 @@ private constructor( internal fun validity(): Int = name.let { if (it == JsonValue.from("web_fetch")) 1 else 0 } + type.let { if (it == JsonValue.from("web_fetch_20250910")) 1 else 0 } + + (allowedCallers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (allowedDomains.asKnown().getOrNull()?.size ?: 0) + (blockedDomains.asKnown().getOrNull()?.size ?: 0) + (cacheControl.asKnown().getOrNull()?.validity() ?: 0) + (citations.asKnown().getOrNull()?.validity() ?: 0) + + (if (deferLoading.asKnown().isPresent) 1 else 0) + (if (maxContentTokens.asKnown().isPresent) 1 else 0) + (if (maxUses.asKnown().isPresent) 1 else 0) + (if (strict.asKnown().isPresent) 1 else 0) + class AllowedCaller @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 DIRECT = of("direct") + + @JvmField val CODE_EXECUTION_20250825 = of("code_execution_20250825") + + @JvmStatic fun of(value: String) = AllowedCaller(JsonField.of(value)) + } + + /** An enum containing [AllowedCaller]'s known values. */ + enum class Known { + DIRECT, + CODE_EXECUTION_20250825, + } + + /** + * An enum containing [AllowedCaller]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [AllowedCaller] 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 { + DIRECT, + CODE_EXECUTION_20250825, + /** + * An enum member indicating that [AllowedCaller] 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) { + DIRECT -> Value.DIRECT + CODE_EXECUTION_20250825 -> Value.CODE_EXECUTION_20250825 + 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) { + DIRECT -> Known.DIRECT + CODE_EXECUTION_20250825 -> Known.CODE_EXECUTION_20250825 + else -> throw AnthropicInvalidDataException("Unknown AllowedCaller: $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 + + fun validate(): AllowedCaller = 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 AllowedCaller && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + override fun equals(other: Any?): Boolean { if (this === other) { return true @@ -542,10 +771,12 @@ private constructor( return other is BetaWebFetchTool20250910 && name == other.name && type == other.type && + allowedCallers == other.allowedCallers && allowedDomains == other.allowedDomains && blockedDomains == other.blockedDomains && cacheControl == other.cacheControl && citations == other.citations && + deferLoading == other.deferLoading && maxContentTokens == other.maxContentTokens && maxUses == other.maxUses && strict == other.strict && @@ -556,10 +787,12 @@ private constructor( Objects.hash( name, type, + allowedCallers, allowedDomains, blockedDomains, cacheControl, citations, + deferLoading, maxContentTokens, maxUses, strict, @@ -570,5 +803,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "BetaWebFetchTool20250910{name=$name, type=$type, allowedDomains=$allowedDomains, blockedDomains=$blockedDomains, cacheControl=$cacheControl, citations=$citations, maxContentTokens=$maxContentTokens, maxUses=$maxUses, strict=$strict, additionalProperties=$additionalProperties}" + "BetaWebFetchTool20250910{name=$name, type=$type, allowedCallers=$allowedCallers, allowedDomains=$allowedDomains, blockedDomains=$blockedDomains, cacheControl=$cacheControl, citations=$citations, deferLoading=$deferLoading, maxContentTokens=$maxContentTokens, maxUses=$maxUses, strict=$strict, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaWebSearchTool20250305.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaWebSearchTool20250305.kt index b21adaa68..bf8398923 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaWebSearchTool20250305.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaWebSearchTool20250305.kt @@ -2,6 +2,7 @@ package com.anthropic.models.beta.messages +import com.anthropic.core.Enum import com.anthropic.core.ExcludeMissing import com.anthropic.core.JsonField import com.anthropic.core.JsonMissing @@ -23,9 +24,11 @@ class BetaWebSearchTool20250305 private constructor( private val name: JsonValue, private val type: JsonValue, + private val allowedCallers: JsonField>, private val allowedDomains: JsonField>, private val blockedDomains: JsonField>, private val cacheControl: JsonField, + private val deferLoading: JsonField, private val maxUses: JsonField, private val strict: JsonField, private val userLocation: JsonField, @@ -36,6 +39,9 @@ private constructor( private constructor( @JsonProperty("name") @ExcludeMissing name: JsonValue = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonValue = JsonMissing.of(), + @JsonProperty("allowed_callers") + @ExcludeMissing + allowedCallers: JsonField> = JsonMissing.of(), @JsonProperty("allowed_domains") @ExcludeMissing allowedDomains: JsonField> = JsonMissing.of(), @@ -45,6 +51,9 @@ private constructor( @JsonProperty("cache_control") @ExcludeMissing cacheControl: JsonField = JsonMissing.of(), + @JsonProperty("defer_loading") + @ExcludeMissing + deferLoading: JsonField = JsonMissing.of(), @JsonProperty("max_uses") @ExcludeMissing maxUses: JsonField = JsonMissing.of(), @JsonProperty("strict") @ExcludeMissing strict: JsonField = JsonMissing.of(), @JsonProperty("user_location") @@ -53,9 +62,11 @@ private constructor( ) : this( name, type, + allowedCallers, allowedDomains, blockedDomains, cacheControl, + deferLoading, maxUses, strict, userLocation, @@ -88,6 +99,13 @@ private constructor( */ @JsonProperty("type") @ExcludeMissing fun _type(): JsonValue = type + /** + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun allowedCallers(): Optional> = + allowedCallers.getOptional("allowed_callers") + /** * If provided, only these domains will be included in results. Cannot be used alongside * `blocked_domains`. @@ -115,6 +133,15 @@ private constructor( fun cacheControl(): Optional = cacheControl.getOptional("cache_control") + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned via + * tool_reference from tool search. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun deferLoading(): Optional = deferLoading.getOptional("defer_loading") + /** * Maximum number of times the tool can be used in the API request. * @@ -137,6 +164,15 @@ private constructor( */ fun userLocation(): Optional = userLocation.getOptional("user_location") + /** + * Returns the raw JSON value of [allowedCallers]. + * + * Unlike [allowedCallers], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("allowed_callers") + @ExcludeMissing + fun _allowedCallers(): JsonField> = allowedCallers + /** * Returns the raw JSON value of [allowedDomains]. * @@ -164,6 +200,15 @@ private constructor( @ExcludeMissing fun _cacheControl(): JsonField = cacheControl + /** + * Returns the raw JSON value of [deferLoading]. + * + * Unlike [deferLoading], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("defer_loading") + @ExcludeMissing + fun _deferLoading(): JsonField = deferLoading + /** * Returns the raw JSON value of [maxUses]. * @@ -212,9 +257,11 @@ private constructor( private var name: JsonValue = JsonValue.from("web_search") private var type: JsonValue = JsonValue.from("web_search_20250305") + private var allowedCallers: JsonField>? = null private var allowedDomains: JsonField>? = null private var blockedDomains: JsonField>? = null private var cacheControl: JsonField = JsonMissing.of() + private var deferLoading: JsonField = JsonMissing.of() private var maxUses: JsonField = JsonMissing.of() private var strict: JsonField = JsonMissing.of() private var userLocation: JsonField = JsonMissing.of() @@ -224,9 +271,11 @@ private constructor( internal fun from(betaWebSearchTool20250305: BetaWebSearchTool20250305) = apply { name = betaWebSearchTool20250305.name type = betaWebSearchTool20250305.type + allowedCallers = betaWebSearchTool20250305.allowedCallers.map { it.toMutableList() } allowedDomains = betaWebSearchTool20250305.allowedDomains.map { it.toMutableList() } blockedDomains = betaWebSearchTool20250305.blockedDomains.map { it.toMutableList() } cacheControl = betaWebSearchTool20250305.cacheControl + deferLoading = betaWebSearchTool20250305.deferLoading maxUses = betaWebSearchTool20250305.maxUses strict = betaWebSearchTool20250305.strict userLocation = betaWebSearchTool20250305.userLocation @@ -261,6 +310,32 @@ private constructor( */ fun type(type: JsonValue) = apply { this.type = type } + fun allowedCallers(allowedCallers: List) = + allowedCallers(JsonField.of(allowedCallers)) + + /** + * Sets [Builder.allowedCallers] to an arbitrary JSON value. + * + * You should usually call [Builder.allowedCallers] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun allowedCallers(allowedCallers: JsonField>) = apply { + this.allowedCallers = allowedCallers.map { it.toMutableList() } + } + + /** + * Adds a single [AllowedCaller] to [allowedCallers]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addAllowedCaller(allowedCaller: AllowedCaller) = apply { + allowedCallers = + (allowedCallers ?: JsonField.of(mutableListOf())).also { + checkKnown("allowedCallers", it).add(allowedCaller) + } + } + /** * If provided, only these domains will be included in results. Cannot be used alongside * `blocked_domains`. @@ -348,6 +423,23 @@ private constructor( this.cacheControl = cacheControl } + /** + * If true, tool will not be included in initial system prompt. Only loaded when returned + * via tool_reference from tool search. + */ + fun deferLoading(deferLoading: Boolean) = deferLoading(JsonField.of(deferLoading)) + + /** + * Sets [Builder.deferLoading] to an arbitrary JSON value. + * + * You should usually call [Builder.deferLoading] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun deferLoading(deferLoading: JsonField) = apply { + this.deferLoading = deferLoading + } + /** Maximum number of times the tool can be used in the API request. */ fun maxUses(maxUses: Long?) = maxUses(JsonField.ofNullable(maxUses)) @@ -426,9 +518,11 @@ private constructor( BetaWebSearchTool20250305( name, type, + (allowedCallers ?: JsonMissing.of()).map { it.toImmutable() }, (allowedDomains ?: JsonMissing.of()).map { it.toImmutable() }, (blockedDomains ?: JsonMissing.of()).map { it.toImmutable() }, cacheControl, + deferLoading, maxUses, strict, userLocation, @@ -453,9 +547,11 @@ private constructor( throw AnthropicInvalidDataException("'type' is invalid, received $it") } } + allowedCallers().ifPresent { it.forEach { it.validate() } } allowedDomains() blockedDomains() cacheControl().ifPresent { it.validate() } + deferLoading() maxUses() strict() userLocation().ifPresent { it.validate() } @@ -479,13 +575,146 @@ private constructor( internal fun validity(): Int = name.let { if (it == JsonValue.from("web_search")) 1 else 0 } + type.let { if (it == JsonValue.from("web_search_20250305")) 1 else 0 } + + (allowedCallers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (allowedDomains.asKnown().getOrNull()?.size ?: 0) + (blockedDomains.asKnown().getOrNull()?.size ?: 0) + (cacheControl.asKnown().getOrNull()?.validity() ?: 0) + + (if (deferLoading.asKnown().isPresent) 1 else 0) + (if (maxUses.asKnown().isPresent) 1 else 0) + (if (strict.asKnown().isPresent) 1 else 0) + (userLocation.asKnown().getOrNull()?.validity() ?: 0) + class AllowedCaller @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 DIRECT = of("direct") + + @JvmField val CODE_EXECUTION_20250825 = of("code_execution_20250825") + + @JvmStatic fun of(value: String) = AllowedCaller(JsonField.of(value)) + } + + /** An enum containing [AllowedCaller]'s known values. */ + enum class Known { + DIRECT, + CODE_EXECUTION_20250825, + } + + /** + * An enum containing [AllowedCaller]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [AllowedCaller] 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 { + DIRECT, + CODE_EXECUTION_20250825, + /** + * An enum member indicating that [AllowedCaller] 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) { + DIRECT -> Value.DIRECT + CODE_EXECUTION_20250825 -> Value.CODE_EXECUTION_20250825 + 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) { + DIRECT -> Known.DIRECT + CODE_EXECUTION_20250825 -> Known.CODE_EXECUTION_20250825 + else -> throw AnthropicInvalidDataException("Unknown AllowedCaller: $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 + + fun validate(): AllowedCaller = 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 AllowedCaller && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + /** Parameters for the user's location. Used to provide more relevant search results. */ class UserLocation @JsonCreator(mode = JsonCreator.Mode.DISABLED) @@ -802,9 +1031,11 @@ private constructor( return other is BetaWebSearchTool20250305 && name == other.name && type == other.type && + allowedCallers == other.allowedCallers && allowedDomains == other.allowedDomains && blockedDomains == other.blockedDomains && cacheControl == other.cacheControl && + deferLoading == other.deferLoading && maxUses == other.maxUses && strict == other.strict && userLocation == other.userLocation && @@ -815,9 +1046,11 @@ private constructor( Objects.hash( name, type, + allowedCallers, allowedDomains, blockedDomains, cacheControl, + deferLoading, maxUses, strict, userLocation, @@ -828,5 +1061,5 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "BetaWebSearchTool20250305{name=$name, type=$type, allowedDomains=$allowedDomains, blockedDomains=$blockedDomains, cacheControl=$cacheControl, maxUses=$maxUses, strict=$strict, userLocation=$userLocation, additionalProperties=$additionalProperties}" + "BetaWebSearchTool20250305{name=$name, type=$type, allowedCallers=$allowedCallers, allowedDomains=$allowedDomains, blockedDomains=$blockedDomains, cacheControl=$cacheControl, deferLoading=$deferLoading, maxUses=$maxUses, strict=$strict, userLocation=$userLocation, additionalProperties=$additionalProperties}" } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/MessageCountTokensParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/MessageCountTokensParams.kt index f117e89e7..578116e07 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/MessageCountTokensParams.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/MessageCountTokensParams.kt @@ -144,6 +144,15 @@ private constructor( */ fun mcpServers(): Optional> = body.mcpServers() + /** + * Configuration options for the model's output. Controls aspects like how much effort the model + * puts into its response. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun outputConfig(): Optional = body.outputConfig() + /** * A schema to specify Claude's output format in responses. * @@ -292,6 +301,13 @@ private constructor( */ fun _mcpServers(): JsonField> = body._mcpServers() + /** + * Returns the raw JSON value of [outputConfig]. + * + * Unlike [outputConfig], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _outputConfig(): JsonField = body._outputConfig() + /** * Returns the raw JSON value of [outputFormat]. * @@ -400,7 +416,7 @@ private constructor( * - [model] * - [contextManagement] * - [mcpServers] - * - [outputFormat] + * - [outputConfig] * - etc. */ fun body(body: Body) = apply { this.body = body.toBuilder() } @@ -609,6 +625,23 @@ private constructor( body.addMcpServer(mcpServer) } + /** + * Configuration options for the model's output. Controls aspects like how much effort the + * model puts into its response. + */ + fun outputConfig(outputConfig: BetaOutputConfig) = apply { body.outputConfig(outputConfig) } + + /** + * Sets [Builder.outputConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.outputConfig] with a well-typed [BetaOutputConfig] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun outputConfig(outputConfig: JsonField) = apply { + body.outputConfig(outputConfig) + } + /** A schema to specify Claude's output format in responses. */ fun outputFormat(outputFormat: BetaJsonOutputFormat?) = apply { body.outputFormat(outputFormat) @@ -882,6 +915,14 @@ private constructor( body.addTool(betaToolTextEditor20241022) } + /** + * Alias for calling [addTool] with + * `Tool.ofBetaToolComputerUse20251124(betaToolComputerUse20251124)`. + */ + fun addTool(betaToolComputerUse20251124: BetaToolComputerUse20251124) = apply { + body.addTool(betaToolComputerUse20251124) + } + /** * Alias for calling [addTool] with * `Tool.ofBetaToolTextEditor20250124(betaToolTextEditor20250124)`. @@ -922,6 +963,25 @@ private constructor( body.addTool(betaWebFetchTool20250910) } + /** + * Alias for calling [addTool] with + * `Tool.ofBetaToolSearchToolBm25_20251119(betaToolSearchToolBm25_20251119)`. + */ + fun addTool(betaToolSearchToolBm25_20251119: BetaToolSearchToolBm25_20251119) = apply { + body.addTool(betaToolSearchToolBm25_20251119) + } + + /** + * Alias for calling [addTool] with + * `Tool.ofBetaToolSearchToolRegex20251119(betaToolSearchToolRegex20251119)`. + */ + fun addTool(betaToolSearchToolRegex20251119: BetaToolSearchToolRegex20251119) = apply { + body.addTool(betaToolSearchToolRegex20251119) + } + + /** Alias for calling [addTool] with `Tool.ofBetaMcpToolset(betaMcpToolset)`. */ + fun addTool(betaMcpToolset: BetaMcpToolset) = apply { body.addTool(betaMcpToolset) } + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { body.additionalProperties(additionalBodyProperties) } @@ -1080,6 +1140,7 @@ private constructor( private val model: JsonField, private val contextManagement: JsonField, private val mcpServers: JsonField>, + private val outputConfig: JsonField, private val outputFormat: JsonField, private val system: JsonField, private val thinking: JsonField, @@ -1100,6 +1161,9 @@ private constructor( @JsonProperty("mcp_servers") @ExcludeMissing mcpServers: JsonField> = JsonMissing.of(), + @JsonProperty("output_config") + @ExcludeMissing + outputConfig: JsonField = JsonMissing.of(), @JsonProperty("output_format") @ExcludeMissing outputFormat: JsonField = JsonMissing.of(), @@ -1116,6 +1180,7 @@ private constructor( model, contextManagement, mcpServers, + outputConfig, outputFormat, system, thinking, @@ -1218,6 +1283,15 @@ private constructor( fun mcpServers(): Optional> = mcpServers.getOptional("mcp_servers") + /** + * Configuration options for the model's output. Controls aspects like how much effort the + * model puts into its response. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun outputConfig(): Optional = outputConfig.getOptional("output_config") + /** * A schema to specify Claude's output format in responses. * @@ -1375,6 +1449,16 @@ private constructor( @ExcludeMissing fun _mcpServers(): JsonField> = mcpServers + /** + * Returns the raw JSON value of [outputConfig]. + * + * Unlike [outputConfig], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("output_config") + @ExcludeMissing + fun _outputConfig(): JsonField = outputConfig + /** * Returns the raw JSON value of [outputFormat]. * @@ -1451,6 +1535,7 @@ private constructor( private var contextManagement: JsonField = JsonMissing.of() private var mcpServers: JsonField>? = null + private var outputConfig: JsonField = JsonMissing.of() private var outputFormat: JsonField = JsonMissing.of() private var system: JsonField = JsonMissing.of() private var thinking: JsonField = JsonMissing.of() @@ -1464,6 +1549,7 @@ private constructor( model = body.model contextManagement = body.contextManagement mcpServers = body.mcpServers.map { it.toMutableList() } + outputConfig = body.outputConfig outputFormat = body.outputFormat system = body.system thinking = body.thinking @@ -1707,6 +1793,24 @@ private constructor( } } + /** + * Configuration options for the model's output. Controls aspects like how much effort + * the model puts into its response. + */ + fun outputConfig(outputConfig: BetaOutputConfig) = + outputConfig(JsonField.of(outputConfig)) + + /** + * Sets [Builder.outputConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.outputConfig] with a well-typed [BetaOutputConfig] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun outputConfig(outputConfig: JsonField) = apply { + this.outputConfig = outputConfig + } + /** A schema to specify Claude's output format in responses. */ fun outputFormat(outputFormat: BetaJsonOutputFormat?) = outputFormat(JsonField.ofNullable(outputFormat)) @@ -1989,6 +2093,13 @@ private constructor( fun addTool(betaToolTextEditor20241022: BetaToolTextEditor20241022) = addTool(Tool.ofBetaToolTextEditor20241022(betaToolTextEditor20241022)) + /** + * Alias for calling [addTool] with + * `Tool.ofBetaToolComputerUse20251124(betaToolComputerUse20251124)`. + */ + fun addTool(betaToolComputerUse20251124: BetaToolComputerUse20251124) = + addTool(Tool.ofBetaToolComputerUse20251124(betaToolComputerUse20251124)) + /** * Alias for calling [addTool] with * `Tool.ofBetaToolTextEditor20250124(betaToolTextEditor20250124)`. @@ -2024,6 +2135,24 @@ private constructor( fun addTool(betaWebFetchTool20250910: BetaWebFetchTool20250910) = addTool(Tool.ofBetaWebFetchTool20250910(betaWebFetchTool20250910)) + /** + * Alias for calling [addTool] with + * `Tool.ofBetaToolSearchToolBm25_20251119(betaToolSearchToolBm25_20251119)`. + */ + fun addTool(betaToolSearchToolBm25_20251119: BetaToolSearchToolBm25_20251119) = + addTool(Tool.ofBetaToolSearchToolBm25_20251119(betaToolSearchToolBm25_20251119)) + + /** + * Alias for calling [addTool] with + * `Tool.ofBetaToolSearchToolRegex20251119(betaToolSearchToolRegex20251119)`. + */ + fun addTool(betaToolSearchToolRegex20251119: BetaToolSearchToolRegex20251119) = + addTool(Tool.ofBetaToolSearchToolRegex20251119(betaToolSearchToolRegex20251119)) + + /** Alias for calling [addTool] with `Tool.ofBetaMcpToolset(betaMcpToolset)`. */ + fun addTool(betaMcpToolset: BetaMcpToolset) = + addTool(Tool.ofBetaMcpToolset(betaMcpToolset)) + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -2062,6 +2191,7 @@ private constructor( checkRequired("model", model), contextManagement, (mcpServers ?: JsonMissing.of()).map { it.toImmutable() }, + outputConfig, outputFormat, system, thinking, @@ -2082,6 +2212,7 @@ private constructor( model() contextManagement().ifPresent { it.validate() } mcpServers().ifPresent { it.forEach { it.validate() } } + outputConfig().ifPresent { it.validate() } outputFormat().ifPresent { it.validate() } system().ifPresent { it.validate() } thinking().ifPresent { it.validate() } @@ -2110,6 +2241,7 @@ private constructor( (if (model.asKnown().isPresent) 1 else 0) + (contextManagement.asKnown().getOrNull()?.validity() ?: 0) + (mcpServers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (outputConfig.asKnown().getOrNull()?.validity() ?: 0) + (outputFormat.asKnown().getOrNull()?.validity() ?: 0) + (system.asKnown().getOrNull()?.validity() ?: 0) + (thinking.asKnown().getOrNull()?.validity() ?: 0) + @@ -2126,6 +2258,7 @@ private constructor( model == other.model && contextManagement == other.contextManagement && mcpServers == other.mcpServers && + outputConfig == other.outputConfig && outputFormat == other.outputFormat && system == other.system && thinking == other.thinking && @@ -2140,6 +2273,7 @@ private constructor( model, contextManagement, mcpServers, + outputConfig, outputFormat, system, thinking, @@ -2152,7 +2286,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "Body{messages=$messages, model=$model, contextManagement=$contextManagement, mcpServers=$mcpServers, outputFormat=$outputFormat, system=$system, thinking=$thinking, toolChoice=$toolChoice, tools=$tools, additionalProperties=$additionalProperties}" + "Body{messages=$messages, model=$model, contextManagement=$contextManagement, mcpServers=$mcpServers, outputConfig=$outputConfig, outputFormat=$outputFormat, system=$system, thinking=$thinking, toolChoice=$toolChoice, tools=$tools, additionalProperties=$additionalProperties}" } /** @@ -2342,6 +2476,12 @@ private constructor( } } + /** + * Configuration for a group of tools from an MCP server. + * + * Allows configuring enabled status and defer_loading for all tools from an MCP server, with + * optional per-tool overrides. + */ @JsonDeserialize(using = Tool.Deserializer::class) @JsonSerialize(using = Tool.Serializer::class) class Tool @@ -2355,11 +2495,15 @@ private constructor( private val betaMemoryTool20250818: BetaMemoryTool20250818? = null, private val betaToolComputerUse20250124: BetaToolComputerUse20250124? = null, private val betaToolTextEditor20241022: BetaToolTextEditor20241022? = null, + private val betaToolComputerUse20251124: BetaToolComputerUse20251124? = null, private val betaToolTextEditor20250124: BetaToolTextEditor20250124? = null, private val betaToolTextEditor20250429: BetaToolTextEditor20250429? = null, private val betaToolTextEditor20250728: BetaToolTextEditor20250728? = null, private val betaWebSearchTool20250305: BetaWebSearchTool20250305? = null, private val betaWebFetchTool20250910: BetaWebFetchTool20250910? = null, + private val betaToolSearchToolBm25_20251119: BetaToolSearchToolBm25_20251119? = null, + private val betaToolSearchToolRegex20251119: BetaToolSearchToolRegex20251119? = null, + private val betaMcpToolset: BetaMcpToolset? = null, private val _json: JsonValue? = null, ) { @@ -2389,6 +2533,9 @@ private constructor( fun betaToolTextEditor20241022(): Optional = Optional.ofNullable(betaToolTextEditor20241022) + fun betaToolComputerUse20251124(): Optional = + Optional.ofNullable(betaToolComputerUse20251124) + fun betaToolTextEditor20250124(): Optional = Optional.ofNullable(betaToolTextEditor20250124) @@ -2404,6 +2551,20 @@ private constructor( fun betaWebFetchTool20250910(): Optional = Optional.ofNullable(betaWebFetchTool20250910) + fun betaToolSearchToolBm25_20251119(): Optional = + Optional.ofNullable(betaToolSearchToolBm25_20251119) + + fun betaToolSearchToolRegex20251119(): Optional = + Optional.ofNullable(betaToolSearchToolRegex20251119) + + /** + * Configuration for a group of tools from an MCP server. + * + * Allows configuring enabled status and defer_loading for all tools from an MCP server, + * with optional per-tool overrides. + */ + fun betaMcpToolset(): Optional = Optional.ofNullable(betaMcpToolset) + fun isBeta(): Boolean = beta != null fun isBetaToolBash20241022(): Boolean = betaToolBash20241022 != null @@ -2422,6 +2583,8 @@ private constructor( fun isBetaToolTextEditor20241022(): Boolean = betaToolTextEditor20241022 != null + fun isBetaToolComputerUse20251124(): Boolean = betaToolComputerUse20251124 != null + fun isBetaToolTextEditor20250124(): Boolean = betaToolTextEditor20250124 != null fun isBetaToolTextEditor20250429(): Boolean = betaToolTextEditor20250429 != null @@ -2432,6 +2595,12 @@ private constructor( fun isBetaWebFetchTool20250910(): Boolean = betaWebFetchTool20250910 != null + fun isBetaToolSearchToolBm25_20251119(): Boolean = betaToolSearchToolBm25_20251119 != null + + fun isBetaToolSearchToolRegex20251119(): Boolean = betaToolSearchToolRegex20251119 != null + + fun isBetaMcpToolset(): Boolean = betaMcpToolset != null + fun asBeta(): BetaTool = beta.getOrThrow("beta") fun asBetaToolBash20241022(): BetaToolBash20241022 = @@ -2458,6 +2627,9 @@ private constructor( fun asBetaToolTextEditor20241022(): BetaToolTextEditor20241022 = betaToolTextEditor20241022.getOrThrow("betaToolTextEditor20241022") + fun asBetaToolComputerUse20251124(): BetaToolComputerUse20251124 = + betaToolComputerUse20251124.getOrThrow("betaToolComputerUse20251124") + fun asBetaToolTextEditor20250124(): BetaToolTextEditor20250124 = betaToolTextEditor20250124.getOrThrow("betaToolTextEditor20250124") @@ -2473,6 +2645,20 @@ private constructor( fun asBetaWebFetchTool20250910(): BetaWebFetchTool20250910 = betaWebFetchTool20250910.getOrThrow("betaWebFetchTool20250910") + fun asBetaToolSearchToolBm25_20251119(): BetaToolSearchToolBm25_20251119 = + betaToolSearchToolBm25_20251119.getOrThrow("betaToolSearchToolBm25_20251119") + + fun asBetaToolSearchToolRegex20251119(): BetaToolSearchToolRegex20251119 = + betaToolSearchToolRegex20251119.getOrThrow("betaToolSearchToolRegex20251119") + + /** + * Configuration for a group of tools from an MCP server. + * + * Allows configuring enabled status and defer_loading for all tools from an MCP server, + * with optional per-tool overrides. + */ + fun asBetaMcpToolset(): BetaMcpToolset = betaMcpToolset.getOrThrow("betaMcpToolset") + fun _json(): Optional = Optional.ofNullable(_json) fun accept(visitor: Visitor): T = @@ -2494,6 +2680,8 @@ private constructor( visitor.visitBetaToolComputerUse20250124(betaToolComputerUse20250124) betaToolTextEditor20241022 != null -> visitor.visitBetaToolTextEditor20241022(betaToolTextEditor20241022) + betaToolComputerUse20251124 != null -> + visitor.visitBetaToolComputerUse20251124(betaToolComputerUse20251124) betaToolTextEditor20250124 != null -> visitor.visitBetaToolTextEditor20250124(betaToolTextEditor20250124) betaToolTextEditor20250429 != null -> @@ -2504,6 +2692,11 @@ private constructor( visitor.visitBetaWebSearchTool20250305(betaWebSearchTool20250305) betaWebFetchTool20250910 != null -> visitor.visitBetaWebFetchTool20250910(betaWebFetchTool20250910) + betaToolSearchToolBm25_20251119 != null -> + visitor.visitBetaToolSearchToolBm25_20251119(betaToolSearchToolBm25_20251119) + betaToolSearchToolRegex20251119 != null -> + visitor.visitBetaToolSearchToolRegex20251119(betaToolSearchToolRegex20251119) + betaMcpToolset != null -> visitor.visitBetaMcpToolset(betaMcpToolset) else -> visitor.unknown(_json) } @@ -2568,6 +2761,12 @@ private constructor( betaToolTextEditor20241022.validate() } + override fun visitBetaToolComputerUse20251124( + betaToolComputerUse20251124: BetaToolComputerUse20251124 + ) { + betaToolComputerUse20251124.validate() + } + override fun visitBetaToolTextEditor20250124( betaToolTextEditor20250124: BetaToolTextEditor20250124 ) { @@ -2597,6 +2796,22 @@ private constructor( ) { betaWebFetchTool20250910.validate() } + + override fun visitBetaToolSearchToolBm25_20251119( + betaToolSearchToolBm25_20251119: BetaToolSearchToolBm25_20251119 + ) { + betaToolSearchToolBm25_20251119.validate() + } + + override fun visitBetaToolSearchToolRegex20251119( + betaToolSearchToolRegex20251119: BetaToolSearchToolRegex20251119 + ) { + betaToolSearchToolRegex20251119.validate() + } + + override fun visitBetaMcpToolset(betaMcpToolset: BetaMcpToolset) { + betaMcpToolset.validate() + } } ) validated = true @@ -2654,6 +2869,10 @@ private constructor( betaToolTextEditor20241022: BetaToolTextEditor20241022 ) = betaToolTextEditor20241022.validity() + override fun visitBetaToolComputerUse20251124( + betaToolComputerUse20251124: BetaToolComputerUse20251124 + ) = betaToolComputerUse20251124.validity() + override fun visitBetaToolTextEditor20250124( betaToolTextEditor20250124: BetaToolTextEditor20250124 ) = betaToolTextEditor20250124.validity() @@ -2674,6 +2893,17 @@ private constructor( betaWebFetchTool20250910: BetaWebFetchTool20250910 ) = betaWebFetchTool20250910.validity() + override fun visitBetaToolSearchToolBm25_20251119( + betaToolSearchToolBm25_20251119: BetaToolSearchToolBm25_20251119 + ) = betaToolSearchToolBm25_20251119.validity() + + override fun visitBetaToolSearchToolRegex20251119( + betaToolSearchToolRegex20251119: BetaToolSearchToolRegex20251119 + ) = betaToolSearchToolRegex20251119.validity() + + override fun visitBetaMcpToolset(betaMcpToolset: BetaMcpToolset) = + betaMcpToolset.validity() + override fun unknown(json: JsonValue?) = 0 } ) @@ -2693,11 +2923,15 @@ private constructor( betaMemoryTool20250818 == other.betaMemoryTool20250818 && betaToolComputerUse20250124 == other.betaToolComputerUse20250124 && betaToolTextEditor20241022 == other.betaToolTextEditor20241022 && + betaToolComputerUse20251124 == other.betaToolComputerUse20251124 && betaToolTextEditor20250124 == other.betaToolTextEditor20250124 && betaToolTextEditor20250429 == other.betaToolTextEditor20250429 && betaToolTextEditor20250728 == other.betaToolTextEditor20250728 && betaWebSearchTool20250305 == other.betaWebSearchTool20250305 && - betaWebFetchTool20250910 == other.betaWebFetchTool20250910 + betaWebFetchTool20250910 == other.betaWebFetchTool20250910 && + betaToolSearchToolBm25_20251119 == other.betaToolSearchToolBm25_20251119 && + betaToolSearchToolRegex20251119 == other.betaToolSearchToolRegex20251119 && + betaMcpToolset == other.betaMcpToolset } override fun hashCode(): Int = @@ -2711,11 +2945,15 @@ private constructor( betaMemoryTool20250818, betaToolComputerUse20250124, betaToolTextEditor20241022, + betaToolComputerUse20251124, betaToolTextEditor20250124, betaToolTextEditor20250429, betaToolTextEditor20250728, betaWebSearchTool20250305, betaWebFetchTool20250910, + betaToolSearchToolBm25_20251119, + betaToolSearchToolRegex20251119, + betaMcpToolset, ) override fun toString(): String = @@ -2735,6 +2973,8 @@ private constructor( "Tool{betaToolComputerUse20250124=$betaToolComputerUse20250124}" betaToolTextEditor20241022 != null -> "Tool{betaToolTextEditor20241022=$betaToolTextEditor20241022}" + betaToolComputerUse20251124 != null -> + "Tool{betaToolComputerUse20251124=$betaToolComputerUse20251124}" betaToolTextEditor20250124 != null -> "Tool{betaToolTextEditor20250124=$betaToolTextEditor20250124}" betaToolTextEditor20250429 != null -> @@ -2745,6 +2985,11 @@ private constructor( "Tool{betaWebSearchTool20250305=$betaWebSearchTool20250305}" betaWebFetchTool20250910 != null -> "Tool{betaWebFetchTool20250910=$betaWebFetchTool20250910}" + betaToolSearchToolBm25_20251119 != null -> + "Tool{betaToolSearchToolBm25_20251119=$betaToolSearchToolBm25_20251119}" + betaToolSearchToolRegex20251119 != null -> + "Tool{betaToolSearchToolRegex20251119=$betaToolSearchToolRegex20251119}" + betaMcpToolset != null -> "Tool{betaMcpToolset=$betaMcpToolset}" _json != null -> "Tool{_unknown=$_json}" else -> throw IllegalStateException("Invalid Tool") } @@ -2790,6 +3035,11 @@ private constructor( betaToolTextEditor20241022: BetaToolTextEditor20241022 ) = Tool(betaToolTextEditor20241022 = betaToolTextEditor20241022) + @JvmStatic + fun ofBetaToolComputerUse20251124( + betaToolComputerUse20251124: BetaToolComputerUse20251124 + ) = Tool(betaToolComputerUse20251124 = betaToolComputerUse20251124) + @JvmStatic fun ofBetaToolTextEditor20250124( betaToolTextEditor20250124: BetaToolTextEditor20250124 @@ -2812,6 +3062,26 @@ private constructor( @JvmStatic fun ofBetaWebFetchTool20250910(betaWebFetchTool20250910: BetaWebFetchTool20250910) = Tool(betaWebFetchTool20250910 = betaWebFetchTool20250910) + + @JvmStatic + fun ofBetaToolSearchToolBm25_20251119( + betaToolSearchToolBm25_20251119: BetaToolSearchToolBm25_20251119 + ) = Tool(betaToolSearchToolBm25_20251119 = betaToolSearchToolBm25_20251119) + + @JvmStatic + fun ofBetaToolSearchToolRegex20251119( + betaToolSearchToolRegex20251119: BetaToolSearchToolRegex20251119 + ) = Tool(betaToolSearchToolRegex20251119 = betaToolSearchToolRegex20251119) + + /** + * Configuration for a group of tools from an MCP server. + * + * Allows configuring enabled status and defer_loading for all tools from an MCP server, + * with optional per-tool overrides. + */ + @JvmStatic + fun ofBetaMcpToolset(betaMcpToolset: BetaMcpToolset) = + Tool(betaMcpToolset = betaMcpToolset) } /** An interface that defines how to map each variant of [Tool] to a value of type [T]. */ @@ -2845,6 +3115,10 @@ private constructor( betaToolTextEditor20241022: BetaToolTextEditor20241022 ): T + fun visitBetaToolComputerUse20251124( + betaToolComputerUse20251124: BetaToolComputerUse20251124 + ): T + fun visitBetaToolTextEditor20250124( betaToolTextEditor20250124: BetaToolTextEditor20250124 ): T @@ -2863,6 +3137,22 @@ private constructor( fun visitBetaWebFetchTool20250910(betaWebFetchTool20250910: BetaWebFetchTool20250910): T + fun visitBetaToolSearchToolBm25_20251119( + betaToolSearchToolBm25_20251119: BetaToolSearchToolBm25_20251119 + ): T + + fun visitBetaToolSearchToolRegex20251119( + betaToolSearchToolRegex20251119: BetaToolSearchToolRegex20251119 + ): T + + /** + * Configuration for a group of tools from an MCP server. + * + * Allows configuring enabled status and defer_loading for all tools from an MCP server, + * with optional per-tool overrides. + */ + fun visitBetaMcpToolset(betaMcpToolset: BetaMcpToolset): T + /** * Maps an unknown variant of [Tool] to a value of type [T]. * @@ -2906,6 +3196,8 @@ private constructor( ?.let { Tool(betaToolComputerUse20250124 = it, _json = json) }, tryDeserialize(node, jacksonTypeRef()) ?.let { Tool(betaToolTextEditor20241022 = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { Tool(betaToolComputerUse20251124 = it, _json = json) }, tryDeserialize(node, jacksonTypeRef()) ?.let { Tool(betaToolTextEditor20250124 = it, _json = json) }, tryDeserialize(node, jacksonTypeRef()) @@ -2918,6 +3210,13 @@ private constructor( tryDeserialize(node, jacksonTypeRef())?.let { Tool(betaWebFetchTool20250910 = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { Tool(betaToolSearchToolBm25_20251119 = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef()) + ?.let { Tool(betaToolSearchToolRegex20251119 = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef())?.let { + Tool(betaMcpToolset = it, _json = json) + }, ) .filterNotNull() .allMaxBy { it.validity() } @@ -2960,6 +3259,8 @@ private constructor( generator.writeObject(value.betaToolComputerUse20250124) value.betaToolTextEditor20241022 != null -> generator.writeObject(value.betaToolTextEditor20241022) + value.betaToolComputerUse20251124 != null -> + generator.writeObject(value.betaToolComputerUse20251124) value.betaToolTextEditor20250124 != null -> generator.writeObject(value.betaToolTextEditor20250124) value.betaToolTextEditor20250429 != null -> @@ -2970,6 +3271,11 @@ private constructor( generator.writeObject(value.betaWebSearchTool20250305) value.betaWebFetchTool20250910 != null -> generator.writeObject(value.betaWebFetchTool20250910) + value.betaToolSearchToolBm25_20251119 != null -> + generator.writeObject(value.betaToolSearchToolBm25_20251119) + value.betaToolSearchToolRegex20251119 != null -> + generator.writeObject(value.betaToolSearchToolRegex20251119) + value.betaMcpToolset != null -> generator.writeObject(value.betaMcpToolset) value._json != null -> generator.writeObject(value._json) else -> throw IllegalStateException("Invalid Tool") } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/MessageCreateParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/MessageCreateParams.kt index 8e243bcd7..2878d5e85 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/MessageCreateParams.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/MessageCreateParams.kt @@ -180,6 +180,15 @@ private constructor( */ fun metadata(): Optional = body.metadata() + /** + * Configuration options for the model's output. Controls aspects like how much effort the model + * puts into its response. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun outputConfig(): Optional = body.outputConfig() + /** * A schema to specify Claude's output format in responses. * @@ -418,6 +427,13 @@ private constructor( */ fun _metadata(): JsonField = body._metadata() + /** + * Returns the raw JSON value of [outputConfig]. + * + * Unlike [outputConfig], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _outputConfig(): JsonField = body._outputConfig() + /** * Returns the raw JSON value of [outputFormat]. * @@ -830,6 +846,23 @@ private constructor( */ fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } + /** + * Configuration options for the model's output. Controls aspects like how much effort the + * model puts into its response. + */ + fun outputConfig(outputConfig: BetaOutputConfig) = apply { body.outputConfig(outputConfig) } + + /** + * Sets [Builder.outputConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.outputConfig] with a well-typed [BetaOutputConfig] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun outputConfig(outputConfig: JsonField) = apply { + body.outputConfig(outputConfig) + } + /** A schema to specify Claude's output format in responses. */ fun outputFormat(outputFormat: BetaJsonOutputFormat?) = apply { body.outputFormat(outputFormat) @@ -1191,6 +1224,14 @@ private constructor( body.addTool(textEditor20241022) } + /** + * Alias for calling [addTool] with + * `BetaToolUnion.ofComputerUse20251124(computerUse20251124)`. + */ + fun addTool(computerUse20251124: BetaToolComputerUse20251124) = apply { + body.addTool(computerUse20251124) + } + /** * Alias for calling [addTool] with * `BetaToolUnion.ofTextEditor20250124(textEditor20250124)`. @@ -1249,6 +1290,25 @@ private constructor( addTool(toolFromClass(toolParametersType, localValidation)) } + /** + * Alias for calling [addTool] with + * `BetaToolUnion.ofSearchToolBm25_20251119(searchToolBm25_20251119)`. + */ + fun addTool(searchToolBm25_20251119: BetaToolSearchToolBm25_20251119) = apply { + body.addTool(searchToolBm25_20251119) + } + + /** + * Alias for calling [addTool] with + * `BetaToolUnion.ofSearchToolRegex20251119(searchToolRegex20251119)`. + */ + fun addTool(searchToolRegex20251119: BetaToolSearchToolRegex20251119) = apply { + body.addTool(searchToolRegex20251119) + } + + /** Alias for calling [addTool] with `BetaToolUnion.ofMcpToolset(mcpToolset)`. */ + fun addTool(mcpToolset: BetaMcpToolset) = apply { body.addTool(mcpToolset) } + /** * Only sample from the top K options for each subsequent token. * @@ -1450,6 +1510,7 @@ private constructor( private val contextManagement: JsonField, private val mcpServers: JsonField>, private val metadata: JsonField, + private val outputConfig: JsonField, private val outputFormat: JsonField, private val serviceTier: JsonField, private val stopSequences: JsonField>, @@ -1484,6 +1545,9 @@ private constructor( @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("output_config") + @ExcludeMissing + outputConfig: JsonField = JsonMissing.of(), @JsonProperty("output_format") @ExcludeMissing outputFormat: JsonField = JsonMissing.of(), @@ -1516,6 +1580,7 @@ private constructor( contextManagement, mcpServers, metadata, + outputConfig, outputFormat, serviceTier, stopSequences, @@ -1653,6 +1718,15 @@ private constructor( */ fun metadata(): Optional = metadata.getOptional("metadata") + /** + * Configuration options for the model's output. Controls aspects like how much effort the + * model puts into its response. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun outputConfig(): Optional = outputConfig.getOptional("output_config") + /** * A schema to specify Claude's output format in responses. * @@ -1904,6 +1978,16 @@ private constructor( @ExcludeMissing fun _metadata(): JsonField = metadata + /** + * Returns the raw JSON value of [outputConfig]. + * + * Unlike [outputConfig], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("output_config") + @ExcludeMissing + fun _outputConfig(): JsonField = outputConfig + /** * Returns the raw JSON value of [outputFormat]. * @@ -2026,6 +2110,7 @@ private constructor( private var mcpServers: JsonField>? = null private var metadata: JsonField = JsonMissing.of() + private var outputConfig: JsonField = JsonMissing.of() private var outputFormat: JsonField = JsonMissing.of() private var serviceTier: JsonField = JsonMissing.of() private var stopSequences: JsonField>? = null @@ -2047,6 +2132,7 @@ private constructor( contextManagement = body.contextManagement mcpServers = body.mcpServers.map { it.toMutableList() } metadata = body.metadata + outputConfig = body.outputConfig outputFormat = body.outputFormat serviceTier = body.serviceTier stopSequences = body.stopSequences.map { it.toMutableList() } @@ -2352,6 +2438,24 @@ private constructor( */ fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + /** + * Configuration options for the model's output. Controls aspects like how much effort + * the model puts into its response. + */ + fun outputConfig(outputConfig: BetaOutputConfig) = + outputConfig(JsonField.of(outputConfig)) + + /** + * Sets [Builder.outputConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.outputConfig] with a well-typed [BetaOutputConfig] + * value instead. This method is primarily for setting the field to an undocumented or + * not yet supported value. + */ + fun outputConfig(outputConfig: JsonField) = apply { + this.outputConfig = outputConfig + } + /** A schema to specify Claude's output format in responses. */ fun outputFormat(outputFormat: BetaJsonOutputFormat?) = outputFormat(JsonField.ofNullable(outputFormat)) @@ -2709,6 +2813,13 @@ private constructor( fun addTool(textEditor20241022: BetaToolTextEditor20241022) = addTool(BetaToolUnion.ofTextEditor20241022(textEditor20241022)) + /** + * Alias for calling [addTool] with + * `BetaToolUnion.ofComputerUse20251124(computerUse20251124)`. + */ + fun addTool(computerUse20251124: BetaToolComputerUse20251124) = + addTool(BetaToolUnion.ofComputerUse20251124(computerUse20251124)) + /** * Alias for calling [addTool] with * `BetaToolUnion.ofTextEditor20250124(textEditor20250124)`. @@ -2744,6 +2855,24 @@ private constructor( fun addTool(webFetchTool20250910: BetaWebFetchTool20250910) = addTool(BetaToolUnion.ofWebFetchTool20250910(webFetchTool20250910)) + /** + * Alias for calling [addTool] with + * `BetaToolUnion.ofSearchToolBm25_20251119(searchToolBm25_20251119)`. + */ + fun addTool(searchToolBm25_20251119: BetaToolSearchToolBm25_20251119) = + addTool(BetaToolUnion.ofSearchToolBm25_20251119(searchToolBm25_20251119)) + + /** + * Alias for calling [addTool] with + * `BetaToolUnion.ofSearchToolRegex20251119(searchToolRegex20251119)`. + */ + fun addTool(searchToolRegex20251119: BetaToolSearchToolRegex20251119) = + addTool(BetaToolUnion.ofSearchToolRegex20251119(searchToolRegex20251119)) + + /** Alias for calling [addTool] with `BetaToolUnion.ofMcpToolset(mcpToolset)`. */ + fun addTool(mcpToolset: BetaMcpToolset) = + addTool(BetaToolUnion.ofMcpToolset(mcpToolset)) + /** * Only sample from the top K options for each subsequent token. * @@ -2826,6 +2955,7 @@ private constructor( contextManagement, (mcpServers ?: JsonMissing.of()).map { it.toImmutable() }, metadata, + outputConfig, outputFormat, serviceTier, (stopSequences ?: JsonMissing.of()).map { it.toImmutable() }, @@ -2854,6 +2984,7 @@ private constructor( contextManagement().ifPresent { it.validate() } mcpServers().ifPresent { it.forEach { it.validate() } } metadata().ifPresent { it.validate() } + outputConfig().ifPresent { it.validate() } outputFormat().ifPresent { it.validate() } serviceTier().ifPresent { it.validate() } stopSequences() @@ -2890,6 +3021,7 @@ private constructor( (contextManagement.asKnown().getOrNull()?.validity() ?: 0) + (mcpServers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (outputConfig.asKnown().getOrNull()?.validity() ?: 0) + (outputFormat.asKnown().getOrNull()?.validity() ?: 0) + (serviceTier.asKnown().getOrNull()?.validity() ?: 0) + (stopSequences.asKnown().getOrNull()?.size ?: 0) + @@ -2914,6 +3046,7 @@ private constructor( contextManagement == other.contextManagement && mcpServers == other.mcpServers && metadata == other.metadata && + outputConfig == other.outputConfig && outputFormat == other.outputFormat && serviceTier == other.serviceTier && stopSequences == other.stopSequences && @@ -2936,6 +3069,7 @@ private constructor( contextManagement, mcpServers, metadata, + outputConfig, outputFormat, serviceTier, stopSequences, @@ -2953,7 +3087,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "Body{maxTokens=$maxTokens, messages=$messages, model=$model, container=$container, contextManagement=$contextManagement, mcpServers=$mcpServers, metadata=$metadata, outputFormat=$outputFormat, serviceTier=$serviceTier, stopSequences=$stopSequences, system=$system, temperature=$temperature, thinking=$thinking, toolChoice=$toolChoice, tools=$tools, topK=$topK, topP=$topP, additionalProperties=$additionalProperties}" + "Body{maxTokens=$maxTokens, messages=$messages, model=$model, container=$container, contextManagement=$contextManagement, mcpServers=$mcpServers, metadata=$metadata, outputConfig=$outputConfig, outputFormat=$outputFormat, serviceTier=$serviceTier, stopSequences=$stopSequences, system=$system, temperature=$temperature, thinking=$thinking, toolChoice=$toolChoice, tools=$tools, topK=$topK, topP=$topP, additionalProperties=$additionalProperties}" } /** Container identifier for reuse across requests. */ diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/batches/BatchCreateParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/batches/BatchCreateParams.kt index 99367f0a8..90c29654f 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/batches/BatchCreateParams.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/batches/BatchCreateParams.kt @@ -25,10 +25,12 @@ import com.anthropic.models.beta.messages.BetaContainerParams import com.anthropic.models.beta.messages.BetaContentBlockParam import com.anthropic.models.beta.messages.BetaContextManagementConfig import com.anthropic.models.beta.messages.BetaJsonOutputFormat +import com.anthropic.models.beta.messages.BetaMcpToolset import com.anthropic.models.beta.messages.BetaMemoryTool20250818 import com.anthropic.models.beta.messages.BetaMessage import com.anthropic.models.beta.messages.BetaMessageParam import com.anthropic.models.beta.messages.BetaMetadata +import com.anthropic.models.beta.messages.BetaOutputConfig import com.anthropic.models.beta.messages.BetaRequestMcpServerUrlDefinition import com.anthropic.models.beta.messages.BetaTextBlockParam import com.anthropic.models.beta.messages.BetaThinkingConfigDisabled @@ -44,6 +46,9 @@ import com.anthropic.models.beta.messages.BetaToolChoiceNone import com.anthropic.models.beta.messages.BetaToolChoiceTool import com.anthropic.models.beta.messages.BetaToolComputerUse20241022 import com.anthropic.models.beta.messages.BetaToolComputerUse20250124 +import com.anthropic.models.beta.messages.BetaToolComputerUse20251124 +import com.anthropic.models.beta.messages.BetaToolSearchToolBm25_20251119 +import com.anthropic.models.beta.messages.BetaToolSearchToolRegex20251119 import com.anthropic.models.beta.messages.BetaToolTextEditor20241022 import com.anthropic.models.beta.messages.BetaToolTextEditor20250124 import com.anthropic.models.beta.messages.BetaToolTextEditor20250429 @@ -561,8 +566,8 @@ private constructor( /** * Messages API creation parameters for the individual request. * - * See the [Messages API reference](/en/api/messages) for full documentation on available - * parameters. + * See the [Messages API reference](https://docs.claude.com/en/api/messages) for full + * documentation on available parameters. * * @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). @@ -643,8 +648,8 @@ private constructor( /** * Messages API creation parameters for the individual request. * - * See the [Messages API reference](/en/api/messages) for full documentation on - * available parameters. + * See the [Messages API reference](https://docs.claude.com/en/api/messages) for full + * documentation on available parameters. */ fun params(params: Params) = params(JsonField.of(params)) @@ -731,8 +736,8 @@ private constructor( /** * Messages API creation parameters for the individual request. * - * See the [Messages API reference](/en/api/messages) for full documentation on available - * parameters. + * See the [Messages API reference](https://docs.claude.com/en/api/messages) for full + * documentation on available parameters. */ class Params @JsonCreator(mode = JsonCreator.Mode.DISABLED) @@ -744,6 +749,7 @@ private constructor( private val contextManagement: JsonField, private val mcpServers: JsonField>, private val metadata: JsonField, + private val outputConfig: JsonField, private val outputFormat: JsonField, private val serviceTier: JsonField, private val stopSequences: JsonField>, @@ -779,6 +785,9 @@ private constructor( @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), + @JsonProperty("output_config") + @ExcludeMissing + outputConfig: JsonField = JsonMissing.of(), @JsonProperty("output_format") @ExcludeMissing outputFormat: JsonField = JsonMissing.of(), @@ -816,6 +825,7 @@ private constructor( contextManagement, mcpServers, metadata, + outputConfig, outputFormat, serviceTier, stopSequences, @@ -958,6 +968,16 @@ private constructor( */ fun metadata(): Optional = metadata.getOptional("metadata") + /** + * Configuration options for the model's output. Controls aspects like how much effort + * the model puts into its response. + * + * @throws AnthropicInvalidDataException if the JSON field has an unexpected type (e.g. + * if the server responded with an unexpected value). + */ + fun outputConfig(): Optional = + outputConfig.getOptional("output_config") + /** * A schema to specify Claude's output format in responses. * @@ -1228,6 +1248,16 @@ private constructor( @ExcludeMissing fun _metadata(): JsonField = metadata + /** + * Returns the raw JSON value of [outputConfig]. + * + * Unlike [outputConfig], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("output_config") + @ExcludeMissing + fun _outputConfig(): JsonField = outputConfig + /** * Returns the raw JSON value of [outputFormat]. * @@ -1364,6 +1394,7 @@ private constructor( private var mcpServers: JsonField>? = null private var metadata: JsonField = JsonMissing.of() + private var outputConfig: JsonField = JsonMissing.of() private var outputFormat: JsonField = JsonMissing.of() private var serviceTier: JsonField = JsonMissing.of() private var stopSequences: JsonField>? = null @@ -1386,6 +1417,7 @@ private constructor( contextManagement = params.contextManagement mcpServers = params.mcpServers.map { it.toMutableList() } metadata = params.metadata + outputConfig = params.outputConfig outputFormat = params.outputFormat serviceTier = params.serviceTier stopSequences = params.stopSequences.map { it.toMutableList() } @@ -1697,6 +1729,24 @@ private constructor( */ fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + /** + * Configuration options for the model's output. Controls aspects like how much + * effort the model puts into its response. + */ + fun outputConfig(outputConfig: BetaOutputConfig) = + outputConfig(JsonField.of(outputConfig)) + + /** + * Sets [Builder.outputConfig] to an arbitrary JSON value. + * + * You should usually call [Builder.outputConfig] with a well-typed + * [BetaOutputConfig] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun outputConfig(outputConfig: JsonField) = apply { + this.outputConfig = outputConfig + } + /** A schema to specify Claude's output format in responses. */ fun outputFormat(outputFormat: BetaJsonOutputFormat?) = outputFormat(JsonField.ofNullable(outputFormat)) @@ -2081,6 +2131,13 @@ private constructor( fun addTool(textEditor20241022: BetaToolTextEditor20241022) = addTool(BetaToolUnion.ofTextEditor20241022(textEditor20241022)) + /** + * Alias for calling [addTool] with + * `BetaToolUnion.ofComputerUse20251124(computerUse20251124)`. + */ + fun addTool(computerUse20251124: BetaToolComputerUse20251124) = + addTool(BetaToolUnion.ofComputerUse20251124(computerUse20251124)) + /** * Alias for calling [addTool] with * `BetaToolUnion.ofTextEditor20250124(textEditor20250124)`. @@ -2116,6 +2173,24 @@ private constructor( fun addTool(webFetchTool20250910: BetaWebFetchTool20250910) = addTool(BetaToolUnion.ofWebFetchTool20250910(webFetchTool20250910)) + /** + * Alias for calling [addTool] with + * `BetaToolUnion.ofSearchToolBm25_20251119(searchToolBm25_20251119)`. + */ + fun addTool(searchToolBm25_20251119: BetaToolSearchToolBm25_20251119) = + addTool(BetaToolUnion.ofSearchToolBm25_20251119(searchToolBm25_20251119)) + + /** + * Alias for calling [addTool] with + * `BetaToolUnion.ofSearchToolRegex20251119(searchToolRegex20251119)`. + */ + fun addTool(searchToolRegex20251119: BetaToolSearchToolRegex20251119) = + addTool(BetaToolUnion.ofSearchToolRegex20251119(searchToolRegex20251119)) + + /** Alias for calling [addTool] with `BetaToolUnion.ofMcpToolset(mcpToolset)`. */ + fun addTool(mcpToolset: BetaMcpToolset) = + addTool(BetaToolUnion.ofMcpToolset(mcpToolset)) + /** * Only sample from the top K options for each subsequent token. * @@ -2203,6 +2278,7 @@ private constructor( contextManagement, (mcpServers ?: JsonMissing.of()).map { it.toImmutable() }, metadata, + outputConfig, outputFormat, serviceTier, (stopSequences ?: JsonMissing.of()).map { it.toImmutable() }, @@ -2232,6 +2308,7 @@ private constructor( contextManagement().ifPresent { it.validate() } mcpServers().ifPresent { it.forEach { it.validate() } } metadata().ifPresent { it.validate() } + outputConfig().ifPresent { it.validate() } outputFormat().ifPresent { it.validate() } serviceTier().ifPresent { it.validate() } stopSequences() @@ -2269,6 +2346,7 @@ private constructor( (contextManagement.asKnown().getOrNull()?.validity() ?: 0) + (mcpServers.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (outputConfig.asKnown().getOrNull()?.validity() ?: 0) + (outputFormat.asKnown().getOrNull()?.validity() ?: 0) + (serviceTier.asKnown().getOrNull()?.validity() ?: 0) + (stopSequences.asKnown().getOrNull()?.size ?: 0) + @@ -2815,6 +2893,7 @@ private constructor( contextManagement == other.contextManagement && mcpServers == other.mcpServers && metadata == other.metadata && + outputConfig == other.outputConfig && outputFormat == other.outputFormat && serviceTier == other.serviceTier && stopSequences == other.stopSequences && @@ -2838,6 +2917,7 @@ private constructor( contextManagement, mcpServers, metadata, + outputConfig, outputFormat, serviceTier, stopSequences, @@ -2856,7 +2936,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "Params{maxTokens=$maxTokens, messages=$messages, model=$model, container=$container, contextManagement=$contextManagement, mcpServers=$mcpServers, metadata=$metadata, outputFormat=$outputFormat, serviceTier=$serviceTier, stopSequences=$stopSequences, stream=$stream, system=$system, temperature=$temperature, thinking=$thinking, toolChoice=$toolChoice, tools=$tools, topK=$topK, topP=$topP, additionalProperties=$additionalProperties}" + "Params{maxTokens=$maxTokens, messages=$messages, model=$model, container=$container, contextManagement=$contextManagement, mcpServers=$mcpServers, metadata=$metadata, outputConfig=$outputConfig, outputFormat=$outputFormat, serviceTier=$serviceTier, stopSequences=$stopSequences, stream=$stream, system=$system, temperature=$temperature, thinking=$thinking, toolChoice=$toolChoice, tools=$tools, topK=$topK, topP=$topP, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/Model.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/Model.kt index c06f4c954..020476fbe 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/Model.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/Model.kt @@ -24,6 +24,12 @@ class Model @JsonCreator private constructor(private val value: JsonField Value.CLAUDE_OPUS_4_5_20251101 + CLAUDE_OPUS_4_5 -> Value.CLAUDE_OPUS_4_5 CLAUDE_3_7_SONNET_LATEST -> Value.CLAUDE_3_7_SONNET_LATEST CLAUDE_3_7_SONNET_20250219 -> Value.CLAUDE_3_7_SONNET_20250219 CLAUDE_3_5_HAIKU_LATEST -> Value.CLAUDE_3_5_HAIKU_LATEST @@ -253,6 +269,8 @@ class Model @JsonCreator private constructor(private val value: JsonField Known.CLAUDE_OPUS_4_5_20251101 + CLAUDE_OPUS_4_5 -> Known.CLAUDE_OPUS_4_5 CLAUDE_3_7_SONNET_LATEST -> Known.CLAUDE_3_7_SONNET_LATEST CLAUDE_3_7_SONNET_20250219 -> Known.CLAUDE_3_7_SONNET_20250219 CLAUDE_3_5_HAIKU_LATEST -> Known.CLAUDE_3_5_HAIKU_LATEST diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/batches/BatchCreateParams.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/batches/BatchCreateParams.kt index 481cf88ce..d0081a6e0 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/batches/BatchCreateParams.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/batches/BatchCreateParams.kt @@ -511,8 +511,8 @@ private constructor( /** * Messages API creation parameters for the individual request. * - * See the [Messages API reference](/en/api/messages) for full documentation on available - * parameters. + * See the [Messages API reference](https://docs.claude.com/en/api/messages) for full + * documentation on available parameters. * * @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). @@ -593,8 +593,8 @@ private constructor( /** * Messages API creation parameters for the individual request. * - * See the [Messages API reference](/en/api/messages) for full documentation on - * available parameters. + * See the [Messages API reference](https://docs.claude.com/en/api/messages) for full + * documentation on available parameters. */ fun params(params: Params) = params(JsonField.of(params)) @@ -681,8 +681,8 @@ private constructor( /** * Messages API creation parameters for the individual request. * - * See the [Messages API reference](/en/api/messages) for full documentation on available - * parameters. + * See the [Messages API reference](https://docs.claude.com/en/api/messages) for full + * documentation on available parameters. */ class Params @JsonCreator(mode = JsonCreator.Mode.DISABLED) diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/core/http/HttpRequestTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/core/http/HttpRequestTest.kt index 45cbcdfb2..95315d38a 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/core/http/HttpRequestTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/core/http/HttpRequestTest.kt @@ -2,8 +2,11 @@ package com.anthropic.core.http import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.EnumSource internal class HttpRequestTest { + @Test fun replaceAllPathSegmentsNoneWithNone() { val request1 = createRequest() @@ -63,4 +66,106 @@ internal class HttpRequestTest { .addPathSegments(*pathSegments) .build() } + + enum class UrlTestCase(val request: HttpRequest, val expectedUrl: String) { + BASE_URL_ONLY( + HttpRequest.builder().method(HttpMethod.GET).baseUrl("https://api.example.com").build(), + expectedUrl = "https://api.example.com", + ), + BASE_URL_WITH_TRAILING_SLASH( + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl("https://api.example.com/") + .build(), + expectedUrl = "https://api.example.com/", + ), + SINGLE_PATH_SEGMENT( + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl("https://api.example.com") + .addPathSegment("users") + .build(), + expectedUrl = "https://api.example.com/users", + ), + MULTIPLE_PATH_SEGMENTS( + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl("https://api.example.com") + .addPathSegments("users", "123", "profile") + .build(), + expectedUrl = "https://api.example.com/users/123/profile", + ), + PATH_SEGMENT_WITH_SPECIAL_CHARS( + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl("https://api.example.com") + .addPathSegment("user name") + .build(), + expectedUrl = "https://api.example.com/user+name", + ), + SINGLE_QUERY_PARAM( + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl("https://api.example.com") + .addPathSegment("users") + .putQueryParam("limit", "10") + .build(), + expectedUrl = "https://api.example.com/users?limit=10", + ), + MULTIPLE_QUERY_PARAMS( + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl("https://api.example.com") + .addPathSegment("users") + .putQueryParam("limit", "10") + .putQueryParam("offset", "20") + .build(), + expectedUrl = "https://api.example.com/users?limit=10&offset=20", + ), + QUERY_PARAM_WITH_SPECIAL_CHARS( + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl("https://api.example.com") + .addPathSegment("search") + .putQueryParam("q", "hello world") + .build(), + expectedUrl = "https://api.example.com/search?q=hello+world", + ), + MULTIPLE_VALUES_SAME_PARAM( + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl("https://api.example.com") + .addPathSegment("users") + .putQueryParams("tags", listOf("admin", "user")) + .build(), + expectedUrl = "https://api.example.com/users?tags=admin&tags=user", + ), + BASE_URL_WITH_TRAILING_SLASH_AND_PATH( + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl("https://api.example.com/") + .addPathSegment("users") + .build(), + expectedUrl = "https://api.example.com/users", + ), + COMPLEX_URL( + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl("https://api.example.com") + .addPathSegments("v1", "users", "123") + .putQueryParams("include", listOf("profile", "settings")) + .putQueryParam("format", "json") + .build(), + expectedUrl = + "https://api.example.com/v1/users/123?include=profile&include=settings&format=json", + ), + } + + @ParameterizedTest + @EnumSource + fun url(testCase: UrlTestCase) { + val actualUrl = testCase.request.url() + + assertThat(actualUrl).isEqualTo(testCase.expectedUrl) + } } diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/helpers/BetaMessageAccumulatorTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/helpers/BetaMessageAccumulatorTest.kt index a24a48d47..559f7c3ea 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/helpers/BetaMessageAccumulatorTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/helpers/BetaMessageAccumulatorTest.kt @@ -602,6 +602,74 @@ internal class BetaMessageAccumulatorTest { .hasMessage("Missing input JSON for index 1.") } + @Test + fun accumulateToolUseContentBlockWithEmptyInput() { + val accumulator = BetaMessageAccumulator.create() + + accumulator.accumulate(messageStartEvent()) + accumulator.accumulate(toolUseContentBlockStartEvent(1L, "1-TOOL.")) + + // Tool use content block deltas will build up the JSON string: {} + accumulator.accumulate(toolUseContentBlockDeltaEvent(1L, "{")) + accumulator.accumulate(toolUseContentBlockDeltaEvent(1L, "}")) + + accumulator.accumulate(contentBlockStopEvent(1L)) + accumulator.accumulate( + messageDeltaEvent( + stopReason = JsonField.of(BetaStopReason.TOOL_USE), + outputTokens = 88L, + ) + ) + accumulator.accumulate(messageStopEvent()) + + val message = accumulator.message() + val content = message.content() + + assertThat(message.stopSequence()).isEmpty() + assertThat(message.stopReason()).hasValue(BetaStopReason.TOOL_USE) + assertThat(message.usage().inputTokens()).isEqualTo(INPUT_TOKENS) + assertThat(message.usage().outputTokens()).isEqualTo(88L) + + assertThat(content.size).isEqualTo(1) + assertThat(content[0].asToolUse().name()).isEqualTo("1-TOOL.") + assertThat(content[0].asToolUse()._input().asObject().get()).isEmpty() + } + + @Test + fun accumulateToolUseContentBlockWithNoInput() { + val accumulator = BetaMessageAccumulator.create() + + accumulator.accumulate(messageStartEvent()) + accumulator.accumulate(toolUseContentBlockStartEvent(1L, "1-TOOL.")) + + // Tool use content block deltas will build up an empty JSON string. This behavior was + // observed in issue #249. It should be interpreted as a missing field. Whitespace should + // be ignored. + accumulator.accumulate(toolUseContentBlockDeltaEvent(1L, "")) + accumulator.accumulate(toolUseContentBlockDeltaEvent(1L, " ")) + + accumulator.accumulate(contentBlockStopEvent(1L)) + accumulator.accumulate( + messageDeltaEvent( + stopReason = JsonField.of(BetaStopReason.TOOL_USE), + outputTokens = 88L, + ) + ) + accumulator.accumulate(messageStopEvent()) + + val message = accumulator.message() + val content = message.content() + + assertThat(message.stopSequence()).isEmpty() + assertThat(message.stopReason()).hasValue(BetaStopReason.TOOL_USE) + assertThat(message.usage().inputTokens()).isEqualTo(INPUT_TOKENS) + assertThat(message.usage().outputTokens()).isEqualTo(88L) + + assertThat(content.size).isEqualTo(1) + assertThat(content[0].asToolUse().name()).isEqualTo("1-TOOL.") + assertThat(content[0].asToolUse()._input().isMissing()).isTrue() + } + @Test fun accumulateTextAndToolUseContentBlocks() { val accumulator = BetaMessageAccumulator.create() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/files/FileDeleteParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/files/FileDeleteParamsTest.kt index 81708f8ee..0fc94fc31 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/files/FileDeleteParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/files/FileDeleteParamsTest.kt @@ -11,10 +11,7 @@ internal class FileDeleteParamsTest { @Test fun create() { - FileDeleteParams.builder() - .fileId("file_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) - .build() + FileDeleteParams.builder().fileId("file_id").addBeta(AnthropicBeta.of("string")).build() } @Test @@ -29,17 +26,11 @@ internal class FileDeleteParamsTest { @Test fun headers() { val params = - FileDeleteParams.builder() - .fileId("file_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) - .build() + FileDeleteParams.builder().fileId("file_id").addBeta(AnthropicBeta.of("string")).build() val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/files/FileDownloadParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/files/FileDownloadParamsTest.kt index b2c7be885..3074f2b37 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/files/FileDownloadParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/files/FileDownloadParamsTest.kt @@ -11,10 +11,7 @@ internal class FileDownloadParamsTest { @Test fun create() { - FileDownloadParams.builder() - .fileId("file_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) - .build() + FileDownloadParams.builder().fileId("file_id").addBeta(AnthropicBeta.of("string")).build() } @Test @@ -31,15 +28,12 @@ internal class FileDownloadParamsTest { val params = FileDownloadParams.builder() .fileId("file_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/files/FileListParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/files/FileListParamsTest.kt index 90491a797..357e32608 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/files/FileListParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/files/FileListParamsTest.kt @@ -16,7 +16,7 @@ internal class FileListParamsTest { .afterId("after_id") .beforeId("before_id") .limit(1L) - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() } @@ -27,15 +27,12 @@ internal class FileListParamsTest { .afterId("after_id") .beforeId("before_id") .limit(1L) - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test @@ -54,7 +51,7 @@ internal class FileListParamsTest { .afterId("after_id") .beforeId("before_id") .limit(1L) - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() val queryParams = params._queryParams() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/files/FileRetrieveMetadataParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/files/FileRetrieveMetadataParamsTest.kt index fee2e0bb5..99c616a6e 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/files/FileRetrieveMetadataParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/files/FileRetrieveMetadataParamsTest.kt @@ -13,7 +13,7 @@ internal class FileRetrieveMetadataParamsTest { fun create() { FileRetrieveMetadataParams.builder() .fileId("file_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() } @@ -31,15 +31,12 @@ internal class FileRetrieveMetadataParamsTest { val params = FileRetrieveMetadataParams.builder() .fileId("file_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/files/FileUploadParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/files/FileUploadParamsTest.kt index 3b187d24b..25c6018e9 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/files/FileUploadParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/files/FileUploadParamsTest.kt @@ -14,7 +14,7 @@ internal class FileUploadParamsTest { @Test fun create() { FileUploadParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .file("some content".byteInputStream()) .build() } @@ -23,16 +23,13 @@ internal class FileUploadParamsTest { fun headers() { val params = FileUploadParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .file("some content".byteInputStream()) .build() val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test @@ -48,7 +45,7 @@ internal class FileUploadParamsTest { fun body() { val params = FileUploadParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .file("some content".byteInputStream()) .build() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaCodeExecutionTool20250522Test.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaCodeExecutionTool20250522Test.kt index 994dbdc0b..7d0d84bc5 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaCodeExecutionTool20250522Test.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaCodeExecutionTool20250522Test.kt @@ -4,6 +4,7 @@ package com.anthropic.models.beta.messages import com.anthropic.core.jsonMapper import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -13,20 +14,25 @@ internal class BetaCodeExecutionTool20250522Test { fun create() { val betaCodeExecutionTool20250522 = BetaCodeExecutionTool20250522.builder() + .addAllowedCaller(BetaCodeExecutionTool20250522.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .strict(true) .build() + assertThat(betaCodeExecutionTool20250522.allowedCallers().getOrNull()) + .containsExactly(BetaCodeExecutionTool20250522.AllowedCaller.DIRECT) assertThat(betaCodeExecutionTool20250522.cacheControl()) .contains( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + assertThat(betaCodeExecutionTool20250522.deferLoading()).contains(true) assertThat(betaCodeExecutionTool20250522.strict()).contains(true) } @@ -35,11 +41,13 @@ internal class BetaCodeExecutionTool20250522Test { val jsonMapper = jsonMapper() val betaCodeExecutionTool20250522 = BetaCodeExecutionTool20250522.builder() + .addAllowedCaller(BetaCodeExecutionTool20250522.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .strict(true) .build() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaCodeExecutionTool20250825Test.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaCodeExecutionTool20250825Test.kt index c6c00e000..48ab9f8c4 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaCodeExecutionTool20250825Test.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaCodeExecutionTool20250825Test.kt @@ -4,6 +4,7 @@ package com.anthropic.models.beta.messages import com.anthropic.core.jsonMapper import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -13,20 +14,25 @@ internal class BetaCodeExecutionTool20250825Test { fun create() { val betaCodeExecutionTool20250825 = BetaCodeExecutionTool20250825.builder() + .addAllowedCaller(BetaCodeExecutionTool20250825.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .strict(true) .build() + assertThat(betaCodeExecutionTool20250825.allowedCallers().getOrNull()) + .containsExactly(BetaCodeExecutionTool20250825.AllowedCaller.DIRECT) assertThat(betaCodeExecutionTool20250825.cacheControl()) .contains( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + assertThat(betaCodeExecutionTool20250825.deferLoading()).contains(true) assertThat(betaCodeExecutionTool20250825.strict()).contains(true) } @@ -35,11 +41,13 @@ internal class BetaCodeExecutionTool20250825Test { val jsonMapper = jsonMapper() val betaCodeExecutionTool20250825 = BetaCodeExecutionTool20250825.builder() + .addAllowedCaller(BetaCodeExecutionTool20250825.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .strict(true) .build() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaContentBlockParamTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaContentBlockParamTest.kt index ab709a177..d07c7e809 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaContentBlockParamTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaContentBlockParamTest.kt @@ -51,6 +51,7 @@ internal class BetaContentBlockParamTest { assertThat(betaContentBlockParam.codeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlockParam.toolSearchToolResult()).isEmpty assertThat(betaContentBlockParam.mcpToolUse()).isEmpty assertThat(betaContentBlockParam.mcpToolResult()).isEmpty assertThat(betaContentBlockParam.containerUpload()).isEmpty @@ -122,6 +123,7 @@ internal class BetaContentBlockParamTest { assertThat(betaContentBlockParam.codeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlockParam.toolSearchToolResult()).isEmpty assertThat(betaContentBlockParam.mcpToolUse()).isEmpty assertThat(betaContentBlockParam.mcpToolResult()).isEmpty assertThat(betaContentBlockParam.containerUpload()).isEmpty @@ -187,6 +189,7 @@ internal class BetaContentBlockParamTest { assertThat(betaContentBlockParam.codeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlockParam.toolSearchToolResult()).isEmpty assertThat(betaContentBlockParam.mcpToolUse()).isEmpty assertThat(betaContentBlockParam.mcpToolResult()).isEmpty assertThat(betaContentBlockParam.containerUpload()).isEmpty @@ -268,6 +271,7 @@ internal class BetaContentBlockParamTest { assertThat(betaContentBlockParam.codeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlockParam.toolSearchToolResult()).isEmpty assertThat(betaContentBlockParam.mcpToolUse()).isEmpty assertThat(betaContentBlockParam.mcpToolResult()).isEmpty assertThat(betaContentBlockParam.containerUpload()).isEmpty @@ -339,6 +343,7 @@ internal class BetaContentBlockParamTest { assertThat(betaContentBlockParam.codeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlockParam.toolSearchToolResult()).isEmpty assertThat(betaContentBlockParam.mcpToolUse()).isEmpty assertThat(betaContentBlockParam.mcpToolResult()).isEmpty assertThat(betaContentBlockParam.containerUpload()).isEmpty @@ -381,6 +386,7 @@ internal class BetaContentBlockParamTest { assertThat(betaContentBlockParam.codeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlockParam.toolSearchToolResult()).isEmpty assertThat(betaContentBlockParam.mcpToolUse()).isEmpty assertThat(betaContentBlockParam.mcpToolResult()).isEmpty assertThat(betaContentBlockParam.containerUpload()).isEmpty @@ -419,6 +425,7 @@ internal class BetaContentBlockParamTest { .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .caller(BetaDirectCaller.builder().build()) .build() val betaContentBlockParam = BetaContentBlockParam.ofToolUse(toolUse) @@ -437,6 +444,7 @@ internal class BetaContentBlockParamTest { assertThat(betaContentBlockParam.codeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlockParam.toolSearchToolResult()).isEmpty assertThat(betaContentBlockParam.mcpToolUse()).isEmpty assertThat(betaContentBlockParam.mcpToolResult()).isEmpty assertThat(betaContentBlockParam.containerUpload()).isEmpty @@ -460,6 +468,7 @@ internal class BetaContentBlockParamTest { .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .caller(BetaDirectCaller.builder().build()) .build() ) @@ -502,6 +511,7 @@ internal class BetaContentBlockParamTest { assertThat(betaContentBlockParam.codeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlockParam.toolSearchToolResult()).isEmpty assertThat(betaContentBlockParam.mcpToolUse()).isEmpty assertThat(betaContentBlockParam.mcpToolResult()).isEmpty assertThat(betaContentBlockParam.containerUpload()).isEmpty @@ -549,6 +559,7 @@ internal class BetaContentBlockParamTest { .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .caller(BetaDirectCaller.builder().build()) .build() val betaContentBlockParam = BetaContentBlockParam.ofServerToolUse(serverToolUse) @@ -567,6 +578,7 @@ internal class BetaContentBlockParamTest { assertThat(betaContentBlockParam.codeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlockParam.toolSearchToolResult()).isEmpty assertThat(betaContentBlockParam.mcpToolUse()).isEmpty assertThat(betaContentBlockParam.mcpToolResult()).isEmpty assertThat(betaContentBlockParam.containerUpload()).isEmpty @@ -590,6 +602,7 @@ internal class BetaContentBlockParamTest { .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .caller(BetaDirectCaller.builder().build()) .build() ) @@ -640,6 +653,7 @@ internal class BetaContentBlockParamTest { assertThat(betaContentBlockParam.codeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlockParam.toolSearchToolResult()).isEmpty assertThat(betaContentBlockParam.mcpToolUse()).isEmpty assertThat(betaContentBlockParam.mcpToolResult()).isEmpty assertThat(betaContentBlockParam.containerUpload()).isEmpty @@ -712,6 +726,7 @@ internal class BetaContentBlockParamTest { assertThat(betaContentBlockParam.codeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlockParam.toolSearchToolResult()).isEmpty assertThat(betaContentBlockParam.mcpToolUse()).isEmpty assertThat(betaContentBlockParam.mcpToolResult()).isEmpty assertThat(betaContentBlockParam.containerUpload()).isEmpty @@ -781,6 +796,7 @@ internal class BetaContentBlockParamTest { .contains(codeExecutionToolResult) assertThat(betaContentBlockParam.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlockParam.toolSearchToolResult()).isEmpty assertThat(betaContentBlockParam.mcpToolUse()).isEmpty assertThat(betaContentBlockParam.mcpToolResult()).isEmpty assertThat(betaContentBlockParam.containerUpload()).isEmpty @@ -852,6 +868,7 @@ internal class BetaContentBlockParamTest { assertThat(betaContentBlockParam.bashCodeExecutionToolResult()) .contains(bashCodeExecutionToolResult) assertThat(betaContentBlockParam.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlockParam.toolSearchToolResult()).isEmpty assertThat(betaContentBlockParam.mcpToolUse()).isEmpty assertThat(betaContentBlockParam.mcpToolResult()).isEmpty assertThat(betaContentBlockParam.containerUpload()).isEmpty @@ -930,6 +947,7 @@ internal class BetaContentBlockParamTest { assertThat(betaContentBlockParam.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.textEditorCodeExecutionToolResult()) .contains(textEditorCodeExecutionToolResult) + assertThat(betaContentBlockParam.toolSearchToolResult()).isEmpty assertThat(betaContentBlockParam.mcpToolUse()).isEmpty assertThat(betaContentBlockParam.mcpToolResult()).isEmpty assertThat(betaContentBlockParam.containerUpload()).isEmpty @@ -968,6 +986,77 @@ internal class BetaContentBlockParamTest { assertThat(roundtrippedBetaContentBlockParam).isEqualTo(betaContentBlockParam) } + @Test + fun ofToolSearchToolResult() { + val toolSearchToolResult = + BetaToolSearchToolResultBlockParam.builder() + .content( + BetaToolSearchToolResultErrorParam.builder() + .errorCode(BetaToolSearchToolResultErrorParam.ErrorCode.INVALID_TOOL_INPUT) + .build() + ) + .toolUseId("srvtoolu_SQfNkl1n_JR_") + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .build() + + val betaContentBlockParam = + BetaContentBlockParam.ofToolSearchToolResult(toolSearchToolResult) + + assertThat(betaContentBlockParam.text()).isEmpty + assertThat(betaContentBlockParam.image()).isEmpty + assertThat(betaContentBlockParam.document()).isEmpty + assertThat(betaContentBlockParam.searchResult()).isEmpty + assertThat(betaContentBlockParam.thinking()).isEmpty + assertThat(betaContentBlockParam.redactedThinking()).isEmpty + assertThat(betaContentBlockParam.toolUse()).isEmpty + assertThat(betaContentBlockParam.toolResult()).isEmpty + assertThat(betaContentBlockParam.serverToolUse()).isEmpty + assertThat(betaContentBlockParam.webSearchToolResult()).isEmpty + assertThat(betaContentBlockParam.webFetchToolResult()).isEmpty + assertThat(betaContentBlockParam.codeExecutionToolResult()).isEmpty + assertThat(betaContentBlockParam.bashCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlockParam.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlockParam.toolSearchToolResult()).contains(toolSearchToolResult) + assertThat(betaContentBlockParam.mcpToolUse()).isEmpty + assertThat(betaContentBlockParam.mcpToolResult()).isEmpty + assertThat(betaContentBlockParam.containerUpload()).isEmpty + } + + @Test + fun ofToolSearchToolResultRoundtrip() { + val jsonMapper = jsonMapper() + val betaContentBlockParam = + BetaContentBlockParam.ofToolSearchToolResult( + BetaToolSearchToolResultBlockParam.builder() + .content( + BetaToolSearchToolResultErrorParam.builder() + .errorCode( + BetaToolSearchToolResultErrorParam.ErrorCode.INVALID_TOOL_INPUT + ) + .build() + ) + .toolUseId("srvtoolu_SQfNkl1n_JR_") + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .build() + ) + + val roundtrippedBetaContentBlockParam = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaContentBlockParam), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaContentBlockParam).isEqualTo(betaContentBlockParam) + } + @Test fun ofMcpToolUse() { val mcpToolUse = @@ -1003,6 +1092,7 @@ internal class BetaContentBlockParamTest { assertThat(betaContentBlockParam.codeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlockParam.toolSearchToolResult()).isEmpty assertThat(betaContentBlockParam.mcpToolUse()).contains(mcpToolUse) assertThat(betaContentBlockParam.mcpToolResult()).isEmpty assertThat(betaContentBlockParam.containerUpload()).isEmpty @@ -1069,6 +1159,7 @@ internal class BetaContentBlockParamTest { assertThat(betaContentBlockParam.codeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlockParam.toolSearchToolResult()).isEmpty assertThat(betaContentBlockParam.mcpToolUse()).isEmpty assertThat(betaContentBlockParam.mcpToolResult()).contains(mcpToolResult) assertThat(betaContentBlockParam.containerUpload()).isEmpty @@ -1128,6 +1219,7 @@ internal class BetaContentBlockParamTest { assertThat(betaContentBlockParam.codeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlockParam.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlockParam.toolSearchToolResult()).isEmpty assertThat(betaContentBlockParam.mcpToolUse()).isEmpty assertThat(betaContentBlockParam.mcpToolResult()).isEmpty assertThat(betaContentBlockParam.containerUpload()).contains(containerUpload) diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaContentBlockTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaContentBlockTest.kt index 4c639b353..273e14fd2 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaContentBlockTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaContentBlockTest.kt @@ -43,6 +43,7 @@ internal class BetaContentBlockTest { assertThat(betaContentBlock.codeExecutionToolResult()).isEmpty assertThat(betaContentBlock.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlock.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlock.toolSearchToolResult()).isEmpty assertThat(betaContentBlock.mcpToolUse()).isEmpty assertThat(betaContentBlock.mcpToolResult()).isEmpty assertThat(betaContentBlock.containerUpload()).isEmpty @@ -94,6 +95,7 @@ internal class BetaContentBlockTest { assertThat(betaContentBlock.codeExecutionToolResult()).isEmpty assertThat(betaContentBlock.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlock.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlock.toolSearchToolResult()).isEmpty assertThat(betaContentBlock.mcpToolUse()).isEmpty assertThat(betaContentBlock.mcpToolResult()).isEmpty assertThat(betaContentBlock.containerUpload()).isEmpty @@ -132,6 +134,7 @@ internal class BetaContentBlockTest { assertThat(betaContentBlock.codeExecutionToolResult()).isEmpty assertThat(betaContentBlock.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlock.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlock.toolSearchToolResult()).isEmpty assertThat(betaContentBlock.mcpToolUse()).isEmpty assertThat(betaContentBlock.mcpToolResult()).isEmpty assertThat(betaContentBlock.containerUpload()).isEmpty @@ -161,6 +164,7 @@ internal class BetaContentBlockTest { .id("id") .input(JsonValue.from(mapOf())) .name("x") + .caller(BetaDirectCaller.builder().build()) .build() val betaContentBlock = BetaContentBlock.ofToolUse(toolUse) @@ -175,6 +179,7 @@ internal class BetaContentBlockTest { assertThat(betaContentBlock.codeExecutionToolResult()).isEmpty assertThat(betaContentBlock.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlock.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlock.toolSearchToolResult()).isEmpty assertThat(betaContentBlock.mcpToolUse()).isEmpty assertThat(betaContentBlock.mcpToolResult()).isEmpty assertThat(betaContentBlock.containerUpload()).isEmpty @@ -189,6 +194,7 @@ internal class BetaContentBlockTest { .id("id") .input(JsonValue.from(mapOf())) .name("x") + .caller(BetaDirectCaller.builder().build()) .build() ) @@ -207,6 +213,7 @@ internal class BetaContentBlockTest { BetaServerToolUseBlock.builder() .id("srvtoolu_SQfNkl1n_JR_") .input(JsonValue.from(mapOf())) + .caller(BetaDirectCaller.builder().build()) .name(BetaServerToolUseBlock.Name.WEB_SEARCH) .build() @@ -222,6 +229,7 @@ internal class BetaContentBlockTest { assertThat(betaContentBlock.codeExecutionToolResult()).isEmpty assertThat(betaContentBlock.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlock.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlock.toolSearchToolResult()).isEmpty assertThat(betaContentBlock.mcpToolUse()).isEmpty assertThat(betaContentBlock.mcpToolResult()).isEmpty assertThat(betaContentBlock.containerUpload()).isEmpty @@ -234,6 +242,7 @@ internal class BetaContentBlockTest { BetaContentBlock.ofServerToolUse( BetaServerToolUseBlock.builder() .id("srvtoolu_SQfNkl1n_JR_") + .caller(BetaDirectCaller.builder().build()) .input(JsonValue.from(mapOf())) .name(BetaServerToolUseBlock.Name.WEB_SEARCH) .build() @@ -272,6 +281,7 @@ internal class BetaContentBlockTest { assertThat(betaContentBlock.codeExecutionToolResult()).isEmpty assertThat(betaContentBlock.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlock.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlock.toolSearchToolResult()).isEmpty assertThat(betaContentBlock.mcpToolUse()).isEmpty assertThat(betaContentBlock.mcpToolResult()).isEmpty assertThat(betaContentBlock.containerUpload()).isEmpty @@ -325,6 +335,7 @@ internal class BetaContentBlockTest { assertThat(betaContentBlock.codeExecutionToolResult()).isEmpty assertThat(betaContentBlock.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlock.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlock.toolSearchToolResult()).isEmpty assertThat(betaContentBlock.mcpToolUse()).isEmpty assertThat(betaContentBlock.mcpToolResult()).isEmpty assertThat(betaContentBlock.containerUpload()).isEmpty @@ -378,6 +389,7 @@ internal class BetaContentBlockTest { assertThat(betaContentBlock.codeExecutionToolResult()).contains(codeExecutionToolResult) assertThat(betaContentBlock.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlock.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlock.toolSearchToolResult()).isEmpty assertThat(betaContentBlock.mcpToolUse()).isEmpty assertThat(betaContentBlock.mcpToolResult()).isEmpty assertThat(betaContentBlock.containerUpload()).isEmpty @@ -435,6 +447,7 @@ internal class BetaContentBlockTest { assertThat(betaContentBlock.bashCodeExecutionToolResult()) .contains(bashCodeExecutionToolResult) assertThat(betaContentBlock.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlock.toolSearchToolResult()).isEmpty assertThat(betaContentBlock.mcpToolUse()).isEmpty assertThat(betaContentBlock.mcpToolResult()).isEmpty assertThat(betaContentBlock.containerUpload()).isEmpty @@ -495,6 +508,7 @@ internal class BetaContentBlockTest { assertThat(betaContentBlock.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlock.textEditorCodeExecutionToolResult()) .contains(textEditorCodeExecutionToolResult) + assertThat(betaContentBlock.toolSearchToolResult()).isEmpty assertThat(betaContentBlock.mcpToolUse()).isEmpty assertThat(betaContentBlock.mcpToolResult()).isEmpty assertThat(betaContentBlock.containerUpload()).isEmpty @@ -528,6 +542,62 @@ internal class BetaContentBlockTest { assertThat(roundtrippedBetaContentBlock).isEqualTo(betaContentBlock) } + @Test + fun ofToolSearchToolResult() { + val toolSearchToolResult = + BetaToolSearchToolResultBlock.builder() + .content( + BetaToolSearchToolResultError.builder() + .errorCode(BetaToolSearchToolResultError.ErrorCode.INVALID_TOOL_INPUT) + .errorMessage("error_message") + .build() + ) + .toolUseId("srvtoolu_SQfNkl1n_JR_") + .build() + + val betaContentBlock = BetaContentBlock.ofToolSearchToolResult(toolSearchToolResult) + + assertThat(betaContentBlock.text()).isEmpty + assertThat(betaContentBlock.thinking()).isEmpty + assertThat(betaContentBlock.redactedThinking()).isEmpty + assertThat(betaContentBlock.toolUse()).isEmpty + assertThat(betaContentBlock.serverToolUse()).isEmpty + assertThat(betaContentBlock.webSearchToolResult()).isEmpty + assertThat(betaContentBlock.webFetchToolResult()).isEmpty + assertThat(betaContentBlock.codeExecutionToolResult()).isEmpty + assertThat(betaContentBlock.bashCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlock.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlock.toolSearchToolResult()).contains(toolSearchToolResult) + assertThat(betaContentBlock.mcpToolUse()).isEmpty + assertThat(betaContentBlock.mcpToolResult()).isEmpty + assertThat(betaContentBlock.containerUpload()).isEmpty + } + + @Test + fun ofToolSearchToolResultRoundtrip() { + val jsonMapper = jsonMapper() + val betaContentBlock = + BetaContentBlock.ofToolSearchToolResult( + BetaToolSearchToolResultBlock.builder() + .content( + BetaToolSearchToolResultError.builder() + .errorCode(BetaToolSearchToolResultError.ErrorCode.INVALID_TOOL_INPUT) + .errorMessage("error_message") + .build() + ) + .toolUseId("srvtoolu_SQfNkl1n_JR_") + .build() + ) + + val roundtrippedBetaContentBlock = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaContentBlock), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaContentBlock).isEqualTo(betaContentBlock) + } + @Test fun ofMcpToolUse() { val mcpToolUse = @@ -550,6 +620,7 @@ internal class BetaContentBlockTest { assertThat(betaContentBlock.codeExecutionToolResult()).isEmpty assertThat(betaContentBlock.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlock.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlock.toolSearchToolResult()).isEmpty assertThat(betaContentBlock.mcpToolUse()).contains(mcpToolUse) assertThat(betaContentBlock.mcpToolResult()).isEmpty assertThat(betaContentBlock.containerUpload()).isEmpty @@ -598,6 +669,7 @@ internal class BetaContentBlockTest { assertThat(betaContentBlock.codeExecutionToolResult()).isEmpty assertThat(betaContentBlock.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlock.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlock.toolSearchToolResult()).isEmpty assertThat(betaContentBlock.mcpToolUse()).isEmpty assertThat(betaContentBlock.mcpToolResult()).contains(mcpToolResult) assertThat(betaContentBlock.containerUpload()).isEmpty @@ -640,6 +712,7 @@ internal class BetaContentBlockTest { assertThat(betaContentBlock.codeExecutionToolResult()).isEmpty assertThat(betaContentBlock.bashCodeExecutionToolResult()).isEmpty assertThat(betaContentBlock.textEditorCodeExecutionToolResult()).isEmpty + assertThat(betaContentBlock.toolSearchToolResult()).isEmpty assertThat(betaContentBlock.mcpToolUse()).isEmpty assertThat(betaContentBlock.mcpToolResult()).isEmpty assertThat(betaContentBlock.containerUpload()).contains(containerUpload) diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaDirectCallerTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaDirectCallerTest.kt new file mode 100644 index 000000000..6be4f9e26 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaDirectCallerTest.kt @@ -0,0 +1,30 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 BetaDirectCallerTest { + + @Test + fun create() { + val betaDirectCaller = BetaDirectCaller.builder().build() + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaDirectCaller = BetaDirectCaller.builder().build() + + val roundtrippedBetaDirectCaller = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaDirectCaller), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaDirectCaller).isEqualTo(betaDirectCaller) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaMcpToolConfigTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaMcpToolConfigTest.kt new file mode 100644 index 000000000..230ab5e9c --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaMcpToolConfigTest.kt @@ -0,0 +1,33 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 BetaMcpToolConfigTest { + + @Test + fun create() { + val betaMcpToolConfig = BetaMcpToolConfig.builder().deferLoading(true).enabled(true).build() + + assertThat(betaMcpToolConfig.deferLoading()).contains(true) + assertThat(betaMcpToolConfig.enabled()).contains(true) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaMcpToolConfig = BetaMcpToolConfig.builder().deferLoading(true).enabled(true).build() + + val roundtrippedBetaMcpToolConfig = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaMcpToolConfig), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaMcpToolConfig).isEqualTo(betaMcpToolConfig) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaMcpToolDefaultConfigTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaMcpToolDefaultConfigTest.kt new file mode 100644 index 000000000..7af942ef8 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaMcpToolDefaultConfigTest.kt @@ -0,0 +1,35 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 BetaMcpToolDefaultConfigTest { + + @Test + fun create() { + val betaMcpToolDefaultConfig = + BetaMcpToolDefaultConfig.builder().deferLoading(true).enabled(true).build() + + assertThat(betaMcpToolDefaultConfig.deferLoading()).contains(true) + assertThat(betaMcpToolDefaultConfig.enabled()).contains(true) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaMcpToolDefaultConfig = + BetaMcpToolDefaultConfig.builder().deferLoading(true).enabled(true).build() + + val roundtrippedBetaMcpToolDefaultConfig = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaMcpToolDefaultConfig), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaMcpToolDefaultConfig).isEqualTo(betaMcpToolDefaultConfig) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaMcpToolsetTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaMcpToolsetTest.kt new file mode 100644 index 000000000..b1772cc31 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaMcpToolsetTest.kt @@ -0,0 +1,88 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +import com.anthropic.core.JsonValue +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 BetaMcpToolsetTest { + + @Test + fun create() { + val betaMcpToolset = + BetaMcpToolset.builder() + .mcpServerName("x") + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .configs( + BetaMcpToolset.Configs.builder() + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf("defer_loading" to true, "enabled" to true)), + ) + .build() + ) + .defaultConfig( + BetaMcpToolDefaultConfig.builder().deferLoading(true).enabled(true).build() + ) + .build() + + assertThat(betaMcpToolset.mcpServerName()).isEqualTo("x") + assertThat(betaMcpToolset.cacheControl()) + .contains( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + assertThat(betaMcpToolset.configs()) + .contains( + BetaMcpToolset.Configs.builder() + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf("defer_loading" to true, "enabled" to true)), + ) + .build() + ) + assertThat(betaMcpToolset.defaultConfig()) + .contains(BetaMcpToolDefaultConfig.builder().deferLoading(true).enabled(true).build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaMcpToolset = + BetaMcpToolset.builder() + .mcpServerName("x") + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .configs( + BetaMcpToolset.Configs.builder() + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf("defer_loading" to true, "enabled" to true)), + ) + .build() + ) + .defaultConfig( + BetaMcpToolDefaultConfig.builder().deferLoading(true).enabled(true).build() + ) + .build() + + val roundtrippedBetaMcpToolset = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaMcpToolset), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaMcpToolset).isEqualTo(betaMcpToolset) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaMemoryTool20250818Test.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaMemoryTool20250818Test.kt index 73b054074..1e68d1046 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaMemoryTool20250818Test.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaMemoryTool20250818Test.kt @@ -2,8 +2,10 @@ package com.anthropic.models.beta.messages +import com.anthropic.core.JsonValue import com.anthropic.core.jsonMapper import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -13,20 +15,36 @@ internal class BetaMemoryTool20250818Test { fun create() { val betaMemoryTool20250818 = BetaMemoryTool20250818.builder() + .addAllowedCaller(BetaMemoryTool20250818.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaMemoryTool20250818.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() + assertThat(betaMemoryTool20250818.allowedCallers().getOrNull()) + .containsExactly(BetaMemoryTool20250818.AllowedCaller.DIRECT) assertThat(betaMemoryTool20250818.cacheControl()) .contains( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + assertThat(betaMemoryTool20250818.deferLoading()).contains(true) + assertThat(betaMemoryTool20250818.inputExamples().getOrNull()) + .containsExactly( + BetaMemoryTool20250818.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) assertThat(betaMemoryTool20250818.strict()).contains(true) } @@ -35,11 +53,18 @@ internal class BetaMemoryTool20250818Test { val jsonMapper = jsonMapper() val betaMemoryTool20250818 = BetaMemoryTool20250818.builder() + .addAllowedCaller(BetaMemoryTool20250818.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaMemoryTool20250818.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaMessageTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaMessageTest.kt index f6dc370ab..e332accc9 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaMessageTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaMessageTest.kt @@ -54,7 +54,7 @@ internal class BetaMessageTest { ) .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(BetaStopReason.END_TURN) .stopSequence(null) .usage( @@ -124,7 +124,7 @@ internal class BetaMessageTest { ) .build() ) - assertThat(betaMessage.model()).isEqualTo(Model.CLAUDE_3_7_SONNET_LATEST) + assertThat(betaMessage.model()).isEqualTo(Model.CLAUDE_SONNET_4_5_20250929) assertThat(betaMessage.stopReason()).contains(BetaStopReason.END_TURN) assertThat(betaMessage.stopSequence()).isEmpty assertThat(betaMessage.usage()) @@ -195,7 +195,7 @@ internal class BetaMessageTest { ) .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(BetaStopReason.END_TURN) .stopSequence(null) .usage( diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaOutputConfigTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaOutputConfigTest.kt new file mode 100644 index 000000000..d3e484dff --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaOutputConfigTest.kt @@ -0,0 +1,34 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 BetaOutputConfigTest { + + @Test + fun create() { + val betaOutputConfig = + BetaOutputConfig.builder().effort(BetaOutputConfig.Effort.LOW).build() + + assertThat(betaOutputConfig.effort()).contains(BetaOutputConfig.Effort.LOW) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaOutputConfig = + BetaOutputConfig.builder().effort(BetaOutputConfig.Effort.LOW).build() + + val roundtrippedBetaOutputConfig = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaOutputConfig), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaOutputConfig).isEqualTo(betaOutputConfig) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaRawMessageStartEventTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaRawMessageStartEventTest.kt index 72d1fce94..c0b76fe41 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaRawMessageStartEventTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaRawMessageStartEventTest.kt @@ -56,7 +56,7 @@ internal class BetaRawMessageStartEventTest { ) .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(BetaStopReason.END_TURN) .stopSequence(null) .usage( @@ -126,7 +126,7 @@ internal class BetaRawMessageStartEventTest { ) .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(BetaStopReason.END_TURN) .stopSequence(null) .usage( @@ -200,7 +200,7 @@ internal class BetaRawMessageStartEventTest { ) .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(BetaStopReason.END_TURN) .stopSequence(null) .usage( diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaRawMessageStreamEventTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaRawMessageStreamEventTest.kt index b9e19d00f..4c2905b0a 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaRawMessageStreamEventTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaRawMessageStreamEventTest.kt @@ -61,7 +61,7 @@ internal class BetaRawMessageStreamEventTest { ) .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(BetaStopReason.END_TURN) .stopSequence(null) .usage( @@ -146,7 +146,7 @@ internal class BetaRawMessageStreamEventTest { ) .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(BetaStopReason.END_TURN) .stopSequence(null) .usage( diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaServerToolCallerTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaServerToolCallerTest.kt new file mode 100644 index 000000000..1d17a7dfe --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaServerToolCallerTest.kt @@ -0,0 +1,34 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 BetaServerToolCallerTest { + + @Test + fun create() { + val betaServerToolCaller = + BetaServerToolCaller.builder().toolId("srvtoolu_SQfNkl1n_JR_").build() + + assertThat(betaServerToolCaller.toolId()).isEqualTo("srvtoolu_SQfNkl1n_JR_") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaServerToolCaller = + BetaServerToolCaller.builder().toolId("srvtoolu_SQfNkl1n_JR_").build() + + val roundtrippedBetaServerToolCaller = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaServerToolCaller), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaServerToolCaller).isEqualTo(betaServerToolCaller) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaServerToolUseBlockParamTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaServerToolUseBlockParamTest.kt index 9d5ca2b88..cf60ef42c 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaServerToolUseBlockParamTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaServerToolUseBlockParamTest.kt @@ -26,6 +26,7 @@ internal class BetaServerToolUseBlockParamTest { .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .caller(BetaDirectCaller.builder().build()) .build() assertThat(betaServerToolUseBlockParam.id()).isEqualTo("srvtoolu_SQfNkl1n_JR_") @@ -43,6 +44,10 @@ internal class BetaServerToolUseBlockParamTest { .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + assertThat(betaServerToolUseBlockParam.caller()) + .contains( + BetaServerToolUseBlockParam.Caller.ofDirect(BetaDirectCaller.builder().build()) + ) } @Test @@ -62,6 +67,7 @@ internal class BetaServerToolUseBlockParamTest { .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .caller(BetaDirectCaller.builder().build()) .build() val roundtrippedBetaServerToolUseBlockParam = diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaServerToolUseBlockTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaServerToolUseBlockTest.kt index 22eb25793..537abf768 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaServerToolUseBlockTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaServerToolUseBlockTest.kt @@ -15,11 +15,14 @@ internal class BetaServerToolUseBlockTest { val betaServerToolUseBlock = BetaServerToolUseBlock.builder() .id("srvtoolu_SQfNkl1n_JR_") + .caller(BetaDirectCaller.builder().build()) .input(JsonValue.from(mapOf())) .name(BetaServerToolUseBlock.Name.WEB_SEARCH) .build() assertThat(betaServerToolUseBlock.id()).isEqualTo("srvtoolu_SQfNkl1n_JR_") + assertThat(betaServerToolUseBlock.caller()) + .isEqualTo(BetaServerToolUseBlock.Caller.ofDirect(BetaDirectCaller.builder().build())) assertThat(betaServerToolUseBlock._input()).isEqualTo(JsonValue.from(mapOf())) assertThat(betaServerToolUseBlock.name()).isEqualTo(BetaServerToolUseBlock.Name.WEB_SEARCH) } @@ -30,6 +33,7 @@ internal class BetaServerToolUseBlockTest { val betaServerToolUseBlock = BetaServerToolUseBlock.builder() .id("srvtoolu_SQfNkl1n_JR_") + .caller(BetaDirectCaller.builder().build()) .input(JsonValue.from(mapOf())) .name(BetaServerToolUseBlock.Name.WEB_SEARCH) .build() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolBash20241022Test.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolBash20241022Test.kt index 917984cc3..de387561b 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolBash20241022Test.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolBash20241022Test.kt @@ -2,8 +2,10 @@ package com.anthropic.models.beta.messages +import com.anthropic.core.JsonValue import com.anthropic.core.jsonMapper import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -13,20 +15,36 @@ internal class BetaToolBash20241022Test { fun create() { val betaToolBash20241022 = BetaToolBash20241022.builder() + .addAllowedCaller(BetaToolBash20241022.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaToolBash20241022.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() + assertThat(betaToolBash20241022.allowedCallers().getOrNull()) + .containsExactly(BetaToolBash20241022.AllowedCaller.DIRECT) assertThat(betaToolBash20241022.cacheControl()) .contains( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + assertThat(betaToolBash20241022.deferLoading()).contains(true) + assertThat(betaToolBash20241022.inputExamples().getOrNull()) + .containsExactly( + BetaToolBash20241022.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) assertThat(betaToolBash20241022.strict()).contains(true) } @@ -35,11 +53,18 @@ internal class BetaToolBash20241022Test { val jsonMapper = jsonMapper() val betaToolBash20241022 = BetaToolBash20241022.builder() + .addAllowedCaller(BetaToolBash20241022.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaToolBash20241022.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolBash20250124Test.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolBash20250124Test.kt index 89fc8012d..6a33a9e56 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolBash20250124Test.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolBash20250124Test.kt @@ -2,8 +2,10 @@ package com.anthropic.models.beta.messages +import com.anthropic.core.JsonValue import com.anthropic.core.jsonMapper import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -13,20 +15,36 @@ internal class BetaToolBash20250124Test { fun create() { val betaToolBash20250124 = BetaToolBash20250124.builder() + .addAllowedCaller(BetaToolBash20250124.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaToolBash20250124.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() + assertThat(betaToolBash20250124.allowedCallers().getOrNull()) + .containsExactly(BetaToolBash20250124.AllowedCaller.DIRECT) assertThat(betaToolBash20250124.cacheControl()) .contains( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + assertThat(betaToolBash20250124.deferLoading()).contains(true) + assertThat(betaToolBash20250124.inputExamples().getOrNull()) + .containsExactly( + BetaToolBash20250124.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) assertThat(betaToolBash20250124.strict()).contains(true) } @@ -35,11 +53,18 @@ internal class BetaToolBash20250124Test { val jsonMapper = jsonMapper() val betaToolBash20250124 = BetaToolBash20250124.builder() + .addAllowedCaller(BetaToolBash20250124.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaToolBash20250124.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolComputerUse20241022Test.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolComputerUse20241022Test.kt index 77eac9e7c..f194dc0e8 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolComputerUse20241022Test.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolComputerUse20241022Test.kt @@ -2,8 +2,10 @@ package com.anthropic.models.beta.messages +import com.anthropic.core.JsonValue import com.anthropic.core.jsonMapper import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -15,24 +17,40 @@ internal class BetaToolComputerUse20241022Test { BetaToolComputerUse20241022.builder() .displayHeightPx(1L) .displayWidthPx(1L) + .addAllowedCaller(BetaToolComputerUse20241022.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .displayNumber(0L) + .addInputExample( + BetaToolComputerUse20241022.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() assertThat(betaToolComputerUse20241022.displayHeightPx()).isEqualTo(1L) assertThat(betaToolComputerUse20241022.displayWidthPx()).isEqualTo(1L) + assertThat(betaToolComputerUse20241022.allowedCallers().getOrNull()) + .containsExactly(BetaToolComputerUse20241022.AllowedCaller.DIRECT) assertThat(betaToolComputerUse20241022.cacheControl()) .contains( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + assertThat(betaToolComputerUse20241022.deferLoading()).contains(true) assertThat(betaToolComputerUse20241022.displayNumber()).contains(0L) + assertThat(betaToolComputerUse20241022.inputExamples().getOrNull()) + .containsExactly( + BetaToolComputerUse20241022.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) assertThat(betaToolComputerUse20241022.strict()).contains(true) } @@ -43,12 +61,19 @@ internal class BetaToolComputerUse20241022Test { BetaToolComputerUse20241022.builder() .displayHeightPx(1L) .displayWidthPx(1L) + .addAllowedCaller(BetaToolComputerUse20241022.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .displayNumber(0L) + .addInputExample( + BetaToolComputerUse20241022.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolComputerUse20250124Test.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolComputerUse20250124Test.kt index 317876230..163a063b9 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolComputerUse20250124Test.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolComputerUse20250124Test.kt @@ -2,8 +2,10 @@ package com.anthropic.models.beta.messages +import com.anthropic.core.JsonValue import com.anthropic.core.jsonMapper import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -15,24 +17,40 @@ internal class BetaToolComputerUse20250124Test { BetaToolComputerUse20250124.builder() .displayHeightPx(1L) .displayWidthPx(1L) + .addAllowedCaller(BetaToolComputerUse20250124.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .displayNumber(0L) + .addInputExample( + BetaToolComputerUse20250124.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() assertThat(betaToolComputerUse20250124.displayHeightPx()).isEqualTo(1L) assertThat(betaToolComputerUse20250124.displayWidthPx()).isEqualTo(1L) + assertThat(betaToolComputerUse20250124.allowedCallers().getOrNull()) + .containsExactly(BetaToolComputerUse20250124.AllowedCaller.DIRECT) assertThat(betaToolComputerUse20250124.cacheControl()) .contains( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + assertThat(betaToolComputerUse20250124.deferLoading()).contains(true) assertThat(betaToolComputerUse20250124.displayNumber()).contains(0L) + assertThat(betaToolComputerUse20250124.inputExamples().getOrNull()) + .containsExactly( + BetaToolComputerUse20250124.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) assertThat(betaToolComputerUse20250124.strict()).contains(true) } @@ -43,12 +61,19 @@ internal class BetaToolComputerUse20250124Test { BetaToolComputerUse20250124.builder() .displayHeightPx(1L) .displayWidthPx(1L) + .addAllowedCaller(BetaToolComputerUse20250124.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .displayNumber(0L) + .addInputExample( + BetaToolComputerUse20250124.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolComputerUse20251124Test.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolComputerUse20251124Test.kt new file mode 100644 index 000000000..f4a54fdfc --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolComputerUse20251124Test.kt @@ -0,0 +1,91 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +import com.anthropic.core.JsonValue +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import kotlin.jvm.optionals.getOrNull +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaToolComputerUse20251124Test { + + @Test + fun create() { + val betaToolComputerUse20251124 = + BetaToolComputerUse20251124.builder() + .displayHeightPx(1L) + .displayWidthPx(1L) + .addAllowedCaller(BetaToolComputerUse20251124.AllowedCaller.DIRECT) + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .deferLoading(true) + .displayNumber(0L) + .enableZoom(true) + .addInputExample( + BetaToolComputerUse20251124.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .strict(true) + .build() + + assertThat(betaToolComputerUse20251124.displayHeightPx()).isEqualTo(1L) + assertThat(betaToolComputerUse20251124.displayWidthPx()).isEqualTo(1L) + assertThat(betaToolComputerUse20251124.allowedCallers().getOrNull()) + .containsExactly(BetaToolComputerUse20251124.AllowedCaller.DIRECT) + assertThat(betaToolComputerUse20251124.cacheControl()) + .contains( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + assertThat(betaToolComputerUse20251124.deferLoading()).contains(true) + assertThat(betaToolComputerUse20251124.displayNumber()).contains(0L) + assertThat(betaToolComputerUse20251124.enableZoom()).contains(true) + assertThat(betaToolComputerUse20251124.inputExamples().getOrNull()) + .containsExactly( + BetaToolComputerUse20251124.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + assertThat(betaToolComputerUse20251124.strict()).contains(true) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaToolComputerUse20251124 = + BetaToolComputerUse20251124.builder() + .displayHeightPx(1L) + .displayWidthPx(1L) + .addAllowedCaller(BetaToolComputerUse20251124.AllowedCaller.DIRECT) + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .deferLoading(true) + .displayNumber(0L) + .enableZoom(true) + .addInputExample( + BetaToolComputerUse20251124.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .strict(true) + .build() + + val roundtrippedBetaToolComputerUse20251124 = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaToolComputerUse20251124), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaToolComputerUse20251124).isEqualTo(betaToolComputerUse20251124) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolReferenceBlockParamTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolReferenceBlockParamTest.kt new file mode 100644 index 000000000..0332d422c --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolReferenceBlockParamTest.kt @@ -0,0 +1,54 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 BetaToolReferenceBlockParamTest { + + @Test + fun create() { + val betaToolReferenceBlockParam = + BetaToolReferenceBlockParam.builder() + .toolName("tool_name") + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .build() + + assertThat(betaToolReferenceBlockParam.toolName()).isEqualTo("tool_name") + assertThat(betaToolReferenceBlockParam.cacheControl()) + .contains( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaToolReferenceBlockParam = + BetaToolReferenceBlockParam.builder() + .toolName("tool_name") + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .build() + + val roundtrippedBetaToolReferenceBlockParam = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaToolReferenceBlockParam), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaToolReferenceBlockParam).isEqualTo(betaToolReferenceBlockParam) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolReferenceBlockTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolReferenceBlockTest.kt new file mode 100644 index 000000000..8cbba0a0e --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolReferenceBlockTest.kt @@ -0,0 +1,32 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 BetaToolReferenceBlockTest { + + @Test + fun create() { + val betaToolReferenceBlock = BetaToolReferenceBlock.builder().toolName("tool_name").build() + + assertThat(betaToolReferenceBlock.toolName()).isEqualTo("tool_name") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaToolReferenceBlock = BetaToolReferenceBlock.builder().toolName("tool_name").build() + + val roundtrippedBetaToolReferenceBlock = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaToolReferenceBlock), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaToolReferenceBlock).isEqualTo(betaToolReferenceBlock) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolBm25_20251119Test.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolBm25_20251119Test.kt new file mode 100644 index 000000000..703a334a5 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolBm25_20251119Test.kt @@ -0,0 +1,67 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import kotlin.jvm.optionals.getOrNull +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaToolSearchToolBm25_20251119Test { + + @Test + fun create() { + val betaToolSearchToolBm25_20251119 = + BetaToolSearchToolBm25_20251119.builder() + .type(BetaToolSearchToolBm25_20251119.Type.TOOL_SEARCH_TOOL_BM25_20251119) + .addAllowedCaller(BetaToolSearchToolBm25_20251119.AllowedCaller.DIRECT) + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .deferLoading(true) + .strict(true) + .build() + + assertThat(betaToolSearchToolBm25_20251119.type()) + .isEqualTo(BetaToolSearchToolBm25_20251119.Type.TOOL_SEARCH_TOOL_BM25_20251119) + assertThat(betaToolSearchToolBm25_20251119.allowedCallers().getOrNull()) + .containsExactly(BetaToolSearchToolBm25_20251119.AllowedCaller.DIRECT) + assertThat(betaToolSearchToolBm25_20251119.cacheControl()) + .contains( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + assertThat(betaToolSearchToolBm25_20251119.deferLoading()).contains(true) + assertThat(betaToolSearchToolBm25_20251119.strict()).contains(true) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaToolSearchToolBm25_20251119 = + BetaToolSearchToolBm25_20251119.builder() + .type(BetaToolSearchToolBm25_20251119.Type.TOOL_SEARCH_TOOL_BM25_20251119) + .addAllowedCaller(BetaToolSearchToolBm25_20251119.AllowedCaller.DIRECT) + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .deferLoading(true) + .strict(true) + .build() + + val roundtrippedBetaToolSearchToolBm25_20251119 = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaToolSearchToolBm25_20251119), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaToolSearchToolBm25_20251119) + .isEqualTo(betaToolSearchToolBm25_20251119) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolRegex20251119Test.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolRegex20251119Test.kt new file mode 100644 index 000000000..0d7336509 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolRegex20251119Test.kt @@ -0,0 +1,67 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +import com.anthropic.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import kotlin.jvm.optionals.getOrNull +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BetaToolSearchToolRegex20251119Test { + + @Test + fun create() { + val betaToolSearchToolRegex20251119 = + BetaToolSearchToolRegex20251119.builder() + .type(BetaToolSearchToolRegex20251119.Type.TOOL_SEARCH_TOOL_REGEX_20251119) + .addAllowedCaller(BetaToolSearchToolRegex20251119.AllowedCaller.DIRECT) + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .deferLoading(true) + .strict(true) + .build() + + assertThat(betaToolSearchToolRegex20251119.type()) + .isEqualTo(BetaToolSearchToolRegex20251119.Type.TOOL_SEARCH_TOOL_REGEX_20251119) + assertThat(betaToolSearchToolRegex20251119.allowedCallers().getOrNull()) + .containsExactly(BetaToolSearchToolRegex20251119.AllowedCaller.DIRECT) + assertThat(betaToolSearchToolRegex20251119.cacheControl()) + .contains( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + assertThat(betaToolSearchToolRegex20251119.deferLoading()).contains(true) + assertThat(betaToolSearchToolRegex20251119.strict()).contains(true) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaToolSearchToolRegex20251119 = + BetaToolSearchToolRegex20251119.builder() + .type(BetaToolSearchToolRegex20251119.Type.TOOL_SEARCH_TOOL_REGEX_20251119) + .addAllowedCaller(BetaToolSearchToolRegex20251119.AllowedCaller.DIRECT) + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .deferLoading(true) + .strict(true) + .build() + + val roundtrippedBetaToolSearchToolRegex20251119 = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaToolSearchToolRegex20251119), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaToolSearchToolRegex20251119) + .isEqualTo(betaToolSearchToolRegex20251119) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolResultBlockParamTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolResultBlockParamTest.kt new file mode 100644 index 000000000..8853c6c8c --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolResultBlockParamTest.kt @@ -0,0 +1,74 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 BetaToolSearchToolResultBlockParamTest { + + @Test + fun create() { + val betaToolSearchToolResultBlockParam = + BetaToolSearchToolResultBlockParam.builder() + .content( + BetaToolSearchToolResultErrorParam.builder() + .errorCode(BetaToolSearchToolResultErrorParam.ErrorCode.INVALID_TOOL_INPUT) + .build() + ) + .toolUseId("srvtoolu_SQfNkl1n_JR_") + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .build() + + assertThat(betaToolSearchToolResultBlockParam.content()) + .isEqualTo( + BetaToolSearchToolResultBlockParam.Content.ofBetaToolSearchToolResultErrorParam( + BetaToolSearchToolResultErrorParam.builder() + .errorCode(BetaToolSearchToolResultErrorParam.ErrorCode.INVALID_TOOL_INPUT) + .build() + ) + ) + assertThat(betaToolSearchToolResultBlockParam.toolUseId()) + .isEqualTo("srvtoolu_SQfNkl1n_JR_") + assertThat(betaToolSearchToolResultBlockParam.cacheControl()) + .contains( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaToolSearchToolResultBlockParam = + BetaToolSearchToolResultBlockParam.builder() + .content( + BetaToolSearchToolResultErrorParam.builder() + .errorCode(BetaToolSearchToolResultErrorParam.ErrorCode.INVALID_TOOL_INPUT) + .build() + ) + .toolUseId("srvtoolu_SQfNkl1n_JR_") + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .build() + + val roundtrippedBetaToolSearchToolResultBlockParam = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaToolSearchToolResultBlockParam), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaToolSearchToolResultBlockParam) + .isEqualTo(betaToolSearchToolResultBlockParam) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolResultBlockTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolResultBlockTest.kt new file mode 100644 index 000000000..0e4fe7517 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolResultBlockTest.kt @@ -0,0 +1,60 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 BetaToolSearchToolResultBlockTest { + + @Test + fun create() { + val betaToolSearchToolResultBlock = + BetaToolSearchToolResultBlock.builder() + .content( + BetaToolSearchToolResultError.builder() + .errorCode(BetaToolSearchToolResultError.ErrorCode.INVALID_TOOL_INPUT) + .errorMessage("error_message") + .build() + ) + .toolUseId("srvtoolu_SQfNkl1n_JR_") + .build() + + assertThat(betaToolSearchToolResultBlock.content()) + .isEqualTo( + BetaToolSearchToolResultBlock.Content.ofBetaToolSearchToolResultError( + BetaToolSearchToolResultError.builder() + .errorCode(BetaToolSearchToolResultError.ErrorCode.INVALID_TOOL_INPUT) + .errorMessage("error_message") + .build() + ) + ) + assertThat(betaToolSearchToolResultBlock.toolUseId()).isEqualTo("srvtoolu_SQfNkl1n_JR_") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaToolSearchToolResultBlock = + BetaToolSearchToolResultBlock.builder() + .content( + BetaToolSearchToolResultError.builder() + .errorCode(BetaToolSearchToolResultError.ErrorCode.INVALID_TOOL_INPUT) + .errorMessage("error_message") + .build() + ) + .toolUseId("srvtoolu_SQfNkl1n_JR_") + .build() + + val roundtrippedBetaToolSearchToolResultBlock = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaToolSearchToolResultBlock), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaToolSearchToolResultBlock) + .isEqualTo(betaToolSearchToolResultBlock) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolResultErrorParamTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolResultErrorParamTest.kt new file mode 100644 index 000000000..401a9c0d9 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolResultErrorParamTest.kt @@ -0,0 +1,40 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 BetaToolSearchToolResultErrorParamTest { + + @Test + fun create() { + val betaToolSearchToolResultErrorParam = + BetaToolSearchToolResultErrorParam.builder() + .errorCode(BetaToolSearchToolResultErrorParam.ErrorCode.INVALID_TOOL_INPUT) + .build() + + assertThat(betaToolSearchToolResultErrorParam.errorCode()) + .isEqualTo(BetaToolSearchToolResultErrorParam.ErrorCode.INVALID_TOOL_INPUT) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaToolSearchToolResultErrorParam = + BetaToolSearchToolResultErrorParam.builder() + .errorCode(BetaToolSearchToolResultErrorParam.ErrorCode.INVALID_TOOL_INPUT) + .build() + + val roundtrippedBetaToolSearchToolResultErrorParam = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaToolSearchToolResultErrorParam), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaToolSearchToolResultErrorParam) + .isEqualTo(betaToolSearchToolResultErrorParam) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolResultErrorTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolResultErrorTest.kt new file mode 100644 index 000000000..261cd7f58 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolResultErrorTest.kt @@ -0,0 +1,43 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 BetaToolSearchToolResultErrorTest { + + @Test + fun create() { + val betaToolSearchToolResultError = + BetaToolSearchToolResultError.builder() + .errorCode(BetaToolSearchToolResultError.ErrorCode.INVALID_TOOL_INPUT) + .errorMessage("error_message") + .build() + + assertThat(betaToolSearchToolResultError.errorCode()) + .isEqualTo(BetaToolSearchToolResultError.ErrorCode.INVALID_TOOL_INPUT) + assertThat(betaToolSearchToolResultError.errorMessage()).contains("error_message") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaToolSearchToolResultError = + BetaToolSearchToolResultError.builder() + .errorCode(BetaToolSearchToolResultError.ErrorCode.INVALID_TOOL_INPUT) + .errorMessage("error_message") + .build() + + val roundtrippedBetaToolSearchToolResultError = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaToolSearchToolResultError), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaToolSearchToolResultError) + .isEqualTo(betaToolSearchToolResultError) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolSearchResultBlockParamTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolSearchResultBlockParamTest.kt new file mode 100644 index 000000000..eeb3a2fd2 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolSearchResultBlockParamTest.kt @@ -0,0 +1,67 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 BetaToolSearchToolSearchResultBlockParamTest { + + @Test + fun create() { + val betaToolSearchToolSearchResultBlockParam = + BetaToolSearchToolSearchResultBlockParam.builder() + .addToolReference( + BetaToolReferenceBlockParam.builder() + .toolName("tool_name") + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .build() + ) + .build() + + assertThat(betaToolSearchToolSearchResultBlockParam.toolReferences()) + .containsExactly( + BetaToolReferenceBlockParam.builder() + .toolName("tool_name") + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaToolSearchToolSearchResultBlockParam = + BetaToolSearchToolSearchResultBlockParam.builder() + .addToolReference( + BetaToolReferenceBlockParam.builder() + .toolName("tool_name") + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .build() + ) + .build() + + val roundtrippedBetaToolSearchToolSearchResultBlockParam = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaToolSearchToolSearchResultBlockParam), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaToolSearchToolSearchResultBlockParam) + .isEqualTo(betaToolSearchToolSearchResultBlockParam) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolSearchResultBlockTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolSearchResultBlockTest.kt new file mode 100644 index 000000000..2554f2da7 --- /dev/null +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolSearchToolSearchResultBlockTest.kt @@ -0,0 +1,40 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.anthropic.models.beta.messages + +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 BetaToolSearchToolSearchResultBlockTest { + + @Test + fun create() { + val betaToolSearchToolSearchResultBlock = + BetaToolSearchToolSearchResultBlock.builder() + .addToolReference(BetaToolReferenceBlock.builder().toolName("tool_name").build()) + .build() + + assertThat(betaToolSearchToolSearchResultBlock.toolReferences()) + .containsExactly(BetaToolReferenceBlock.builder().toolName("tool_name").build()) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val betaToolSearchToolSearchResultBlock = + BetaToolSearchToolSearchResultBlock.builder() + .addToolReference(BetaToolReferenceBlock.builder().toolName("tool_name").build()) + .build() + + val roundtrippedBetaToolSearchToolSearchResultBlock = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaToolSearchToolSearchResultBlock), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaToolSearchToolSearchResultBlock) + .isEqualTo(betaToolSearchToolSearchResultBlock) + } +} diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolTest.kt index bb53d3466..5a4952b7b 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolTest.kt @@ -5,6 +5,7 @@ package com.anthropic.models.beta.messages import com.anthropic.core.JsonValue import com.anthropic.core.jsonMapper import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -26,12 +27,19 @@ internal class BetaToolTest { .build() ) .name("name") + .addAllowedCaller(BetaTool.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .description("Get the current weather in a given location") + .addInputExample( + BetaTool.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .type(BetaTool.Type.CUSTOM) .build() @@ -49,13 +57,22 @@ internal class BetaToolTest { .build() ) assertThat(betaTool.name()).isEqualTo("name") + assertThat(betaTool.allowedCallers().getOrNull()) + .containsExactly(BetaTool.AllowedCaller.DIRECT) assertThat(betaTool.cacheControl()) .contains( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + assertThat(betaTool.deferLoading()).contains(true) assertThat(betaTool.description()).contains("Get the current weather in a given location") + assertThat(betaTool.inputExamples().getOrNull()) + .containsExactly( + BetaTool.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) assertThat(betaTool.strict()).contains(true) assertThat(betaTool.type()).contains(BetaTool.Type.CUSTOM) } @@ -77,12 +94,19 @@ internal class BetaToolTest { .build() ) .name("name") + .addAllowedCaller(BetaTool.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .description("Get the current weather in a given location") + .addInputExample( + BetaTool.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .type(BetaTool.Type.CUSTOM) .build() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20241022Test.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20241022Test.kt index ebbe90558..33a10cdd1 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20241022Test.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20241022Test.kt @@ -2,8 +2,10 @@ package com.anthropic.models.beta.messages +import com.anthropic.core.JsonValue import com.anthropic.core.jsonMapper import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -13,20 +15,36 @@ internal class BetaToolTextEditor20241022Test { fun create() { val betaToolTextEditor20241022 = BetaToolTextEditor20241022.builder() + .addAllowedCaller(BetaToolTextEditor20241022.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaToolTextEditor20241022.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() + assertThat(betaToolTextEditor20241022.allowedCallers().getOrNull()) + .containsExactly(BetaToolTextEditor20241022.AllowedCaller.DIRECT) assertThat(betaToolTextEditor20241022.cacheControl()) .contains( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + assertThat(betaToolTextEditor20241022.deferLoading()).contains(true) + assertThat(betaToolTextEditor20241022.inputExamples().getOrNull()) + .containsExactly( + BetaToolTextEditor20241022.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) assertThat(betaToolTextEditor20241022.strict()).contains(true) } @@ -35,11 +53,18 @@ internal class BetaToolTextEditor20241022Test { val jsonMapper = jsonMapper() val betaToolTextEditor20241022 = BetaToolTextEditor20241022.builder() + .addAllowedCaller(BetaToolTextEditor20241022.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaToolTextEditor20241022.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20250124Test.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20250124Test.kt index 663647105..35c34bf4d 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20250124Test.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20250124Test.kt @@ -2,8 +2,10 @@ package com.anthropic.models.beta.messages +import com.anthropic.core.JsonValue import com.anthropic.core.jsonMapper import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -13,20 +15,36 @@ internal class BetaToolTextEditor20250124Test { fun create() { val betaToolTextEditor20250124 = BetaToolTextEditor20250124.builder() + .addAllowedCaller(BetaToolTextEditor20250124.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaToolTextEditor20250124.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() + assertThat(betaToolTextEditor20250124.allowedCallers().getOrNull()) + .containsExactly(BetaToolTextEditor20250124.AllowedCaller.DIRECT) assertThat(betaToolTextEditor20250124.cacheControl()) .contains( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + assertThat(betaToolTextEditor20250124.deferLoading()).contains(true) + assertThat(betaToolTextEditor20250124.inputExamples().getOrNull()) + .containsExactly( + BetaToolTextEditor20250124.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) assertThat(betaToolTextEditor20250124.strict()).contains(true) } @@ -35,11 +53,18 @@ internal class BetaToolTextEditor20250124Test { val jsonMapper = jsonMapper() val betaToolTextEditor20250124 = BetaToolTextEditor20250124.builder() + .addAllowedCaller(BetaToolTextEditor20250124.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaToolTextEditor20250124.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20250429Test.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20250429Test.kt index d77a52cbc..4539ce6f8 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20250429Test.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20250429Test.kt @@ -2,8 +2,10 @@ package com.anthropic.models.beta.messages +import com.anthropic.core.JsonValue import com.anthropic.core.jsonMapper import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -13,20 +15,36 @@ internal class BetaToolTextEditor20250429Test { fun create() { val betaToolTextEditor20250429 = BetaToolTextEditor20250429.builder() + .addAllowedCaller(BetaToolTextEditor20250429.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaToolTextEditor20250429.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() + assertThat(betaToolTextEditor20250429.allowedCallers().getOrNull()) + .containsExactly(BetaToolTextEditor20250429.AllowedCaller.DIRECT) assertThat(betaToolTextEditor20250429.cacheControl()) .contains( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + assertThat(betaToolTextEditor20250429.deferLoading()).contains(true) + assertThat(betaToolTextEditor20250429.inputExamples().getOrNull()) + .containsExactly( + BetaToolTextEditor20250429.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) assertThat(betaToolTextEditor20250429.strict()).contains(true) } @@ -35,11 +53,18 @@ internal class BetaToolTextEditor20250429Test { val jsonMapper = jsonMapper() val betaToolTextEditor20250429 = BetaToolTextEditor20250429.builder() + .addAllowedCaller(BetaToolTextEditor20250429.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaToolTextEditor20250429.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20250728Test.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20250728Test.kt index 718863fd6..c6ab185e3 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20250728Test.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolTextEditor20250728Test.kt @@ -2,8 +2,10 @@ package com.anthropic.models.beta.messages +import com.anthropic.core.JsonValue import com.anthropic.core.jsonMapper import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -13,21 +15,37 @@ internal class BetaToolTextEditor20250728Test { fun create() { val betaToolTextEditor20250728 = BetaToolTextEditor20250728.builder() + .addAllowedCaller(BetaToolTextEditor20250728.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaToolTextEditor20250728.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .maxCharacters(1L) .strict(true) .build() + assertThat(betaToolTextEditor20250728.allowedCallers().getOrNull()) + .containsExactly(BetaToolTextEditor20250728.AllowedCaller.DIRECT) assertThat(betaToolTextEditor20250728.cacheControl()) .contains( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + assertThat(betaToolTextEditor20250728.deferLoading()).contains(true) + assertThat(betaToolTextEditor20250728.inputExamples().getOrNull()) + .containsExactly( + BetaToolTextEditor20250728.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) assertThat(betaToolTextEditor20250728.maxCharacters()).contains(1L) assertThat(betaToolTextEditor20250728.strict()).contains(true) } @@ -37,11 +55,18 @@ internal class BetaToolTextEditor20250728Test { val jsonMapper = jsonMapper() val betaToolTextEditor20250728 = BetaToolTextEditor20250728.builder() + .addAllowedCaller(BetaToolTextEditor20250728.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaToolTextEditor20250728.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .maxCharacters(1L) .strict(true) .build() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolUnionTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolUnionTest.kt index 862f30d26..d23ee42c7 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolUnionTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolUnionTest.kt @@ -30,12 +30,19 @@ internal class BetaToolUnionTest { .build() ) .name("name") + .addAllowedCaller(BetaTool.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .description("Get the current weather in a given location") + .addInputExample( + BetaTool.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .type(BetaTool.Type.CUSTOM) .build() @@ -51,11 +58,15 @@ internal class BetaToolUnionTest { assertThat(betaToolUnion.memoryTool20250818()).isEmpty assertThat(betaToolUnion.computerUse20250124()).isEmpty assertThat(betaToolUnion.textEditor20241022()).isEmpty + assertThat(betaToolUnion.computerUse20251124()).isEmpty assertThat(betaToolUnion.textEditor20250124()).isEmpty assertThat(betaToolUnion.textEditor20250429()).isEmpty assertThat(betaToolUnion.textEditor20250728()).isEmpty assertThat(betaToolUnion.webSearchTool20250305()).isEmpty assertThat(betaToolUnion.webFetchTool20250910()).isEmpty + assertThat(betaToolUnion.searchToolBm25_20251119()).isEmpty + assertThat(betaToolUnion.searchToolRegex20251119()).isEmpty + assertThat(betaToolUnion.mcpToolset()).isEmpty } @Test @@ -76,12 +87,19 @@ internal class BetaToolUnionTest { .build() ) .name("name") + .addAllowedCaller(BetaTool.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .description("Get the current weather in a given location") + .addInputExample( + BetaTool.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .type(BetaTool.Type.CUSTOM) .build() @@ -100,11 +118,18 @@ internal class BetaToolUnionTest { fun ofBash20241022() { val bash20241022 = BetaToolBash20241022.builder() + .addAllowedCaller(BetaToolBash20241022.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaToolBash20241022.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() @@ -119,11 +144,15 @@ internal class BetaToolUnionTest { assertThat(betaToolUnion.memoryTool20250818()).isEmpty assertThat(betaToolUnion.computerUse20250124()).isEmpty assertThat(betaToolUnion.textEditor20241022()).isEmpty + assertThat(betaToolUnion.computerUse20251124()).isEmpty assertThat(betaToolUnion.textEditor20250124()).isEmpty assertThat(betaToolUnion.textEditor20250429()).isEmpty assertThat(betaToolUnion.textEditor20250728()).isEmpty assertThat(betaToolUnion.webSearchTool20250305()).isEmpty assertThat(betaToolUnion.webFetchTool20250910()).isEmpty + assertThat(betaToolUnion.searchToolBm25_20251119()).isEmpty + assertThat(betaToolUnion.searchToolRegex20251119()).isEmpty + assertThat(betaToolUnion.mcpToolset()).isEmpty } @Test @@ -132,11 +161,18 @@ internal class BetaToolUnionTest { val betaToolUnion = BetaToolUnion.ofBash20241022( BetaToolBash20241022.builder() + .addAllowedCaller(BetaToolBash20241022.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaToolBash20241022.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() ) @@ -154,11 +190,18 @@ internal class BetaToolUnionTest { fun ofBash20250124() { val bash20250124 = BetaToolBash20250124.builder() + .addAllowedCaller(BetaToolBash20250124.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaToolBash20250124.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() @@ -173,11 +216,15 @@ internal class BetaToolUnionTest { assertThat(betaToolUnion.memoryTool20250818()).isEmpty assertThat(betaToolUnion.computerUse20250124()).isEmpty assertThat(betaToolUnion.textEditor20241022()).isEmpty + assertThat(betaToolUnion.computerUse20251124()).isEmpty assertThat(betaToolUnion.textEditor20250124()).isEmpty assertThat(betaToolUnion.textEditor20250429()).isEmpty assertThat(betaToolUnion.textEditor20250728()).isEmpty assertThat(betaToolUnion.webSearchTool20250305()).isEmpty assertThat(betaToolUnion.webFetchTool20250910()).isEmpty + assertThat(betaToolUnion.searchToolBm25_20251119()).isEmpty + assertThat(betaToolUnion.searchToolRegex20251119()).isEmpty + assertThat(betaToolUnion.mcpToolset()).isEmpty } @Test @@ -186,11 +233,18 @@ internal class BetaToolUnionTest { val betaToolUnion = BetaToolUnion.ofBash20250124( BetaToolBash20250124.builder() + .addAllowedCaller(BetaToolBash20250124.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaToolBash20250124.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() ) @@ -208,11 +262,13 @@ internal class BetaToolUnionTest { fun ofCodeExecutionTool20250522() { val codeExecutionTool20250522 = BetaCodeExecutionTool20250522.builder() + .addAllowedCaller(BetaCodeExecutionTool20250522.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .strict(true) .build() @@ -227,11 +283,15 @@ internal class BetaToolUnionTest { assertThat(betaToolUnion.memoryTool20250818()).isEmpty assertThat(betaToolUnion.computerUse20250124()).isEmpty assertThat(betaToolUnion.textEditor20241022()).isEmpty + assertThat(betaToolUnion.computerUse20251124()).isEmpty assertThat(betaToolUnion.textEditor20250124()).isEmpty assertThat(betaToolUnion.textEditor20250429()).isEmpty assertThat(betaToolUnion.textEditor20250728()).isEmpty assertThat(betaToolUnion.webSearchTool20250305()).isEmpty assertThat(betaToolUnion.webFetchTool20250910()).isEmpty + assertThat(betaToolUnion.searchToolBm25_20251119()).isEmpty + assertThat(betaToolUnion.searchToolRegex20251119()).isEmpty + assertThat(betaToolUnion.mcpToolset()).isEmpty } @Test @@ -240,11 +300,13 @@ internal class BetaToolUnionTest { val betaToolUnion = BetaToolUnion.ofCodeExecutionTool20250522( BetaCodeExecutionTool20250522.builder() + .addAllowedCaller(BetaCodeExecutionTool20250522.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .strict(true) .build() ) @@ -262,11 +324,13 @@ internal class BetaToolUnionTest { fun ofCodeExecutionTool20250825() { val codeExecutionTool20250825 = BetaCodeExecutionTool20250825.builder() + .addAllowedCaller(BetaCodeExecutionTool20250825.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .strict(true) .build() @@ -281,11 +345,15 @@ internal class BetaToolUnionTest { assertThat(betaToolUnion.memoryTool20250818()).isEmpty assertThat(betaToolUnion.computerUse20250124()).isEmpty assertThat(betaToolUnion.textEditor20241022()).isEmpty + assertThat(betaToolUnion.computerUse20251124()).isEmpty assertThat(betaToolUnion.textEditor20250124()).isEmpty assertThat(betaToolUnion.textEditor20250429()).isEmpty assertThat(betaToolUnion.textEditor20250728()).isEmpty assertThat(betaToolUnion.webSearchTool20250305()).isEmpty assertThat(betaToolUnion.webFetchTool20250910()).isEmpty + assertThat(betaToolUnion.searchToolBm25_20251119()).isEmpty + assertThat(betaToolUnion.searchToolRegex20251119()).isEmpty + assertThat(betaToolUnion.mcpToolset()).isEmpty } @Test @@ -294,11 +362,13 @@ internal class BetaToolUnionTest { val betaToolUnion = BetaToolUnion.ofCodeExecutionTool20250825( BetaCodeExecutionTool20250825.builder() + .addAllowedCaller(BetaCodeExecutionTool20250825.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .strict(true) .build() ) @@ -318,12 +388,19 @@ internal class BetaToolUnionTest { BetaToolComputerUse20241022.builder() .displayHeightPx(1L) .displayWidthPx(1L) + .addAllowedCaller(BetaToolComputerUse20241022.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .displayNumber(0L) + .addInputExample( + BetaToolComputerUse20241022.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() @@ -338,11 +415,15 @@ internal class BetaToolUnionTest { assertThat(betaToolUnion.memoryTool20250818()).isEmpty assertThat(betaToolUnion.computerUse20250124()).isEmpty assertThat(betaToolUnion.textEditor20241022()).isEmpty + assertThat(betaToolUnion.computerUse20251124()).isEmpty assertThat(betaToolUnion.textEditor20250124()).isEmpty assertThat(betaToolUnion.textEditor20250429()).isEmpty assertThat(betaToolUnion.textEditor20250728()).isEmpty assertThat(betaToolUnion.webSearchTool20250305()).isEmpty assertThat(betaToolUnion.webFetchTool20250910()).isEmpty + assertThat(betaToolUnion.searchToolBm25_20251119()).isEmpty + assertThat(betaToolUnion.searchToolRegex20251119()).isEmpty + assertThat(betaToolUnion.mcpToolset()).isEmpty } @Test @@ -353,12 +434,19 @@ internal class BetaToolUnionTest { BetaToolComputerUse20241022.builder() .displayHeightPx(1L) .displayWidthPx(1L) + .addAllowedCaller(BetaToolComputerUse20241022.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .displayNumber(0L) + .addInputExample( + BetaToolComputerUse20241022.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() ) @@ -376,11 +464,18 @@ internal class BetaToolUnionTest { fun ofMemoryTool20250818() { val memoryTool20250818 = BetaMemoryTool20250818.builder() + .addAllowedCaller(BetaMemoryTool20250818.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaMemoryTool20250818.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() @@ -395,11 +490,15 @@ internal class BetaToolUnionTest { assertThat(betaToolUnion.memoryTool20250818()).contains(memoryTool20250818) assertThat(betaToolUnion.computerUse20250124()).isEmpty assertThat(betaToolUnion.textEditor20241022()).isEmpty + assertThat(betaToolUnion.computerUse20251124()).isEmpty assertThat(betaToolUnion.textEditor20250124()).isEmpty assertThat(betaToolUnion.textEditor20250429()).isEmpty assertThat(betaToolUnion.textEditor20250728()).isEmpty assertThat(betaToolUnion.webSearchTool20250305()).isEmpty assertThat(betaToolUnion.webFetchTool20250910()).isEmpty + assertThat(betaToolUnion.searchToolBm25_20251119()).isEmpty + assertThat(betaToolUnion.searchToolRegex20251119()).isEmpty + assertThat(betaToolUnion.mcpToolset()).isEmpty } @Test @@ -408,11 +507,18 @@ internal class BetaToolUnionTest { val betaToolUnion = BetaToolUnion.ofMemoryTool20250818( BetaMemoryTool20250818.builder() + .addAllowedCaller(BetaMemoryTool20250818.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaMemoryTool20250818.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() ) @@ -432,12 +538,19 @@ internal class BetaToolUnionTest { BetaToolComputerUse20250124.builder() .displayHeightPx(1L) .displayWidthPx(1L) + .addAllowedCaller(BetaToolComputerUse20250124.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .displayNumber(0L) + .addInputExample( + BetaToolComputerUse20250124.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() @@ -452,11 +565,15 @@ internal class BetaToolUnionTest { assertThat(betaToolUnion.memoryTool20250818()).isEmpty assertThat(betaToolUnion.computerUse20250124()).contains(computerUse20250124) assertThat(betaToolUnion.textEditor20241022()).isEmpty + assertThat(betaToolUnion.computerUse20251124()).isEmpty assertThat(betaToolUnion.textEditor20250124()).isEmpty assertThat(betaToolUnion.textEditor20250429()).isEmpty assertThat(betaToolUnion.textEditor20250728()).isEmpty assertThat(betaToolUnion.webSearchTool20250305()).isEmpty assertThat(betaToolUnion.webFetchTool20250910()).isEmpty + assertThat(betaToolUnion.searchToolBm25_20251119()).isEmpty + assertThat(betaToolUnion.searchToolRegex20251119()).isEmpty + assertThat(betaToolUnion.mcpToolset()).isEmpty } @Test @@ -467,12 +584,19 @@ internal class BetaToolUnionTest { BetaToolComputerUse20250124.builder() .displayHeightPx(1L) .displayWidthPx(1L) + .addAllowedCaller(BetaToolComputerUse20250124.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .displayNumber(0L) + .addInputExample( + BetaToolComputerUse20250124.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() ) @@ -490,11 +614,18 @@ internal class BetaToolUnionTest { fun ofTextEditor20241022() { val textEditor20241022 = BetaToolTextEditor20241022.builder() + .addAllowedCaller(BetaToolTextEditor20241022.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaToolTextEditor20241022.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() @@ -509,11 +640,15 @@ internal class BetaToolUnionTest { assertThat(betaToolUnion.memoryTool20250818()).isEmpty assertThat(betaToolUnion.computerUse20250124()).isEmpty assertThat(betaToolUnion.textEditor20241022()).contains(textEditor20241022) + assertThat(betaToolUnion.computerUse20251124()).isEmpty assertThat(betaToolUnion.textEditor20250124()).isEmpty assertThat(betaToolUnion.textEditor20250429()).isEmpty assertThat(betaToolUnion.textEditor20250728()).isEmpty assertThat(betaToolUnion.webSearchTool20250305()).isEmpty assertThat(betaToolUnion.webFetchTool20250910()).isEmpty + assertThat(betaToolUnion.searchToolBm25_20251119()).isEmpty + assertThat(betaToolUnion.searchToolRegex20251119()).isEmpty + assertThat(betaToolUnion.mcpToolset()).isEmpty } @Test @@ -522,11 +657,98 @@ internal class BetaToolUnionTest { val betaToolUnion = BetaToolUnion.ofTextEditor20241022( BetaToolTextEditor20241022.builder() + .addAllowedCaller(BetaToolTextEditor20241022.AllowedCaller.DIRECT) + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .deferLoading(true) + .addInputExample( + BetaToolTextEditor20241022.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .strict(true) + .build() + ) + + val roundtrippedBetaToolUnion = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaToolUnion), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaToolUnion).isEqualTo(betaToolUnion) + } + + @Test + fun ofComputerUse20251124() { + val computerUse20251124 = + BetaToolComputerUse20251124.builder() + .displayHeightPx(1L) + .displayWidthPx(1L) + .addAllowedCaller(BetaToolComputerUse20251124.AllowedCaller.DIRECT) + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .deferLoading(true) + .displayNumber(0L) + .enableZoom(true) + .addInputExample( + BetaToolComputerUse20251124.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .strict(true) + .build() + + val betaToolUnion = BetaToolUnion.ofComputerUse20251124(computerUse20251124) + + assertThat(betaToolUnion.betaTool()).isEmpty + assertThat(betaToolUnion.bash20241022()).isEmpty + assertThat(betaToolUnion.bash20250124()).isEmpty + assertThat(betaToolUnion.codeExecutionTool20250522()).isEmpty + assertThat(betaToolUnion.codeExecutionTool20250825()).isEmpty + assertThat(betaToolUnion.computerUse20241022()).isEmpty + assertThat(betaToolUnion.memoryTool20250818()).isEmpty + assertThat(betaToolUnion.computerUse20250124()).isEmpty + assertThat(betaToolUnion.textEditor20241022()).isEmpty + assertThat(betaToolUnion.computerUse20251124()).contains(computerUse20251124) + assertThat(betaToolUnion.textEditor20250124()).isEmpty + assertThat(betaToolUnion.textEditor20250429()).isEmpty + assertThat(betaToolUnion.textEditor20250728()).isEmpty + assertThat(betaToolUnion.webSearchTool20250305()).isEmpty + assertThat(betaToolUnion.webFetchTool20250910()).isEmpty + assertThat(betaToolUnion.searchToolBm25_20251119()).isEmpty + assertThat(betaToolUnion.searchToolRegex20251119()).isEmpty + assertThat(betaToolUnion.mcpToolset()).isEmpty + } + + @Test + fun ofComputerUse20251124Roundtrip() { + val jsonMapper = jsonMapper() + val betaToolUnion = + BetaToolUnion.ofComputerUse20251124( + BetaToolComputerUse20251124.builder() + .displayHeightPx(1L) + .displayWidthPx(1L) + .addAllowedCaller(BetaToolComputerUse20251124.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .displayNumber(0L) + .enableZoom(true) + .addInputExample( + BetaToolComputerUse20251124.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() ) @@ -544,11 +766,18 @@ internal class BetaToolUnionTest { fun ofTextEditor20250124() { val textEditor20250124 = BetaToolTextEditor20250124.builder() + .addAllowedCaller(BetaToolTextEditor20250124.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaToolTextEditor20250124.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() @@ -563,11 +792,15 @@ internal class BetaToolUnionTest { assertThat(betaToolUnion.memoryTool20250818()).isEmpty assertThat(betaToolUnion.computerUse20250124()).isEmpty assertThat(betaToolUnion.textEditor20241022()).isEmpty + assertThat(betaToolUnion.computerUse20251124()).isEmpty assertThat(betaToolUnion.textEditor20250124()).contains(textEditor20250124) assertThat(betaToolUnion.textEditor20250429()).isEmpty assertThat(betaToolUnion.textEditor20250728()).isEmpty assertThat(betaToolUnion.webSearchTool20250305()).isEmpty assertThat(betaToolUnion.webFetchTool20250910()).isEmpty + assertThat(betaToolUnion.searchToolBm25_20251119()).isEmpty + assertThat(betaToolUnion.searchToolRegex20251119()).isEmpty + assertThat(betaToolUnion.mcpToolset()).isEmpty } @Test @@ -576,11 +809,18 @@ internal class BetaToolUnionTest { val betaToolUnion = BetaToolUnion.ofTextEditor20250124( BetaToolTextEditor20250124.builder() + .addAllowedCaller(BetaToolTextEditor20250124.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaToolTextEditor20250124.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() ) @@ -598,11 +838,18 @@ internal class BetaToolUnionTest { fun ofTextEditor20250429() { val textEditor20250429 = BetaToolTextEditor20250429.builder() + .addAllowedCaller(BetaToolTextEditor20250429.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaToolTextEditor20250429.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() @@ -617,11 +864,15 @@ internal class BetaToolUnionTest { assertThat(betaToolUnion.memoryTool20250818()).isEmpty assertThat(betaToolUnion.computerUse20250124()).isEmpty assertThat(betaToolUnion.textEditor20241022()).isEmpty + assertThat(betaToolUnion.computerUse20251124()).isEmpty assertThat(betaToolUnion.textEditor20250124()).isEmpty assertThat(betaToolUnion.textEditor20250429()).contains(textEditor20250429) assertThat(betaToolUnion.textEditor20250728()).isEmpty assertThat(betaToolUnion.webSearchTool20250305()).isEmpty assertThat(betaToolUnion.webFetchTool20250910()).isEmpty + assertThat(betaToolUnion.searchToolBm25_20251119()).isEmpty + assertThat(betaToolUnion.searchToolRegex20251119()).isEmpty + assertThat(betaToolUnion.mcpToolset()).isEmpty } @Test @@ -630,11 +881,18 @@ internal class BetaToolUnionTest { val betaToolUnion = BetaToolUnion.ofTextEditor20250429( BetaToolTextEditor20250429.builder() + .addAllowedCaller(BetaToolTextEditor20250429.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaToolTextEditor20250429.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .build() ) @@ -652,11 +910,18 @@ internal class BetaToolUnionTest { fun ofTextEditor20250728() { val textEditor20250728 = BetaToolTextEditor20250728.builder() + .addAllowedCaller(BetaToolTextEditor20250728.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaToolTextEditor20250728.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .maxCharacters(1L) .strict(true) .build() @@ -672,11 +937,15 @@ internal class BetaToolUnionTest { assertThat(betaToolUnion.memoryTool20250818()).isEmpty assertThat(betaToolUnion.computerUse20250124()).isEmpty assertThat(betaToolUnion.textEditor20241022()).isEmpty + assertThat(betaToolUnion.computerUse20251124()).isEmpty assertThat(betaToolUnion.textEditor20250124()).isEmpty assertThat(betaToolUnion.textEditor20250429()).isEmpty assertThat(betaToolUnion.textEditor20250728()).contains(textEditor20250728) assertThat(betaToolUnion.webSearchTool20250305()).isEmpty assertThat(betaToolUnion.webFetchTool20250910()).isEmpty + assertThat(betaToolUnion.searchToolBm25_20251119()).isEmpty + assertThat(betaToolUnion.searchToolRegex20251119()).isEmpty + assertThat(betaToolUnion.mcpToolset()).isEmpty } @Test @@ -685,11 +954,18 @@ internal class BetaToolUnionTest { val betaToolUnion = BetaToolUnion.ofTextEditor20250728( BetaToolTextEditor20250728.builder() + .addAllowedCaller(BetaToolTextEditor20250728.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) + .addInputExample( + BetaToolTextEditor20250728.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .maxCharacters(1L) .strict(true) .build() @@ -708,6 +984,7 @@ internal class BetaToolUnionTest { fun ofWebSearchTool20250305() { val webSearchTool20250305 = BetaWebSearchTool20250305.builder() + .addAllowedCaller(BetaWebSearchTool20250305.AllowedCaller.DIRECT) .addAllowedDomain("string") .addBlockedDomain("string") .cacheControl( @@ -715,6 +992,7 @@ internal class BetaToolUnionTest { .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .maxUses(1L) .strict(true) .userLocation( @@ -738,11 +1016,15 @@ internal class BetaToolUnionTest { assertThat(betaToolUnion.memoryTool20250818()).isEmpty assertThat(betaToolUnion.computerUse20250124()).isEmpty assertThat(betaToolUnion.textEditor20241022()).isEmpty + assertThat(betaToolUnion.computerUse20251124()).isEmpty assertThat(betaToolUnion.textEditor20250124()).isEmpty assertThat(betaToolUnion.textEditor20250429()).isEmpty assertThat(betaToolUnion.textEditor20250728()).isEmpty assertThat(betaToolUnion.webSearchTool20250305()).contains(webSearchTool20250305) assertThat(betaToolUnion.webFetchTool20250910()).isEmpty + assertThat(betaToolUnion.searchToolBm25_20251119()).isEmpty + assertThat(betaToolUnion.searchToolRegex20251119()).isEmpty + assertThat(betaToolUnion.mcpToolset()).isEmpty } @Test @@ -751,6 +1033,7 @@ internal class BetaToolUnionTest { val betaToolUnion = BetaToolUnion.ofWebSearchTool20250305( BetaWebSearchTool20250305.builder() + .addAllowedCaller(BetaWebSearchTool20250305.AllowedCaller.DIRECT) .addAllowedDomain("string") .addBlockedDomain("string") .cacheControl( @@ -758,6 +1041,7 @@ internal class BetaToolUnionTest { .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .maxUses(1L) .strict(true) .userLocation( @@ -784,6 +1068,7 @@ internal class BetaToolUnionTest { fun ofWebFetchTool20250910() { val webFetchTool20250910 = BetaWebFetchTool20250910.builder() + .addAllowedCaller(BetaWebFetchTool20250910.AllowedCaller.DIRECT) .addAllowedDomain("string") .addBlockedDomain("string") .cacheControl( @@ -792,6 +1077,7 @@ internal class BetaToolUnionTest { .build() ) .citations(BetaCitationsConfigParam.builder().enabled(true).build()) + .deferLoading(true) .maxContentTokens(1L) .maxUses(1L) .strict(true) @@ -808,11 +1094,15 @@ internal class BetaToolUnionTest { assertThat(betaToolUnion.memoryTool20250818()).isEmpty assertThat(betaToolUnion.computerUse20250124()).isEmpty assertThat(betaToolUnion.textEditor20241022()).isEmpty + assertThat(betaToolUnion.computerUse20251124()).isEmpty assertThat(betaToolUnion.textEditor20250124()).isEmpty assertThat(betaToolUnion.textEditor20250429()).isEmpty assertThat(betaToolUnion.textEditor20250728()).isEmpty assertThat(betaToolUnion.webSearchTool20250305()).isEmpty assertThat(betaToolUnion.webFetchTool20250910()).contains(webFetchTool20250910) + assertThat(betaToolUnion.searchToolBm25_20251119()).isEmpty + assertThat(betaToolUnion.searchToolRegex20251119()).isEmpty + assertThat(betaToolUnion.mcpToolset()).isEmpty } @Test @@ -821,6 +1111,7 @@ internal class BetaToolUnionTest { val betaToolUnion = BetaToolUnion.ofWebFetchTool20250910( BetaWebFetchTool20250910.builder() + .addAllowedCaller(BetaWebFetchTool20250910.AllowedCaller.DIRECT) .addAllowedDomain("string") .addBlockedDomain("string") .cacheControl( @@ -829,6 +1120,7 @@ internal class BetaToolUnionTest { .build() ) .citations(BetaCitationsConfigParam.builder().enabled(true).build()) + .deferLoading(true) .maxContentTokens(1L) .maxUses(1L) .strict(true) @@ -844,6 +1136,214 @@ internal class BetaToolUnionTest { assertThat(roundtrippedBetaToolUnion).isEqualTo(betaToolUnion) } + @Test + fun ofSearchToolBm25_20251119() { + val searchToolBm25_20251119 = + BetaToolSearchToolBm25_20251119.builder() + .type(BetaToolSearchToolBm25_20251119.Type.TOOL_SEARCH_TOOL_BM25_20251119) + .addAllowedCaller(BetaToolSearchToolBm25_20251119.AllowedCaller.DIRECT) + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .deferLoading(true) + .strict(true) + .build() + + val betaToolUnion = BetaToolUnion.ofSearchToolBm25_20251119(searchToolBm25_20251119) + + assertThat(betaToolUnion.betaTool()).isEmpty + assertThat(betaToolUnion.bash20241022()).isEmpty + assertThat(betaToolUnion.bash20250124()).isEmpty + assertThat(betaToolUnion.codeExecutionTool20250522()).isEmpty + assertThat(betaToolUnion.codeExecutionTool20250825()).isEmpty + assertThat(betaToolUnion.computerUse20241022()).isEmpty + assertThat(betaToolUnion.memoryTool20250818()).isEmpty + assertThat(betaToolUnion.computerUse20250124()).isEmpty + assertThat(betaToolUnion.textEditor20241022()).isEmpty + assertThat(betaToolUnion.computerUse20251124()).isEmpty + assertThat(betaToolUnion.textEditor20250124()).isEmpty + assertThat(betaToolUnion.textEditor20250429()).isEmpty + assertThat(betaToolUnion.textEditor20250728()).isEmpty + assertThat(betaToolUnion.webSearchTool20250305()).isEmpty + assertThat(betaToolUnion.webFetchTool20250910()).isEmpty + assertThat(betaToolUnion.searchToolBm25_20251119()).contains(searchToolBm25_20251119) + assertThat(betaToolUnion.searchToolRegex20251119()).isEmpty + assertThat(betaToolUnion.mcpToolset()).isEmpty + } + + @Test + fun ofSearchToolBm25_20251119Roundtrip() { + val jsonMapper = jsonMapper() + val betaToolUnion = + BetaToolUnion.ofSearchToolBm25_20251119( + BetaToolSearchToolBm25_20251119.builder() + .type(BetaToolSearchToolBm25_20251119.Type.TOOL_SEARCH_TOOL_BM25_20251119) + .addAllowedCaller(BetaToolSearchToolBm25_20251119.AllowedCaller.DIRECT) + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .deferLoading(true) + .strict(true) + .build() + ) + + val roundtrippedBetaToolUnion = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaToolUnion), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaToolUnion).isEqualTo(betaToolUnion) + } + + @Test + fun ofSearchToolRegex20251119() { + val searchToolRegex20251119 = + BetaToolSearchToolRegex20251119.builder() + .type(BetaToolSearchToolRegex20251119.Type.TOOL_SEARCH_TOOL_REGEX_20251119) + .addAllowedCaller(BetaToolSearchToolRegex20251119.AllowedCaller.DIRECT) + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .deferLoading(true) + .strict(true) + .build() + + val betaToolUnion = BetaToolUnion.ofSearchToolRegex20251119(searchToolRegex20251119) + + assertThat(betaToolUnion.betaTool()).isEmpty + assertThat(betaToolUnion.bash20241022()).isEmpty + assertThat(betaToolUnion.bash20250124()).isEmpty + assertThat(betaToolUnion.codeExecutionTool20250522()).isEmpty + assertThat(betaToolUnion.codeExecutionTool20250825()).isEmpty + assertThat(betaToolUnion.computerUse20241022()).isEmpty + assertThat(betaToolUnion.memoryTool20250818()).isEmpty + assertThat(betaToolUnion.computerUse20250124()).isEmpty + assertThat(betaToolUnion.textEditor20241022()).isEmpty + assertThat(betaToolUnion.computerUse20251124()).isEmpty + assertThat(betaToolUnion.textEditor20250124()).isEmpty + assertThat(betaToolUnion.textEditor20250429()).isEmpty + assertThat(betaToolUnion.textEditor20250728()).isEmpty + assertThat(betaToolUnion.webSearchTool20250305()).isEmpty + assertThat(betaToolUnion.webFetchTool20250910()).isEmpty + assertThat(betaToolUnion.searchToolBm25_20251119()).isEmpty + assertThat(betaToolUnion.searchToolRegex20251119()).contains(searchToolRegex20251119) + assertThat(betaToolUnion.mcpToolset()).isEmpty + } + + @Test + fun ofSearchToolRegex20251119Roundtrip() { + val jsonMapper = jsonMapper() + val betaToolUnion = + BetaToolUnion.ofSearchToolRegex20251119( + BetaToolSearchToolRegex20251119.builder() + .type(BetaToolSearchToolRegex20251119.Type.TOOL_SEARCH_TOOL_REGEX_20251119) + .addAllowedCaller(BetaToolSearchToolRegex20251119.AllowedCaller.DIRECT) + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .deferLoading(true) + .strict(true) + .build() + ) + + val roundtrippedBetaToolUnion = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaToolUnion), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaToolUnion).isEqualTo(betaToolUnion) + } + + @Test + fun ofMcpToolset() { + val mcpToolset = + BetaMcpToolset.builder() + .mcpServerName("x") + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .configs( + BetaMcpToolset.Configs.builder() + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf("defer_loading" to true, "enabled" to true)), + ) + .build() + ) + .defaultConfig( + BetaMcpToolDefaultConfig.builder().deferLoading(true).enabled(true).build() + ) + .build() + + val betaToolUnion = BetaToolUnion.ofMcpToolset(mcpToolset) + + assertThat(betaToolUnion.betaTool()).isEmpty + assertThat(betaToolUnion.bash20241022()).isEmpty + assertThat(betaToolUnion.bash20250124()).isEmpty + assertThat(betaToolUnion.codeExecutionTool20250522()).isEmpty + assertThat(betaToolUnion.codeExecutionTool20250825()).isEmpty + assertThat(betaToolUnion.computerUse20241022()).isEmpty + assertThat(betaToolUnion.memoryTool20250818()).isEmpty + assertThat(betaToolUnion.computerUse20250124()).isEmpty + assertThat(betaToolUnion.textEditor20241022()).isEmpty + assertThat(betaToolUnion.computerUse20251124()).isEmpty + assertThat(betaToolUnion.textEditor20250124()).isEmpty + assertThat(betaToolUnion.textEditor20250429()).isEmpty + assertThat(betaToolUnion.textEditor20250728()).isEmpty + assertThat(betaToolUnion.webSearchTool20250305()).isEmpty + assertThat(betaToolUnion.webFetchTool20250910()).isEmpty + assertThat(betaToolUnion.searchToolBm25_20251119()).isEmpty + assertThat(betaToolUnion.searchToolRegex20251119()).isEmpty + assertThat(betaToolUnion.mcpToolset()).contains(mcpToolset) + } + + @Test + fun ofMcpToolsetRoundtrip() { + val jsonMapper = jsonMapper() + val betaToolUnion = + BetaToolUnion.ofMcpToolset( + BetaMcpToolset.builder() + .mcpServerName("x") + .cacheControl( + BetaCacheControlEphemeral.builder() + .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) + .build() + ) + .configs( + BetaMcpToolset.Configs.builder() + .putAdditionalProperty( + "foo", + JsonValue.from(mapOf("defer_loading" to true, "enabled" to true)), + ) + .build() + ) + .defaultConfig( + BetaMcpToolDefaultConfig.builder().deferLoading(true).enabled(true).build() + ) + .build() + ) + + val roundtrippedBetaToolUnion = + jsonMapper.readValue( + jsonMapper.writeValueAsString(betaToolUnion), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBetaToolUnion).isEqualTo(betaToolUnion) + } + 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/messages/BetaToolUseBlockParamTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolUseBlockParamTest.kt index 5cd9a6963..a16970c23 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolUseBlockParamTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolUseBlockParamTest.kt @@ -26,6 +26,7 @@ internal class BetaToolUseBlockParamTest { .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .caller(BetaDirectCaller.builder().build()) .build() assertThat(betaToolUseBlockParam.id()).isEqualTo("id") @@ -42,6 +43,8 @@ internal class BetaToolUseBlockParamTest { .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + assertThat(betaToolUseBlockParam.caller()) + .contains(BetaToolUseBlockParam.Caller.ofDirect(BetaDirectCaller.builder().build())) } @Test @@ -61,6 +64,7 @@ internal class BetaToolUseBlockParamTest { .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .caller(BetaDirectCaller.builder().build()) .build() val roundtrippedBetaToolUseBlockParam = diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolUseBlockTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolUseBlockTest.kt index 6a852116d..7f8bde0af 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolUseBlockTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaToolUseBlockTest.kt @@ -17,11 +17,14 @@ internal class BetaToolUseBlockTest { .id("id") .input(JsonValue.from(mapOf())) .name("x") + .caller(BetaDirectCaller.builder().build()) .build() assertThat(betaToolUseBlock.id()).isEqualTo("id") assertThat(betaToolUseBlock._input()).isEqualTo(JsonValue.from(mapOf())) assertThat(betaToolUseBlock.name()).isEqualTo("x") + assertThat(betaToolUseBlock.caller()) + .contains(BetaToolUseBlock.Caller.ofDirect(BetaDirectCaller.builder().build())) } @Test @@ -32,6 +35,7 @@ internal class BetaToolUseBlockTest { .id("id") .input(JsonValue.from(mapOf())) .name("x") + .caller(BetaDirectCaller.builder().build()) .build() val roundtrippedBetaToolUseBlock = diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaWebFetchTool20250910Test.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaWebFetchTool20250910Test.kt index afabb4ac0..c69ab6504 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaWebFetchTool20250910Test.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaWebFetchTool20250910Test.kt @@ -14,6 +14,7 @@ internal class BetaWebFetchTool20250910Test { fun create() { val betaWebFetchTool20250910 = BetaWebFetchTool20250910.builder() + .addAllowedCaller(BetaWebFetchTool20250910.AllowedCaller.DIRECT) .addAllowedDomain("string") .addBlockedDomain("string") .cacheControl( @@ -22,11 +23,14 @@ internal class BetaWebFetchTool20250910Test { .build() ) .citations(BetaCitationsConfigParam.builder().enabled(true).build()) + .deferLoading(true) .maxContentTokens(1L) .maxUses(1L) .strict(true) .build() + assertThat(betaWebFetchTool20250910.allowedCallers().getOrNull()) + .containsExactly(BetaWebFetchTool20250910.AllowedCaller.DIRECT) assertThat(betaWebFetchTool20250910.allowedDomains().getOrNull()).containsExactly("string") assertThat(betaWebFetchTool20250910.blockedDomains().getOrNull()).containsExactly("string") assertThat(betaWebFetchTool20250910.cacheControl()) @@ -37,6 +41,7 @@ internal class BetaWebFetchTool20250910Test { ) assertThat(betaWebFetchTool20250910.citations()) .contains(BetaCitationsConfigParam.builder().enabled(true).build()) + assertThat(betaWebFetchTool20250910.deferLoading()).contains(true) assertThat(betaWebFetchTool20250910.maxContentTokens()).contains(1L) assertThat(betaWebFetchTool20250910.maxUses()).contains(1L) assertThat(betaWebFetchTool20250910.strict()).contains(true) @@ -47,6 +52,7 @@ internal class BetaWebFetchTool20250910Test { val jsonMapper = jsonMapper() val betaWebFetchTool20250910 = BetaWebFetchTool20250910.builder() + .addAllowedCaller(BetaWebFetchTool20250910.AllowedCaller.DIRECT) .addAllowedDomain("string") .addBlockedDomain("string") .cacheControl( @@ -55,6 +61,7 @@ internal class BetaWebFetchTool20250910Test { .build() ) .citations(BetaCitationsConfigParam.builder().enabled(true).build()) + .deferLoading(true) .maxContentTokens(1L) .maxUses(1L) .strict(true) diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaWebSearchTool20250305Test.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaWebSearchTool20250305Test.kt index da5784fab..d354d0e90 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaWebSearchTool20250305Test.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/BetaWebSearchTool20250305Test.kt @@ -14,6 +14,7 @@ internal class BetaWebSearchTool20250305Test { fun create() { val betaWebSearchTool20250305 = BetaWebSearchTool20250305.builder() + .addAllowedCaller(BetaWebSearchTool20250305.AllowedCaller.DIRECT) .addAllowedDomain("string") .addBlockedDomain("string") .cacheControl( @@ -21,6 +22,7 @@ internal class BetaWebSearchTool20250305Test { .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .maxUses(1L) .strict(true) .userLocation( @@ -33,6 +35,8 @@ internal class BetaWebSearchTool20250305Test { ) .build() + assertThat(betaWebSearchTool20250305.allowedCallers().getOrNull()) + .containsExactly(BetaWebSearchTool20250305.AllowedCaller.DIRECT) assertThat(betaWebSearchTool20250305.allowedDomains().getOrNull()).containsExactly("string") assertThat(betaWebSearchTool20250305.blockedDomains().getOrNull()).containsExactly("string") assertThat(betaWebSearchTool20250305.cacheControl()) @@ -41,6 +45,7 @@ internal class BetaWebSearchTool20250305Test { .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + assertThat(betaWebSearchTool20250305.deferLoading()).contains(true) assertThat(betaWebSearchTool20250305.maxUses()).contains(1L) assertThat(betaWebSearchTool20250305.strict()).contains(true) assertThat(betaWebSearchTool20250305.userLocation()) @@ -59,6 +64,7 @@ internal class BetaWebSearchTool20250305Test { val jsonMapper = jsonMapper() val betaWebSearchTool20250305 = BetaWebSearchTool20250305.builder() + .addAllowedCaller(BetaWebSearchTool20250305.AllowedCaller.DIRECT) .addAllowedDomain("string") .addBlockedDomain("string") .cacheControl( @@ -66,6 +72,7 @@ internal class BetaWebSearchTool20250305Test { .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .maxUses(1L) .strict(true) .userLocation( diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/MessageCountTokensParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/MessageCountTokensParamsTest.kt index 3f1edca55..9d73d2855 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/MessageCountTokensParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/MessageCountTokensParamsTest.kt @@ -15,9 +15,9 @@ internal class MessageCountTokensParamsTest { @Test fun create() { MessageCountTokensParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .contextManagement( BetaContextManagementConfig.builder() .addEdit( @@ -44,6 +44,7 @@ internal class MessageCountTokensParamsTest { ) .build() ) + .outputConfig(BetaOutputConfig.builder().effort(BetaOutputConfig.Effort.LOW).build()) .outputFormat( BetaJsonOutputFormat.builder() .schema( @@ -90,12 +91,19 @@ internal class MessageCountTokensParamsTest { .build() ) .name("name") + .addAllowedCaller(BetaTool.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .description("Get the current weather in a given location") + .addInputExample( + BetaTool.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .type(BetaTool.Type.CUSTOM) .build() @@ -107,9 +115,9 @@ internal class MessageCountTokensParamsTest { fun headers() { val params = MessageCountTokensParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .contextManagement( BetaContextManagementConfig.builder() .addEdit( @@ -138,6 +146,9 @@ internal class MessageCountTokensParamsTest { ) .build() ) + .outputConfig( + BetaOutputConfig.builder().effort(BetaOutputConfig.Effort.LOW).build() + ) .outputFormat( BetaJsonOutputFormat.builder() .schema( @@ -184,12 +195,19 @@ internal class MessageCountTokensParamsTest { .build() ) .name("name") + .addAllowedCaller(BetaTool.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .description("Get the current weather in a given location") + .addInputExample( + BetaTool.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .type(BetaTool.Type.CUSTOM) .build() @@ -198,10 +216,7 @@ internal class MessageCountTokensParamsTest { val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test @@ -209,7 +224,7 @@ internal class MessageCountTokensParamsTest { val params = MessageCountTokensParams.builder() .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .build() val headers = params._headers() @@ -221,9 +236,9 @@ internal class MessageCountTokensParamsTest { fun body() { val params = MessageCountTokensParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .contextManagement( BetaContextManagementConfig.builder() .addEdit( @@ -252,6 +267,9 @@ internal class MessageCountTokensParamsTest { ) .build() ) + .outputConfig( + BetaOutputConfig.builder().effort(BetaOutputConfig.Effort.LOW).build() + ) .outputFormat( BetaJsonOutputFormat.builder() .schema( @@ -298,12 +316,19 @@ internal class MessageCountTokensParamsTest { .build() ) .name("name") + .addAllowedCaller(BetaTool.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .description("Get the current weather in a given location") + .addInputExample( + BetaTool.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .type(BetaTool.Type.CUSTOM) .build() @@ -319,7 +344,7 @@ internal class MessageCountTokensParamsTest { .role(BetaMessageParam.Role.USER) .build() ) - assertThat(body.model()).isEqualTo(Model.CLAUDE_3_7_SONNET_LATEST) + assertThat(body.model()).isEqualTo(Model.CLAUDE_SONNET_4_5_20250929) assertThat(body.contextManagement()) .contains( BetaContextManagementConfig.builder() @@ -348,6 +373,8 @@ internal class MessageCountTokensParamsTest { ) .build() ) + assertThat(body.outputConfig()) + .contains(BetaOutputConfig.builder().effort(BetaOutputConfig.Effort.LOW).build()) assertThat(body.outputFormat()) .contains( BetaJsonOutputFormat.builder() @@ -410,12 +437,19 @@ internal class MessageCountTokensParamsTest { .build() ) .name("name") + .addAllowedCaller(BetaTool.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .description("Get the current weather in a given location") + .addInputExample( + BetaTool.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .type(BetaTool.Type.CUSTOM) .build() @@ -428,7 +462,7 @@ internal class MessageCountTokensParamsTest { val params = MessageCountTokensParams.builder() .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .build() val body = params._body() @@ -440,6 +474,6 @@ internal class MessageCountTokensParamsTest { .role(BetaMessageParam.Role.USER) .build() ) - assertThat(body.model()).isEqualTo(Model.CLAUDE_3_7_SONNET_LATEST) + assertThat(body.model()).isEqualTo(Model.CLAUDE_SONNET_4_5_20250929) } } diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/MessageCreateParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/MessageCreateParamsTest.kt index b4c92d3a6..77681b2a2 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/MessageCreateParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/MessageCreateParamsTest.kt @@ -15,10 +15,10 @@ internal class MessageCreateParamsTest { @Test fun create() { MessageCreateParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .container( BetaContainerParams.builder() .id("id") @@ -58,6 +58,7 @@ internal class MessageCreateParamsTest { .build() ) .metadata(BetaMetadata.builder().userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b").build()) + .outputConfig(BetaOutputConfig.builder().effort(BetaOutputConfig.Effort.LOW).build()) .outputFormat( BetaJsonOutputFormat.builder() .schema( @@ -107,12 +108,19 @@ internal class MessageCreateParamsTest { .build() ) .name("name") + .addAllowedCaller(BetaTool.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .description("Get the current weather in a given location") + .addInputExample( + BetaTool.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .type(BetaTool.Type.CUSTOM) .build() @@ -126,10 +134,10 @@ internal class MessageCreateParamsTest { fun headers() { val params = MessageCreateParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .container( BetaContainerParams.builder() .id("id") @@ -173,6 +181,9 @@ internal class MessageCreateParamsTest { .metadata( BetaMetadata.builder().userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b").build() ) + .outputConfig( + BetaOutputConfig.builder().effort(BetaOutputConfig.Effort.LOW).build() + ) .outputFormat( BetaJsonOutputFormat.builder() .schema( @@ -222,12 +233,19 @@ internal class MessageCreateParamsTest { .build() ) .name("name") + .addAllowedCaller(BetaTool.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .description("Get the current weather in a given location") + .addInputExample( + BetaTool.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .type(BetaTool.Type.CUSTOM) .build() @@ -238,10 +256,7 @@ internal class MessageCreateParamsTest { val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test @@ -250,7 +265,7 @@ internal class MessageCreateParamsTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .build() val headers = params._headers() @@ -262,10 +277,10 @@ internal class MessageCreateParamsTest { fun body() { val params = MessageCreateParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .container( BetaContainerParams.builder() .id("id") @@ -309,6 +324,9 @@ internal class MessageCreateParamsTest { .metadata( BetaMetadata.builder().userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b").build() ) + .outputConfig( + BetaOutputConfig.builder().effort(BetaOutputConfig.Effort.LOW).build() + ) .outputFormat( BetaJsonOutputFormat.builder() .schema( @@ -358,12 +376,19 @@ internal class MessageCreateParamsTest { .build() ) .name("name") + .addAllowedCaller(BetaTool.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .description("Get the current weather in a given location") + .addInputExample( + BetaTool.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .type(BetaTool.Type.CUSTOM) .build() @@ -382,7 +407,7 @@ internal class MessageCreateParamsTest { .role(BetaMessageParam.Role.USER) .build() ) - assertThat(body.model()).isEqualTo(Model.CLAUDE_3_7_SONNET_LATEST) + assertThat(body.model()).isEqualTo(Model.CLAUDE_SONNET_4_5_20250929) assertThat(body.container()) .contains( MessageCreateParams.Container.ofBetaContainerParams( @@ -428,6 +453,8 @@ internal class MessageCreateParamsTest { ) assertThat(body.metadata()) .contains(BetaMetadata.builder().userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b").build()) + assertThat(body.outputConfig()) + .contains(BetaOutputConfig.builder().effort(BetaOutputConfig.Effort.LOW).build()) assertThat(body.outputFormat()) .contains( BetaJsonOutputFormat.builder() @@ -493,12 +520,19 @@ internal class MessageCreateParamsTest { .build() ) .name("name") + .addAllowedCaller(BetaTool.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .description("Get the current weather in a given location") + .addInputExample( + BetaTool.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .type(BetaTool.Type.CUSTOM) .build() @@ -514,7 +548,7 @@ internal class MessageCreateParamsTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .build() val body = params._body() @@ -527,6 +561,6 @@ internal class MessageCreateParamsTest { .role(BetaMessageParam.Role.USER) .build() ) - assertThat(body.model()).isEqualTo(Model.CLAUDE_3_7_SONNET_LATEST) + assertThat(body.model()).isEqualTo(Model.CLAUDE_SONNET_4_5_20250929) } } diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BatchCancelParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BatchCancelParamsTest.kt index c267e8cfa..9e9e31b20 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BatchCancelParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BatchCancelParamsTest.kt @@ -13,7 +13,7 @@ internal class BatchCancelParamsTest { fun create() { BatchCancelParams.builder() .messageBatchId("message_batch_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() } @@ -31,15 +31,12 @@ internal class BatchCancelParamsTest { val params = BatchCancelParams.builder() .messageBatchId("message_batch_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BatchCreateParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BatchCreateParamsTest.kt index 4f1612dca..a75a08958 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BatchCreateParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BatchCreateParamsTest.kt @@ -13,6 +13,7 @@ import com.anthropic.models.beta.messages.BetaContextManagementConfig import com.anthropic.models.beta.messages.BetaInputTokensClearAtLeast import com.anthropic.models.beta.messages.BetaJsonOutputFormat import com.anthropic.models.beta.messages.BetaMetadata +import com.anthropic.models.beta.messages.BetaOutputConfig import com.anthropic.models.beta.messages.BetaRequestMcpServerToolConfiguration import com.anthropic.models.beta.messages.BetaRequestMcpServerUrlDefinition import com.anthropic.models.beta.messages.BetaSkillParams @@ -29,7 +30,7 @@ internal class BatchCreateParamsTest { @Test fun create() { BatchCreateParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .addRequest( BatchCreateParams.Request.builder() .customId("my-custom-id-1") @@ -37,7 +38,7 @@ internal class BatchCreateParamsTest { BatchCreateParams.Request.Params.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .container( BetaContainerParams.builder() .id("id") @@ -85,6 +86,11 @@ internal class BatchCreateParamsTest { .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") .build() ) + .outputConfig( + BetaOutputConfig.builder() + .effort(BetaOutputConfig.Effort.LOW) + .build() + ) .outputFormat( BetaJsonOutputFormat.builder() .schema( @@ -143,12 +149,19 @@ internal class BatchCreateParamsTest { .build() ) .name("name") + .addAllowedCaller(BetaTool.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .description("Get the current weather in a given location") + .addInputExample( + BetaTool.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .type(BetaTool.Type.CUSTOM) .build() @@ -166,7 +179,7 @@ internal class BatchCreateParamsTest { fun headers() { val params = BatchCreateParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .addRequest( BatchCreateParams.Request.builder() .customId("my-custom-id-1") @@ -174,7 +187,7 @@ internal class BatchCreateParamsTest { BatchCreateParams.Request.Params.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .container( BetaContainerParams.builder() .id("id") @@ -222,6 +235,11 @@ internal class BatchCreateParamsTest { .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") .build() ) + .outputConfig( + BetaOutputConfig.builder() + .effort(BetaOutputConfig.Effort.LOW) + .build() + ) .outputFormat( BetaJsonOutputFormat.builder() .schema( @@ -282,12 +300,19 @@ internal class BatchCreateParamsTest { .build() ) .name("name") + .addAllowedCaller(BetaTool.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .description("Get the current weather in a given location") + .addInputExample( + BetaTool.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .type(BetaTool.Type.CUSTOM) .build() @@ -302,10 +327,7 @@ internal class BatchCreateParamsTest { val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test @@ -319,7 +341,7 @@ internal class BatchCreateParamsTest { BatchCreateParams.Request.Params.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .build() ) .build() @@ -335,7 +357,7 @@ internal class BatchCreateParamsTest { fun body() { val params = BatchCreateParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .addRequest( BatchCreateParams.Request.builder() .customId("my-custom-id-1") @@ -343,7 +365,7 @@ internal class BatchCreateParamsTest { BatchCreateParams.Request.Params.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .container( BetaContainerParams.builder() .id("id") @@ -391,6 +413,11 @@ internal class BatchCreateParamsTest { .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") .build() ) + .outputConfig( + BetaOutputConfig.builder() + .effort(BetaOutputConfig.Effort.LOW) + .build() + ) .outputFormat( BetaJsonOutputFormat.builder() .schema( @@ -451,12 +478,19 @@ internal class BatchCreateParamsTest { .build() ) .name("name") + .addAllowedCaller(BetaTool.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .description("Get the current weather in a given location") + .addInputExample( + BetaTool.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .type(BetaTool.Type.CUSTOM) .build() @@ -479,7 +513,7 @@ internal class BatchCreateParamsTest { BatchCreateParams.Request.Params.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .container( BetaContainerParams.builder() .id("id") @@ -527,6 +561,11 @@ internal class BatchCreateParamsTest { .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") .build() ) + .outputConfig( + BetaOutputConfig.builder() + .effort(BetaOutputConfig.Effort.LOW) + .build() + ) .outputFormat( BetaJsonOutputFormat.builder() .schema( @@ -585,12 +624,19 @@ internal class BatchCreateParamsTest { .build() ) .name("name") + .addAllowedCaller(BetaTool.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .description("Get the current weather in a given location") + .addInputExample( + BetaTool.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .type(BetaTool.Type.CUSTOM) .build() @@ -614,7 +660,7 @@ internal class BatchCreateParamsTest { BatchCreateParams.Request.Params.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .build() ) .build() @@ -631,7 +677,7 @@ internal class BatchCreateParamsTest { BatchCreateParams.Request.Params.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .build() ) .build() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BatchDeleteParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BatchDeleteParamsTest.kt index 5d0f8cc80..664085949 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BatchDeleteParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BatchDeleteParamsTest.kt @@ -13,7 +13,7 @@ internal class BatchDeleteParamsTest { fun create() { BatchDeleteParams.builder() .messageBatchId("message_batch_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() } @@ -31,15 +31,12 @@ internal class BatchDeleteParamsTest { val params = BatchDeleteParams.builder() .messageBatchId("message_batch_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BatchListParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BatchListParamsTest.kt index 6d7001dad..3835e8917 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BatchListParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BatchListParamsTest.kt @@ -16,7 +16,7 @@ internal class BatchListParamsTest { .afterId("after_id") .beforeId("before_id") .limit(1L) - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() } @@ -27,15 +27,12 @@ internal class BatchListParamsTest { .afterId("after_id") .beforeId("before_id") .limit(1L) - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test @@ -54,7 +51,7 @@ internal class BatchListParamsTest { .afterId("after_id") .beforeId("before_id") .limit(1L) - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() val queryParams = params._queryParams() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BatchResultsParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BatchResultsParamsTest.kt index 8c109c427..88d081c1e 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BatchResultsParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BatchResultsParamsTest.kt @@ -13,7 +13,7 @@ internal class BatchResultsParamsTest { fun create() { BatchResultsParams.builder() .messageBatchId("message_batch_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() } @@ -31,15 +31,12 @@ internal class BatchResultsParamsTest { val params = BatchResultsParams.builder() .messageBatchId("message_batch_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BatchRetrieveParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BatchRetrieveParamsTest.kt index 72b80abc5..7e24a8664 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BatchRetrieveParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BatchRetrieveParamsTest.kt @@ -13,7 +13,7 @@ internal class BatchRetrieveParamsTest { fun create() { BatchRetrieveParams.builder() .messageBatchId("message_batch_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() } @@ -31,15 +31,12 @@ internal class BatchRetrieveParamsTest { val params = BatchRetrieveParams.builder() .messageBatchId("message_batch_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BetaMessageBatchIndividualResponseTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BetaMessageBatchIndividualResponseTest.kt index e9d5a12fe..b612aa7d5 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BetaMessageBatchIndividualResponseTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BetaMessageBatchIndividualResponseTest.kt @@ -68,7 +68,7 @@ internal class BetaMessageBatchIndividualResponseTest { ) .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(BetaStopReason.END_TURN) .stopSequence(null) .usage( @@ -142,7 +142,7 @@ internal class BetaMessageBatchIndividualResponseTest { ) .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(BetaStopReason.END_TURN) .stopSequence(null) .usage( @@ -220,7 +220,7 @@ internal class BetaMessageBatchIndividualResponseTest { ) .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(BetaStopReason.END_TURN) .stopSequence(null) .usage( diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BetaMessageBatchResultTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BetaMessageBatchResultTest.kt index 4f34e7dfa..630f468d7 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BetaMessageBatchResultTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BetaMessageBatchResultTest.kt @@ -73,7 +73,7 @@ internal class BetaMessageBatchResultTest { ) .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(BetaStopReason.END_TURN) .stopSequence(null) .usage( @@ -156,7 +156,7 @@ internal class BetaMessageBatchResultTest { ) .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(BetaStopReason.END_TURN) .stopSequence(null) .usage( diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BetaMessageBatchSucceededResultTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BetaMessageBatchSucceededResultTest.kt index e14cc1bb6..c33ad98b3 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BetaMessageBatchSucceededResultTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/messages/batches/BetaMessageBatchSucceededResultTest.kt @@ -67,7 +67,7 @@ internal class BetaMessageBatchSucceededResultTest { ) .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(BetaStopReason.END_TURN) .stopSequence(null) .usage( @@ -137,7 +137,7 @@ internal class BetaMessageBatchSucceededResultTest { ) .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(BetaStopReason.END_TURN) .stopSequence(null) .usage( @@ -211,7 +211,7 @@ internal class BetaMessageBatchSucceededResultTest { ) .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(BetaStopReason.END_TURN) .stopSequence(null) .usage( diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/models/ModelListParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/models/ModelListParamsTest.kt index 27f0d739a..0b0ceb114 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/models/ModelListParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/models/ModelListParamsTest.kt @@ -16,7 +16,7 @@ internal class ModelListParamsTest { .afterId("after_id") .beforeId("before_id") .limit(1L) - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() } @@ -27,15 +27,12 @@ internal class ModelListParamsTest { .afterId("after_id") .beforeId("before_id") .limit(1L) - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test @@ -54,7 +51,7 @@ internal class ModelListParamsTest { .afterId("after_id") .beforeId("before_id") .limit(1L) - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() val queryParams = params._queryParams() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/models/ModelRetrieveParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/models/ModelRetrieveParamsTest.kt index 4da826172..7d60bf8da 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/models/ModelRetrieveParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/models/ModelRetrieveParamsTest.kt @@ -13,7 +13,7 @@ internal class ModelRetrieveParamsTest { fun create() { ModelRetrieveParams.builder() .modelId("model_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() } @@ -31,15 +31,12 @@ internal class ModelRetrieveParamsTest { val params = ModelRetrieveParams.builder() .modelId("model_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/SkillCreateParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/SkillCreateParamsTest.kt index 3df8d777f..8c1f9e255 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/SkillCreateParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/SkillCreateParamsTest.kt @@ -14,7 +14,7 @@ internal class SkillCreateParamsTest { @Test fun create() { SkillCreateParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .displayTitle("display_title") .addFile("some content".byteInputStream()) .build() @@ -24,17 +24,14 @@ internal class SkillCreateParamsTest { fun headers() { val params = SkillCreateParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .displayTitle("display_title") .addFile("some content".byteInputStream()) .build() val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test @@ -50,7 +47,7 @@ internal class SkillCreateParamsTest { fun body() { val params = SkillCreateParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .displayTitle("display_title") .addFile("some content".byteInputStream()) .build() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/SkillDeleteParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/SkillDeleteParamsTest.kt index a8440ba00..bc99106c6 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/SkillDeleteParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/SkillDeleteParamsTest.kt @@ -11,10 +11,7 @@ internal class SkillDeleteParamsTest { @Test fun create() { - SkillDeleteParams.builder() - .skillId("skill_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) - .build() + SkillDeleteParams.builder().skillId("skill_id").addBeta(AnthropicBeta.of("string")).build() } @Test @@ -31,15 +28,12 @@ internal class SkillDeleteParamsTest { val params = SkillDeleteParams.builder() .skillId("skill_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/SkillListParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/SkillListParamsTest.kt index 8a725cfaa..49b5b5ebb 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/SkillListParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/SkillListParamsTest.kt @@ -16,7 +16,7 @@ internal class SkillListParamsTest { .limit(0L) .page("page") .source("source") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() } @@ -27,15 +27,12 @@ internal class SkillListParamsTest { .limit(0L) .page("page") .source("source") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test @@ -54,7 +51,7 @@ internal class SkillListParamsTest { .limit(0L) .page("page") .source("source") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() val queryParams = params._queryParams() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/SkillRetrieveParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/SkillRetrieveParamsTest.kt index 8c9ba5343..44627474b 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/SkillRetrieveParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/SkillRetrieveParamsTest.kt @@ -13,7 +13,7 @@ internal class SkillRetrieveParamsTest { fun create() { SkillRetrieveParams.builder() .skillId("skill_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() } @@ -31,15 +31,12 @@ internal class SkillRetrieveParamsTest { val params = SkillRetrieveParams.builder() .skillId("skill_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/versions/VersionCreateParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/versions/VersionCreateParamsTest.kt index 6b3404aff..0ba5a487f 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/versions/VersionCreateParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/versions/VersionCreateParamsTest.kt @@ -15,7 +15,7 @@ internal class VersionCreateParamsTest { fun create() { VersionCreateParams.builder() .skillId("skill_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .addFile("some content".byteInputStream()) .build() } @@ -34,16 +34,13 @@ internal class VersionCreateParamsTest { val params = VersionCreateParams.builder() .skillId("skill_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .addFile("some content".byteInputStream()) .build() val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test @@ -60,7 +57,7 @@ internal class VersionCreateParamsTest { val params = VersionCreateParams.builder() .skillId("skill_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .addFile("some content".byteInputStream()) .build() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/versions/VersionDeleteParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/versions/VersionDeleteParamsTest.kt index fa400d283..b77149e0c 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/versions/VersionDeleteParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/versions/VersionDeleteParamsTest.kt @@ -14,7 +14,7 @@ internal class VersionDeleteParamsTest { VersionDeleteParams.builder() .skillId("skill_id") .version("version") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() } @@ -34,15 +34,12 @@ internal class VersionDeleteParamsTest { VersionDeleteParams.builder() .skillId("skill_id") .version("version") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/versions/VersionListParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/versions/VersionListParamsTest.kt index ba5f0cbb4..3a2fcdb68 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/versions/VersionListParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/versions/VersionListParamsTest.kt @@ -16,7 +16,7 @@ internal class VersionListParamsTest { .skillId("skill_id") .limit(0L) .page("page") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() } @@ -36,15 +36,12 @@ internal class VersionListParamsTest { .skillId("skill_id") .limit(0L) .page("page") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test @@ -63,7 +60,7 @@ internal class VersionListParamsTest { .skillId("skill_id") .limit(0L) .page("page") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() val queryParams = params._queryParams() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/versions/VersionRetrieveParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/versions/VersionRetrieveParamsTest.kt index fa8fbffe3..5f13214af 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/versions/VersionRetrieveParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/beta/skills/versions/VersionRetrieveParamsTest.kt @@ -14,7 +14,7 @@ internal class VersionRetrieveParamsTest { VersionRetrieveParams.builder() .skillId("skill_id") .version("version") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() } @@ -34,15 +34,12 @@ internal class VersionRetrieveParamsTest { VersionRetrieveParams.builder() .skillId("skill_id") .version("version") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/completions/CompletionCreateParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/completions/CompletionCreateParamsTest.kt index fa218df12..46be5fda2 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/completions/CompletionCreateParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/completions/CompletionCreateParamsTest.kt @@ -15,9 +15,9 @@ internal class CompletionCreateParamsTest { @Test fun create() { CompletionCreateParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .maxTokensToSample(256L) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.of("claude-2.1")) .prompt("\n\nHuman: Hello, world!\n\nAssistant:") .metadata(Metadata.builder().userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b").build()) .addStopSequence("string") @@ -31,9 +31,9 @@ internal class CompletionCreateParamsTest { fun headers() { val params = CompletionCreateParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .maxTokensToSample(256L) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.of("claude-2.1")) .prompt("\n\nHuman: Hello, world!\n\nAssistant:") .metadata(Metadata.builder().userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b").build()) .addStopSequence("string") @@ -44,10 +44,7 @@ internal class CompletionCreateParamsTest { val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test @@ -55,7 +52,7 @@ internal class CompletionCreateParamsTest { val params = CompletionCreateParams.builder() .maxTokensToSample(256L) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.of("claude-2.1")) .prompt("\n\nHuman: Hello, world!\n\nAssistant:") .build() @@ -68,9 +65,9 @@ internal class CompletionCreateParamsTest { fun body() { val params = CompletionCreateParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .maxTokensToSample(256L) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.of("claude-2.1")) .prompt("\n\nHuman: Hello, world!\n\nAssistant:") .metadata(Metadata.builder().userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b").build()) .addStopSequence("string") @@ -82,7 +79,7 @@ internal class CompletionCreateParamsTest { val body = params._body() assertThat(body.maxTokensToSample()).isEqualTo(256L) - assertThat(body.model()).isEqualTo(Model.CLAUDE_3_7_SONNET_LATEST) + assertThat(body.model()).isEqualTo(Model.of("claude-2.1")) assertThat(body.prompt()).isEqualTo("\n\nHuman: Hello, world!\n\nAssistant:") assertThat(body.metadata()) .contains(Metadata.builder().userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b").build()) @@ -97,14 +94,14 @@ internal class CompletionCreateParamsTest { val params = CompletionCreateParams.builder() .maxTokensToSample(256L) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.of("claude-2.1")) .prompt("\n\nHuman: Hello, world!\n\nAssistant:") .build() val body = params._body() assertThat(body.maxTokensToSample()).isEqualTo(256L) - assertThat(body.model()).isEqualTo(Model.CLAUDE_3_7_SONNET_LATEST) + assertThat(body.model()).isEqualTo(Model.of("claude-2.1")) assertThat(body.prompt()).isEqualTo("\n\nHuman: Hello, world!\n\nAssistant:") } } diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/completions/CompletionTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/completions/CompletionTest.kt index eb1e06b0f..dcdf78bf2 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/completions/CompletionTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/completions/CompletionTest.kt @@ -16,13 +16,13 @@ internal class CompletionTest { Completion.builder() .id("compl_018CKm6gsux7P8yMcwZbeCPw") .completion(" Hello! My name is Claude.") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.of("claude-2.1")) .stopReason("stop_sequence") .build() assertThat(completion.id()).isEqualTo("compl_018CKm6gsux7P8yMcwZbeCPw") assertThat(completion.completion()).isEqualTo(" Hello! My name is Claude.") - assertThat(completion.model()).isEqualTo(Model.CLAUDE_3_7_SONNET_LATEST) + assertThat(completion.model()).isEqualTo(Model.of("claude-2.1")) assertThat(completion.stopReason()).contains("stop_sequence") } @@ -33,7 +33,7 @@ internal class CompletionTest { Completion.builder() .id("compl_018CKm6gsux7P8yMcwZbeCPw") .completion(" Hello! My name is Claude.") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.of("claude-2.1")) .stopReason("stop_sequence") .build() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/MessageCountTokensParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/MessageCountTokensParamsTest.kt index 3fced7bd9..38d5d445f 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/MessageCountTokensParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/MessageCountTokensParamsTest.kt @@ -13,7 +13,7 @@ internal class MessageCountTokensParamsTest { fun create() { MessageCountTokensParams.builder() .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .systemOfTextBlockParams( listOf( TextBlockParam.builder() @@ -68,7 +68,7 @@ internal class MessageCountTokensParamsTest { val params = MessageCountTokensParams.builder() .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .systemOfTextBlockParams( listOf( TextBlockParam.builder() @@ -123,7 +123,7 @@ internal class MessageCountTokensParamsTest { .containsExactly( MessageParam.builder().content("Hello, world").role(MessageParam.Role.USER).build() ) - assertThat(body.model()).isEqualTo(Model.CLAUDE_3_7_SONNET_LATEST) + assertThat(body.model()).isEqualTo(Model.CLAUDE_SONNET_4_5_20250929) assertThat(body.system()) .contains( MessageCountTokensParams.System.ofTextBlockParams( @@ -191,7 +191,7 @@ internal class MessageCountTokensParamsTest { val params = MessageCountTokensParams.builder() .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .build() val body = params._body() @@ -200,6 +200,6 @@ internal class MessageCountTokensParamsTest { .containsExactly( MessageParam.builder().content("Hello, world").role(MessageParam.Role.USER).build() ) - assertThat(body.model()).isEqualTo(Model.CLAUDE_3_7_SONNET_LATEST) + assertThat(body.model()).isEqualTo(Model.CLAUDE_SONNET_4_5_20250929) } } diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/MessageCreateParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/MessageCreateParamsTest.kt index a4281cc75..176bf1409 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/MessageCreateParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/MessageCreateParamsTest.kt @@ -14,7 +14,7 @@ internal class MessageCreateParamsTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata(Metadata.builder().userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b").build()) .serviceTier(MessageCreateParams.ServiceTier.AUTO) .addStopSequence("string") @@ -76,7 +76,7 @@ internal class MessageCreateParamsTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata(Metadata.builder().userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b").build()) .serviceTier(MessageCreateParams.ServiceTier.AUTO) .addStopSequence("string") @@ -138,7 +138,7 @@ internal class MessageCreateParamsTest { .containsExactly( MessageParam.builder().content("Hello, world").role(MessageParam.Role.USER).build() ) - assertThat(body.model()).isEqualTo(Model.CLAUDE_3_7_SONNET_LATEST) + assertThat(body.model()).isEqualTo(Model.CLAUDE_SONNET_4_5_20250929) assertThat(body.metadata()) .contains(Metadata.builder().userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b").build()) assertThat(body.serviceTier()).contains(MessageCreateParams.ServiceTier.AUTO) @@ -214,7 +214,7 @@ internal class MessageCreateParamsTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .build() val body = params._body() @@ -224,6 +224,6 @@ internal class MessageCreateParamsTest { .containsExactly( MessageParam.builder().content("Hello, world").role(MessageParam.Role.USER).build() ) - assertThat(body.model()).isEqualTo(Model.CLAUDE_3_7_SONNET_LATEST) + assertThat(body.model()).isEqualTo(Model.CLAUDE_SONNET_4_5_20250929) } } diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/MessageTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/MessageTest.kt index a85e95d31..ecbb32815 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/MessageTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/MessageTest.kt @@ -29,7 +29,7 @@ internal class MessageTest { .text("Hi! My name is Claude.") .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(StopReason.END_TURN) .stopSequence(null) .usage( @@ -69,7 +69,7 @@ internal class MessageTest { .build() ) ) - assertThat(message.model()).isEqualTo(Model.CLAUDE_3_7_SONNET_LATEST) + assertThat(message.model()).isEqualTo(Model.CLAUDE_SONNET_4_5_20250929) assertThat(message.stopReason()).contains(StopReason.END_TURN) assertThat(message.stopSequence()).isEmpty assertThat(message.usage()) @@ -112,7 +112,7 @@ internal class MessageTest { .text("Hi! My name is Claude.") .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(StopReason.END_TURN) .stopSequence(null) .usage( diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/RawMessageStartEventTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/RawMessageStartEventTest.kt index 9829549cf..7b0ff977c 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/RawMessageStartEventTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/RawMessageStartEventTest.kt @@ -31,7 +31,7 @@ internal class RawMessageStartEventTest { .text("Hi! My name is Claude.") .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(StopReason.END_TURN) .stopSequence(null) .usage( @@ -75,7 +75,7 @@ internal class RawMessageStartEventTest { .text("Hi! My name is Claude.") .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(StopReason.END_TURN) .stopSequence(null) .usage( @@ -121,7 +121,7 @@ internal class RawMessageStartEventTest { .text("Hi! My name is Claude.") .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(StopReason.END_TURN) .stopSequence(null) .usage( diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/RawMessageStreamEventTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/RawMessageStreamEventTest.kt index cb215336f..e3b269a4e 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/RawMessageStreamEventTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/RawMessageStreamEventTest.kt @@ -36,7 +36,7 @@ internal class RawMessageStreamEventTest { .text("Hi! My name is Claude.") .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(StopReason.END_TURN) .stopSequence(null) .usage( @@ -95,7 +95,7 @@ internal class RawMessageStreamEventTest { .text("Hi! My name is Claude.") .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(StopReason.END_TURN) .stopSequence(null) .usage( diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/batches/BatchCreateParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/batches/BatchCreateParamsTest.kt index 50b7e3fbe..db33a622d 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/batches/BatchCreateParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/batches/BatchCreateParamsTest.kt @@ -25,7 +25,7 @@ internal class BatchCreateParamsTest { BatchCreateParams.Request.Params.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder() .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") @@ -109,7 +109,7 @@ internal class BatchCreateParamsTest { BatchCreateParams.Request.Params.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder() .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") @@ -191,7 +191,7 @@ internal class BatchCreateParamsTest { BatchCreateParams.Request.Params.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder() .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") @@ -274,7 +274,7 @@ internal class BatchCreateParamsTest { BatchCreateParams.Request.Params.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .build() ) .build() @@ -291,7 +291,7 @@ internal class BatchCreateParamsTest { BatchCreateParams.Request.Params.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .build() ) .build() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/batches/MessageBatchIndividualResponseTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/batches/MessageBatchIndividualResponseTest.kt index b313c0029..cdfed8c4a 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/batches/MessageBatchIndividualResponseTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/batches/MessageBatchIndividualResponseTest.kt @@ -40,7 +40,7 @@ internal class MessageBatchIndividualResponseTest { .text("Hi! My name is Claude.") .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(StopReason.END_TURN) .stopSequence(null) .usage( @@ -88,7 +88,7 @@ internal class MessageBatchIndividualResponseTest { .text("Hi! My name is Claude.") .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(StopReason.END_TURN) .stopSequence(null) .usage( @@ -140,7 +140,7 @@ internal class MessageBatchIndividualResponseTest { .text("Hi! My name is Claude.") .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(StopReason.END_TURN) .stopSequence(null) .usage( diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/batches/MessageBatchResultTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/batches/MessageBatchResultTest.kt index 1926a9371..e2ca623d6 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/batches/MessageBatchResultTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/batches/MessageBatchResultTest.kt @@ -45,7 +45,7 @@ internal class MessageBatchResultTest { .text("Hi! My name is Claude.") .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(StopReason.END_TURN) .stopSequence(null) .usage( @@ -102,7 +102,7 @@ internal class MessageBatchResultTest { .text("Hi! My name is Claude.") .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(StopReason.END_TURN) .stopSequence(null) .usage( diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/batches/MessageBatchSucceededResultTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/batches/MessageBatchSucceededResultTest.kt index 79c1058ac..1f08ec6f1 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/batches/MessageBatchSucceededResultTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/messages/batches/MessageBatchSucceededResultTest.kt @@ -39,7 +39,7 @@ internal class MessageBatchSucceededResultTest { .text("Hi! My name is Claude.") .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(StopReason.END_TURN) .stopSequence(null) .usage( @@ -83,7 +83,7 @@ internal class MessageBatchSucceededResultTest { .text("Hi! My name is Claude.") .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(StopReason.END_TURN) .stopSequence(null) .usage( @@ -129,7 +129,7 @@ internal class MessageBatchSucceededResultTest { .text("Hi! My name is Claude.") .build() ) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .stopReason(StopReason.END_TURN) .stopSequence(null) .usage( diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/models/ModelListParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/models/ModelListParamsTest.kt index 38767891a..faec90e12 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/models/ModelListParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/models/ModelListParamsTest.kt @@ -16,7 +16,7 @@ internal class ModelListParamsTest { .afterId("after_id") .beforeId("before_id") .limit(1L) - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() } @@ -27,15 +27,12 @@ internal class ModelListParamsTest { .afterId("after_id") .beforeId("before_id") .limit(1L) - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test @@ -54,7 +51,7 @@ internal class ModelListParamsTest { .afterId("after_id") .beforeId("before_id") .limit(1L) - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() val queryParams = params._queryParams() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/models/models/ModelRetrieveParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/models/models/ModelRetrieveParamsTest.kt index 7ab664fd0..bab000c1f 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/models/models/ModelRetrieveParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/models/models/ModelRetrieveParamsTest.kt @@ -13,7 +13,7 @@ internal class ModelRetrieveParamsTest { fun create() { ModelRetrieveParams.builder() .modelId("model_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() } @@ -31,15 +31,12 @@ internal class ModelRetrieveParamsTest { val params = ModelRetrieveParams.builder() .modelId("model_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() val headers = params._headers() - assertThat(headers) - .isEqualTo( - Headers.builder().put("anthropic-beta", "message-batches-2024-09-24").build() - ) + assertThat(headers).isEqualTo(Headers.builder().put("anthropic-beta", "string").build()) } @Test diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/ErrorHandlingTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/ErrorHandlingTest.kt index 8ee5fceef..b21e9eb0e 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/ErrorHandlingTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/ErrorHandlingTest.kt @@ -81,7 +81,7 @@ internal class ErrorHandlingTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder() .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") @@ -169,7 +169,7 @@ internal class ErrorHandlingTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder() .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") @@ -257,7 +257,7 @@ internal class ErrorHandlingTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder() .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") @@ -345,7 +345,7 @@ internal class ErrorHandlingTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder() .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") @@ -433,7 +433,7 @@ internal class ErrorHandlingTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder() .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") @@ -521,7 +521,7 @@ internal class ErrorHandlingTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder() .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") @@ -609,7 +609,7 @@ internal class ErrorHandlingTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder() .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") @@ -697,7 +697,7 @@ internal class ErrorHandlingTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder() .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") @@ -785,7 +785,7 @@ internal class ErrorHandlingTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder() .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") @@ -873,7 +873,7 @@ internal class ErrorHandlingTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder() .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") @@ -961,7 +961,7 @@ internal class ErrorHandlingTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder() .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") @@ -1049,7 +1049,7 @@ internal class ErrorHandlingTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder() .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") @@ -1137,7 +1137,7 @@ internal class ErrorHandlingTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder() .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") @@ -1225,7 +1225,7 @@ internal class ErrorHandlingTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder() .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") @@ -1313,7 +1313,7 @@ internal class ErrorHandlingTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder() .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") @@ -1401,7 +1401,7 @@ internal class ErrorHandlingTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder() .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") @@ -1487,7 +1487,7 @@ internal class ErrorHandlingTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder() .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/ServiceParamsTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/ServiceParamsTest.kt index a3c455958..3e7e08f05 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/ServiceParamsTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/ServiceParamsTest.kt @@ -51,7 +51,7 @@ internal class ServiceParamsTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata(Metadata.builder().userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b").build()) .serviceTier(MessageCreateParams.ServiceTier.AUTO) .addStopSequence("string") diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/CompletionServiceAsyncTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/CompletionServiceAsyncTest.kt index 3a86c2e3a..66ede0d98 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/CompletionServiceAsyncTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/CompletionServiceAsyncTest.kt @@ -26,9 +26,9 @@ internal class CompletionServiceAsyncTest { val completionFuture = completionServiceAsync.create( CompletionCreateParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .maxTokensToSample(256L) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.of("claude-2.1")) .prompt("\n\nHuman: Hello, world!\n\nAssistant:") .metadata( Metadata.builder().userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b").build() @@ -56,9 +56,9 @@ internal class CompletionServiceAsyncTest { val completionStreamResponse = completionServiceAsync.createStreaming( CompletionCreateParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .maxTokensToSample(256L) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.of("claude-2.1")) .prompt("\n\nHuman: Hello, world!\n\nAssistant:") .metadata( Metadata.builder().userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b").build() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/MessageServiceAsyncTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/MessageServiceAsyncTest.kt index 8f8472201..5cc44750e 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/MessageServiceAsyncTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/MessageServiceAsyncTest.kt @@ -34,7 +34,7 @@ internal class MessageServiceAsyncTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder().userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b").build() ) @@ -113,7 +113,7 @@ internal class MessageServiceAsyncTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder().userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b").build() ) @@ -192,7 +192,7 @@ internal class MessageServiceAsyncTest { messageServiceAsync.countTokens( MessageCountTokensParams.builder() .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .systemOfTextBlockParams( listOf( TextBlockParam.builder() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/ModelServiceAsyncTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/ModelServiceAsyncTest.kt index 8bdc1a54f..474e011fb 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/ModelServiceAsyncTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/ModelServiceAsyncTest.kt @@ -25,7 +25,7 @@ internal class ModelServiceAsyncTest { modelServiceAsync.retrieve( ModelRetrieveParams.builder() .modelId("model_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/FileServiceAsyncTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/FileServiceAsyncTest.kt index 976824220..b88f18f9a 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/FileServiceAsyncTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/FileServiceAsyncTest.kt @@ -53,7 +53,7 @@ internal class FileServiceAsyncTest { fileServiceAsync.delete( FileDeleteParams.builder() .fileId("file_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) @@ -75,7 +75,7 @@ internal class FileServiceAsyncTest { fileServiceAsync.download( FileDownloadParams.builder() .fileId("file_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) @@ -96,7 +96,7 @@ internal class FileServiceAsyncTest { fileServiceAsync.retrieveMetadata( FileRetrieveMetadataParams.builder() .fileId("file_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) @@ -116,7 +116,7 @@ internal class FileServiceAsyncTest { val fileMetadataFuture = fileServiceAsync.upload( FileUploadParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .file("some content".byteInputStream()) .build() ) diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/MessageServiceAsyncTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/MessageServiceAsyncTest.kt index 922f06da8..c80b75e58 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/MessageServiceAsyncTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/MessageServiceAsyncTest.kt @@ -14,6 +14,7 @@ import com.anthropic.models.beta.messages.BetaContextManagementConfig import com.anthropic.models.beta.messages.BetaInputTokensClearAtLeast import com.anthropic.models.beta.messages.BetaJsonOutputFormat import com.anthropic.models.beta.messages.BetaMetadata +import com.anthropic.models.beta.messages.BetaOutputConfig import com.anthropic.models.beta.messages.BetaRequestMcpServerToolConfiguration import com.anthropic.models.beta.messages.BetaRequestMcpServerUrlDefinition import com.anthropic.models.beta.messages.BetaSkillParams @@ -44,10 +45,10 @@ internal class MessageServiceAsyncTest { val betaMessageFuture = messageServiceAsync.create( MessageCreateParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .container( BetaContainerParams.builder() .id("id") @@ -93,6 +94,9 @@ internal class MessageServiceAsyncTest { .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") .build() ) + .outputConfig( + BetaOutputConfig.builder().effort(BetaOutputConfig.Effort.LOW).build() + ) .outputFormat( BetaJsonOutputFormat.builder() .schema( @@ -145,12 +149,19 @@ internal class MessageServiceAsyncTest { .build() ) .name("name") + .addAllowedCaller(BetaTool.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .description("Get the current weather in a given location") + .addInputExample( + BetaTool.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .type(BetaTool.Type.CUSTOM) .build() @@ -177,10 +188,10 @@ internal class MessageServiceAsyncTest { val betaMessageStreamResponse = messageServiceAsync.createStreaming( MessageCreateParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .container( BetaContainerParams.builder() .id("id") @@ -226,6 +237,9 @@ internal class MessageServiceAsyncTest { .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") .build() ) + .outputConfig( + BetaOutputConfig.builder().effort(BetaOutputConfig.Effort.LOW).build() + ) .outputFormat( BetaJsonOutputFormat.builder() .schema( @@ -278,12 +292,19 @@ internal class MessageServiceAsyncTest { .build() ) .name("name") + .addAllowedCaller(BetaTool.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .description("Get the current weather in a given location") + .addInputExample( + BetaTool.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .type(BetaTool.Type.CUSTOM) .build() @@ -313,9 +334,9 @@ internal class MessageServiceAsyncTest { val betaMessageTokensCountFuture = messageServiceAsync.countTokens( MessageCountTokensParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .contextManagement( BetaContextManagementConfig.builder() .addEdit( @@ -344,6 +365,9 @@ internal class MessageServiceAsyncTest { ) .build() ) + .outputConfig( + BetaOutputConfig.builder().effort(BetaOutputConfig.Effort.LOW).build() + ) .outputFormat( BetaJsonOutputFormat.builder() .schema( @@ -393,12 +417,19 @@ internal class MessageServiceAsyncTest { .build() ) .name("name") + .addAllowedCaller(BetaTool.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .description("Get the current weather in a given location") + .addInputExample( + BetaTool.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .type(BetaTool.Type.CUSTOM) .build() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/ModelServiceAsyncTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/ModelServiceAsyncTest.kt index 4c710d299..280938c5b 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/ModelServiceAsyncTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/ModelServiceAsyncTest.kt @@ -25,7 +25,7 @@ internal class ModelServiceAsyncTest { modelServiceAsync.retrieve( ModelRetrieveParams.builder() .modelId("model_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/SkillServiceAsyncTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/SkillServiceAsyncTest.kt index c80946a16..fca234f56 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/SkillServiceAsyncTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/SkillServiceAsyncTest.kt @@ -28,7 +28,7 @@ internal class SkillServiceAsyncTest { val skillFuture = skillServiceAsync.create( SkillCreateParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .displayTitle("display_title") .addFile("some content".byteInputStream()) .build() @@ -51,7 +51,7 @@ internal class SkillServiceAsyncTest { skillServiceAsync.retrieve( SkillRetrieveParams.builder() .skillId("skill_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) @@ -87,7 +87,7 @@ internal class SkillServiceAsyncTest { skillServiceAsync.delete( SkillDeleteParams.builder() .skillId("skill_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/messages/BatchServiceAsyncTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/messages/BatchServiceAsyncTest.kt index 920af29c7..e91307f15 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/messages/BatchServiceAsyncTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/messages/BatchServiceAsyncTest.kt @@ -14,6 +14,7 @@ import com.anthropic.models.beta.messages.BetaContextManagementConfig import com.anthropic.models.beta.messages.BetaInputTokensClearAtLeast import com.anthropic.models.beta.messages.BetaJsonOutputFormat import com.anthropic.models.beta.messages.BetaMetadata +import com.anthropic.models.beta.messages.BetaOutputConfig import com.anthropic.models.beta.messages.BetaRequestMcpServerToolConfiguration import com.anthropic.models.beta.messages.BetaRequestMcpServerUrlDefinition import com.anthropic.models.beta.messages.BetaSkillParams @@ -47,7 +48,7 @@ internal class BatchServiceAsyncTest { val betaMessageBatchFuture = batchServiceAsync.create( BatchCreateParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .addRequest( BatchCreateParams.Request.builder() .customId("my-custom-id-1") @@ -55,7 +56,7 @@ internal class BatchServiceAsyncTest { BatchCreateParams.Request.Params.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .container( BetaContainerParams.builder() .id("id") @@ -105,6 +106,11 @@ internal class BatchServiceAsyncTest { .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") .build() ) + .outputConfig( + BetaOutputConfig.builder() + .effort(BetaOutputConfig.Effort.LOW) + .build() + ) .outputFormat( BetaJsonOutputFormat.builder() .schema( @@ -168,14 +174,24 @@ internal class BatchServiceAsyncTest { .build() ) .name("name") + .addAllowedCaller(BetaTool.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .description( "Get the current weather in a given location" ) + .addInputExample( + BetaTool.InputExample.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("bar"), + ) + .build() + ) .strict(true) .type(BetaTool.Type.CUSTOM) .build() @@ -206,7 +222,7 @@ internal class BatchServiceAsyncTest { batchServiceAsync.retrieve( BatchRetrieveParams.builder() .messageBatchId("message_batch_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) @@ -242,7 +258,7 @@ internal class BatchServiceAsyncTest { batchServiceAsync.delete( BatchDeleteParams.builder() .messageBatchId("message_batch_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) @@ -263,7 +279,7 @@ internal class BatchServiceAsyncTest { batchServiceAsync.cancel( BatchCancelParams.builder() .messageBatchId("message_batch_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) @@ -285,7 +301,7 @@ internal class BatchServiceAsyncTest { batchServiceAsync.resultsStreaming( BatchResultsParams.builder() .messageBatchId("message_batch_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/skills/VersionServiceAsyncTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/skills/VersionServiceAsyncTest.kt index 7e55d5180..fd4146df9 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/skills/VersionServiceAsyncTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/beta/skills/VersionServiceAsyncTest.kt @@ -29,7 +29,7 @@ internal class VersionServiceAsyncTest { versionServiceAsync.create( VersionCreateParams.builder() .skillId("skill_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .addFile("some content".byteInputStream()) .build() ) @@ -52,7 +52,7 @@ internal class VersionServiceAsyncTest { VersionRetrieveParams.builder() .skillId("skill_id") .version("version") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) @@ -89,7 +89,7 @@ internal class VersionServiceAsyncTest { VersionDeleteParams.builder() .skillId("skill_id") .version("version") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/messages/BatchServiceAsyncTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/messages/BatchServiceAsyncTest.kt index 10936013b..293b4a769 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/messages/BatchServiceAsyncTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/async/messages/BatchServiceAsyncTest.kt @@ -39,7 +39,7 @@ internal class BatchServiceAsyncTest { BatchCreateParams.Request.Params.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder() .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/CompletionServiceTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/CompletionServiceTest.kt index 9298c6ac5..3726f518d 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/CompletionServiceTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/CompletionServiceTest.kt @@ -26,9 +26,9 @@ internal class CompletionServiceTest { val completion = completionService.create( CompletionCreateParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .maxTokensToSample(256L) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.of("claude-2.1")) .prompt("\n\nHuman: Hello, world!\n\nAssistant:") .metadata( Metadata.builder().userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b").build() @@ -55,9 +55,9 @@ internal class CompletionServiceTest { val completionStreamResponse = completionService.createStreaming( CompletionCreateParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .maxTokensToSample(256L) - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.of("claude-2.1")) .prompt("\n\nHuman: Hello, world!\n\nAssistant:") .metadata( Metadata.builder().userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b").build() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/MessageServiceTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/MessageServiceTest.kt index 089cac255..e3400e8e3 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/MessageServiceTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/MessageServiceTest.kt @@ -34,7 +34,7 @@ internal class MessageServiceTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder().userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b").build() ) @@ -112,7 +112,7 @@ internal class MessageServiceTest { MessageCreateParams.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder().userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b").build() ) @@ -191,7 +191,7 @@ internal class MessageServiceTest { messageService.countTokens( MessageCountTokensParams.builder() .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .systemOfTextBlockParams( listOf( TextBlockParam.builder() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/ModelServiceTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/ModelServiceTest.kt index 9da3e0278..c34718c28 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/ModelServiceTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/ModelServiceTest.kt @@ -25,7 +25,7 @@ internal class ModelServiceTest { modelService.retrieve( ModelRetrieveParams.builder() .modelId("model_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/FileServiceTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/FileServiceTest.kt index 99c9fc21f..b336322f6 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/FileServiceTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/FileServiceTest.kt @@ -52,7 +52,7 @@ internal class FileServiceTest { fileService.delete( FileDeleteParams.builder() .fileId("file_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) @@ -73,7 +73,7 @@ internal class FileServiceTest { fileService.download( FileDownloadParams.builder() .fileId("file_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) @@ -93,7 +93,7 @@ internal class FileServiceTest { fileService.retrieveMetadata( FileRetrieveMetadataParams.builder() .fileId("file_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) @@ -112,7 +112,7 @@ internal class FileServiceTest { val fileMetadata = fileService.upload( FileUploadParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .file("some content".byteInputStream()) .build() ) diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/MessageServiceTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/MessageServiceTest.kt index 09b5af39a..e80a41827 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/MessageServiceTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/MessageServiceTest.kt @@ -14,6 +14,7 @@ import com.anthropic.models.beta.messages.BetaContextManagementConfig import com.anthropic.models.beta.messages.BetaInputTokensClearAtLeast import com.anthropic.models.beta.messages.BetaJsonOutputFormat import com.anthropic.models.beta.messages.BetaMetadata +import com.anthropic.models.beta.messages.BetaOutputConfig import com.anthropic.models.beta.messages.BetaRequestMcpServerToolConfiguration import com.anthropic.models.beta.messages.BetaRequestMcpServerUrlDefinition import com.anthropic.models.beta.messages.BetaSkillParams @@ -44,10 +45,10 @@ internal class MessageServiceTest { val betaMessage = messageService.create( MessageCreateParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .container( BetaContainerParams.builder() .id("id") @@ -93,6 +94,9 @@ internal class MessageServiceTest { .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") .build() ) + .outputConfig( + BetaOutputConfig.builder().effort(BetaOutputConfig.Effort.LOW).build() + ) .outputFormat( BetaJsonOutputFormat.builder() .schema( @@ -145,12 +149,19 @@ internal class MessageServiceTest { .build() ) .name("name") + .addAllowedCaller(BetaTool.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .description("Get the current weather in a given location") + .addInputExample( + BetaTool.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .type(BetaTool.Type.CUSTOM) .build() @@ -176,10 +187,10 @@ internal class MessageServiceTest { val betaMessageStreamResponse = messageService.createStreaming( MessageCreateParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .container( BetaContainerParams.builder() .id("id") @@ -225,6 +236,9 @@ internal class MessageServiceTest { .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") .build() ) + .outputConfig( + BetaOutputConfig.builder().effort(BetaOutputConfig.Effort.LOW).build() + ) .outputFormat( BetaJsonOutputFormat.builder() .schema( @@ -277,12 +291,19 @@ internal class MessageServiceTest { .build() ) .name("name") + .addAllowedCaller(BetaTool.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .description("Get the current weather in a given location") + .addInputExample( + BetaTool.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .type(BetaTool.Type.CUSTOM) .build() @@ -310,9 +331,9 @@ internal class MessageServiceTest { val betaMessageTokensCount = messageService.countTokens( MessageCountTokensParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .contextManagement( BetaContextManagementConfig.builder() .addEdit( @@ -341,6 +362,9 @@ internal class MessageServiceTest { ) .build() ) + .outputConfig( + BetaOutputConfig.builder().effort(BetaOutputConfig.Effort.LOW).build() + ) .outputFormat( BetaJsonOutputFormat.builder() .schema( @@ -390,12 +414,19 @@ internal class MessageServiceTest { .build() ) .name("name") + .addAllowedCaller(BetaTool.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .description("Get the current weather in a given location") + .addInputExample( + BetaTool.InputExample.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) .strict(true) .type(BetaTool.Type.CUSTOM) .build() diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/ModelServiceTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/ModelServiceTest.kt index 3783295e9..d8207fd21 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/ModelServiceTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/ModelServiceTest.kt @@ -25,7 +25,7 @@ internal class ModelServiceTest { modelService.retrieve( ModelRetrieveParams.builder() .modelId("model_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/SkillServiceTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/SkillServiceTest.kt index d4935b7f1..5e6dfa84e 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/SkillServiceTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/SkillServiceTest.kt @@ -28,7 +28,7 @@ internal class SkillServiceTest { val skill = skillService.create( SkillCreateParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .displayTitle("display_title") .addFile("some content".byteInputStream()) .build() @@ -50,7 +50,7 @@ internal class SkillServiceTest { skillService.retrieve( SkillRetrieveParams.builder() .skillId("skill_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) @@ -84,7 +84,7 @@ internal class SkillServiceTest { skillService.delete( SkillDeleteParams.builder() .skillId("skill_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/messages/BatchServiceTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/messages/BatchServiceTest.kt index 30bf342c1..313058626 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/messages/BatchServiceTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/messages/BatchServiceTest.kt @@ -14,6 +14,7 @@ import com.anthropic.models.beta.messages.BetaContextManagementConfig import com.anthropic.models.beta.messages.BetaInputTokensClearAtLeast import com.anthropic.models.beta.messages.BetaJsonOutputFormat import com.anthropic.models.beta.messages.BetaMetadata +import com.anthropic.models.beta.messages.BetaOutputConfig import com.anthropic.models.beta.messages.BetaRequestMcpServerToolConfiguration import com.anthropic.models.beta.messages.BetaRequestMcpServerUrlDefinition import com.anthropic.models.beta.messages.BetaSkillParams @@ -47,7 +48,7 @@ internal class BatchServiceTest { val betaMessageBatch = batchService.create( BatchCreateParams.builder() - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .addRequest( BatchCreateParams.Request.builder() .customId("my-custom-id-1") @@ -55,7 +56,7 @@ internal class BatchServiceTest { BatchCreateParams.Request.Params.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .container( BetaContainerParams.builder() .id("id") @@ -105,6 +106,11 @@ internal class BatchServiceTest { .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") .build() ) + .outputConfig( + BetaOutputConfig.builder() + .effort(BetaOutputConfig.Effort.LOW) + .build() + ) .outputFormat( BetaJsonOutputFormat.builder() .schema( @@ -168,14 +174,24 @@ internal class BatchServiceTest { .build() ) .name("name") + .addAllowedCaller(BetaTool.AllowedCaller.DIRECT) .cacheControl( BetaCacheControlEphemeral.builder() .ttl(BetaCacheControlEphemeral.Ttl.TTL_5M) .build() ) + .deferLoading(true) .description( "Get the current weather in a given location" ) + .addInputExample( + BetaTool.InputExample.builder() + .putAdditionalProperty( + "foo", + JsonValue.from("bar"), + ) + .build() + ) .strict(true) .type(BetaTool.Type.CUSTOM) .build() @@ -205,7 +221,7 @@ internal class BatchServiceTest { batchService.retrieve( BatchRetrieveParams.builder() .messageBatchId("message_batch_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) @@ -239,7 +255,7 @@ internal class BatchServiceTest { batchService.delete( BatchDeleteParams.builder() .messageBatchId("message_batch_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) @@ -259,7 +275,7 @@ internal class BatchServiceTest { batchService.cancel( BatchCancelParams.builder() .messageBatchId("message_batch_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) @@ -280,7 +296,7 @@ internal class BatchServiceTest { batchService.resultsStreaming( BatchResultsParams.builder() .messageBatchId("message_batch_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/skills/VersionServiceTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/skills/VersionServiceTest.kt index d9629497f..b196a7f95 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/skills/VersionServiceTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/beta/skills/VersionServiceTest.kt @@ -29,7 +29,7 @@ internal class VersionServiceTest { versionService.create( VersionCreateParams.builder() .skillId("skill_id") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .addFile("some content".byteInputStream()) .build() ) @@ -51,7 +51,7 @@ internal class VersionServiceTest { VersionRetrieveParams.builder() .skillId("skill_id") .version("version") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) @@ -86,7 +86,7 @@ internal class VersionServiceTest { VersionDeleteParams.builder() .skillId("skill_id") .version("version") - .addBeta(AnthropicBeta.MESSAGE_BATCHES_2024_09_24) + .addBeta(AnthropicBeta.of("string")) .build() ) diff --git a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/messages/BatchServiceTest.kt b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/messages/BatchServiceTest.kt index 9c1a3f361..32fa5e8d6 100644 --- a/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/messages/BatchServiceTest.kt +++ b/anthropic-java-core/src/test/kotlin/com/anthropic/services/blocking/messages/BatchServiceTest.kt @@ -39,7 +39,7 @@ internal class BatchServiceTest { BatchCreateParams.Request.Params.builder() .maxTokens(1024L) .addUserMessage("Hello, world") - .model(Model.CLAUDE_3_7_SONNET_LATEST) + .model(Model.CLAUDE_SONNET_4_5_20250929) .metadata( Metadata.builder() .userId("13803d75-b4b5-4c3e-b2a2-6f21399b021b") diff --git a/build.gradle.kts b/build.gradle.kts index 721ac5d27..c9cd48f7f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ repositories { allprojects { group = "com.anthropic" - version = "2.11.1" // x-release-please-version + version = "2.12.0" // x-release-please-version } subprojects {