diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f8d7296..5f92f36 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,10 +20,10 @@ jobs: if: github.event_name == 'push' || github.event.pull_request.head.repo.fork steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Set up Java - uses: actions/setup-java@v4 + uses: actions/setup-java@v5 with: distribution: temurin java-version: | @@ -40,14 +40,17 @@ jobs: build: timeout-minutes: 15 name: build + permissions: + contents: read + id-token: write runs-on: ${{ github.repository == 'stainless-sdks/alchemyst-ai-sdk-java' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} if: github.event_name == 'push' || github.event.pull_request.head.repo.fork steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Set up Java - uses: actions/setup-java@v4 + uses: actions/setup-java@v5 with: distribution: temurin java-version: | @@ -61,16 +64,31 @@ jobs: - name: Build SDK run: ./scripts/build + - name: Get GitHub OIDC Token + if: github.repository == 'stainless-sdks/alchemyst-ai-sdk-java' + id: github-oidc + uses: actions/github-script@v8 + with: + script: core.setOutput('github_token', await core.getIDToken()); + + - name: Build and upload Maven artifacts + if: github.repository == 'stainless-sdks/alchemyst-ai-sdk-java' + env: + URL: https://pkg.stainless.com/s + AUTH: ${{ steps.github-oidc.outputs.github_token }} + SHA: ${{ github.sha }} + PROJECT: alchemyst-ai-sdk-java + run: ./scripts/upload-artifacts test: timeout-minutes: 15 name: test runs-on: ${{ github.repository == 'stainless-sdks/alchemyst-ai-sdk-java' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }} if: github.event_name == 'push' || github.event.pull_request.head.repo.fork steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Set up Java - uses: actions/setup-java@v4 + uses: actions/setup-java@v5 with: distribution: temurin java-version: | diff --git a/.github/workflows/publish-sonatype.yml b/.github/workflows/publish-sonatype.yml new file mode 100644 index 0000000..6910735 --- /dev/null +++ b/.github/workflows/publish-sonatype.yml @@ -0,0 +1,41 @@ +# This workflow is triggered when a GitHub release is created. +# It can also be run manually to re-publish to Sonatype in case it failed for some reason. +# You can run this workflow by navigating to https://www.github.com/Alchemyst-ai/alchemyst-sdk-java/actions/workflows/publish-sonatype.yml +name: Publish Sonatype +on: + workflow_dispatch: + + release: + types: [published] + +jobs: + publish: + name: publish + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v6 + + - name: Set up Java + uses: actions/setup-java@v5 + with: + distribution: temurin + java-version: | + 8 + 21 + cache: gradle + + - name: Set up Gradle + uses: gradle/gradle-build-action@v2 + + - name: Publish to Sonatype + run: |- + export -- GPG_SIGNING_KEY_ID + printenv -- GPG_SIGNING_KEY | gpg --batch --passphrase-fd 3 --import 3<<< "$GPG_SIGNING_PASSWORD" + GPG_SIGNING_KEY_ID="$(gpg --with-colons --list-keys | awk -F : -- '/^pub:/ { getline; print "0x" substr($10, length($10) - 7) }')" + ./gradlew publish --no-configuration-cache + env: + SONATYPE_USERNAME: ${{ secrets.ALCHEMYST_AI_SONATYPE_USERNAME || secrets.SONATYPE_USERNAME }} + SONATYPE_PASSWORD: ${{ secrets.ALCHEMYST_AI_SONATYPE_PASSWORD || secrets.SONATYPE_PASSWORD }} + GPG_SIGNING_KEY: ${{ secrets.ALCHEMYST_AI_SONATYPE_GPG_SIGNING_KEY || secrets.GPG_SIGNING_KEY }} + GPG_SIGNING_PASSWORD: ${{ secrets.ALCHEMYST_AI_SONATYPE_GPG_SIGNING_PASSWORD || secrets.GPG_SIGNING_PASSWORD }} \ No newline at end of file diff --git a/.github/workflows/release-doctor.yml b/.github/workflows/release-doctor.yml new file mode 100644 index 0000000..47f5f3c --- /dev/null +++ b/.github/workflows/release-doctor.yml @@ -0,0 +1,24 @@ +name: Release Doctor +on: + pull_request: + branches: + - main + workflow_dispatch: + +jobs: + release_doctor: + name: release doctor + runs-on: ubuntu-latest + if: github.repository == 'Alchemyst-ai/alchemyst-sdk-java' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || startsWith(github.head_ref, 'release-please') || github.head_ref == 'next') + + steps: + - uses: actions/checkout@v6 + + - name: Check release environment + run: | + bash ./bin/check-release-environment + env: + SONATYPE_USERNAME: ${{ secrets.ALCHEMYST_AI_SONATYPE_USERNAME || secrets.SONATYPE_USERNAME }} + SONATYPE_PASSWORD: ${{ secrets.ALCHEMYST_AI_SONATYPE_PASSWORD || secrets.SONATYPE_PASSWORD }} + GPG_SIGNING_KEY: ${{ secrets.ALCHEMYST_AI_SONATYPE_GPG_SIGNING_KEY || secrets.GPG_SIGNING_KEY }} + GPG_SIGNING_PASSWORD: ${{ secrets.ALCHEMYST_AI_SONATYPE_GPG_SIGNING_PASSWORD || secrets.GPG_SIGNING_PASSWORD }} diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..3d2ac0b --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "0.1.0" +} \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index 8b380ed..89f72ef 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 11 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/alchemyst-ai%2Falchemyst-ai-sdk-cdd0680c6405277f8a47a7d1dcecc54011da8dd3107e02e4600929db8925e76e.yml -openapi_spec_hash: 2de3999daed6da41616b86f9f1191222 -config_hash: ed5f9a1ea363791f2371dceb218be252 +configured_endpoints: 15 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/alchemyst-ai%2Falchemyst-ai-sdk-2f45ad752bad791b73a3ceab084c0a3482ab2f4557e6a8654f3d9d72d34a1255.yml +openapi_spec_hash: 40c8e2e8d23537e555dc3156e7d14738 +config_hash: 81ab41dc504ce7093b3a81c7e0b5ad9b diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..d4a8403 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,53 @@ +# Changelog + +## 0.1.0 (2026-01-27) + +Full Changelog: [v0.0.1...v0.1.0](https://github.com/Alchemyst-ai/alchemyst-sdk-java/compare/v0.0.1...v0.1.0) + +### Features + +* **api:** api update ([1ed61b3](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/1ed61b348bd13f2bbf7b55a8025d0fbe287c0d1e)) +* **api:** api update ([c9c5eef](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/c9c5eefd474ea10b3e196f46a8e6858c8a8716eb)) +* **api:** api update ([e6fc759](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/e6fc7595eb7aadbb3afa34f71196b7a2832ac6ee)) +* **api:** api update ([ec854a8](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/ec854a81ce517770c35930bc39802154e19162c6)) +* **api:** api update ([7293a27](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/7293a276f3f20bbf86b42cf4287c7e4eeccdd397)) +* **api:** api update ([8a5700f](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/8a5700f17d0dbca67e0402b9e184e7fbd3aeb91b)) +* **api:** api update ([5355b51](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/5355b5185153bf15461b07678947cb58e8d7f463)) +* **api:** api update ([7bc2e75](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/7bc2e759f0c397b776e83177b885eee4519fff18)) +* **api:** api update ([f2d8572](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/f2d85724db9fe8bb7efa02f8e4c009d995d8d2f0)) +* **api:** api update ([1ad2459](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/1ad2459fa314b04066cc9dde8569d093cdc54347)) +* **api:** api update ([f6b4053](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/f6b4053919d2421f1ff12d76da40dd745a299a07)) +* **api:** api update ([332b173](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/332b17339277c00c0ac550850b7a268eea2076d2)) +* **api:** manual updates ([1a5e991](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/1a5e9914379ef3e1af0622f8a7fd0bc0b1dd4998)) +* **api:** manual updates ([db766aa](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/db766aaac68d34cf82348991e2d6a1d2cf43bfb4)) +* **api:** manual updates ([f60ba30](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/f60ba30d54a67f9543a43717a77e4926866bcc23)) +* **api:** manual updates ([0cfdcfa](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/0cfdcfa52cda6728739dbe9ff351ce63402bfc74)) +* **api:** manual updates ([9fea72a](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/9fea72aa08c955c9f039e250d5fc39b85ea541cb)) +* **api:** manual updates ([952235c](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/952235c34ae4a73cf4ed099a1b63f857ebefcd1c)) +* **api:** manual updates ([f76ba28](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/f76ba28f645f040f38306f12be95071c256a2db7)) +* **client:** allow configuring dispatcher executor service ([65bbbb5](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/65bbbb51be67a7ef854674e9ffc2371c6110fd21)) + + +### Bug Fixes + +* **client:** cancel okhttp call when future cancelled ([c73093e](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/c73093e2fffc5392b25a405aced8c308ae54a133)) +* **client:** multi-value header serialization ([9653f0d](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/9653f0db5b98ec857eb6566647ebf9d7cdd7e41c)) + + +### Chores + +* configure new SDK language ([4a05a1a](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/4a05a1a90db6cb8752a0dc67f2fd525475f40cf3)) +* **internal:** codegen related update ([9f9f948](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/9f9f948f5b54a6e83d5c66907e4142e24172f633)) +* **internal:** codegen related update ([fef1b6d](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/fef1b6d56217c58e26efcf354ccfd0b7636a2936)) +* **internal:** codegen related update ([feb242a](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/feb242a1efe3618f84835193af7b48be45f1e774)) +* **internal:** codegen related update ([a2a0c7e](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/a2a0c7ea7fa3674d65f78e2e833195996aaa5d35)) +* **internal:** codegen related update ([a011c38](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/a011c38af4abca2c75d07aeb0db56b76d1398409)) +* **internal:** codegen related update ([8c3c714](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/8c3c71436488deb19eeea9a0d8b9fe2400eae452)) +* **internal:** codegen related update ([079e38c](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/079e38c86b4f66775d59c0dd537d916be1bf0b3b)) +* **internal:** codegen related update ([758020b](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/758020b1f703e97396010ed2aa1bbdbe18522533)) +* update SDK settings ([1c396b2](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/1c396b2879ad0b4c9feab0d8150dcede7d89abb4)) + + +### Documentation + +* remove `$` for better copy-pasteabality ([87f9cc8](https://github.com/Alchemyst-ai/alchemyst-sdk-java/commit/87f9cc8a86baf0b7167064cdd3ae1ae25aa5f809)) diff --git a/LICENSE b/LICENSE index dc34e8e..15b3c0f 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2025 Alchemyst AI + Copyright 2026 Alchemyst AI Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index 3df3d9b..a90ebb8 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,30 @@ # Alchemyst AI Java API Library -[![Maven Central](https://img.shields.io/maven-central/v/com.alchemystai.sdk/alchemyst-ai-java)](https://central.sonatype.com/artifact/com.alchemystai.sdk/alchemyst-ai-java/0.0.1) -[![javadoc](https://javadoc.io/badge2/com.alchemystai.sdk/alchemyst-ai-java/0.0.1/javadoc.svg)](https://javadoc.io/doc/com.alchemystai.sdk/alchemyst-ai-java/0.0.1) + -The Alchemyst AI Java SDK provides convenient access to the [Alchemyst AI REST API](https://docs.getalchemystai.com) from applications written in Java. +[![Maven Central](https://img.shields.io/maven-central/v/com.alchemystai.sdk/alchemyst-ai-java)](https://central.sonatype.com/artifact/com.alchemystai.sdk/alchemyst-ai-java/0.1.0) +[![javadoc](https://javadoc.io/badge2/com.alchemystai.sdk/alchemyst-ai-java/0.1.0/javadoc.svg)](https://javadoc.io/doc/com.alchemystai.sdk/alchemyst-ai-java/0.1.0) + + + +The Alchemyst AI Java SDK provides convenient access to the [Alchemyst AI REST API](https://getalchemystai.com/docs) from applications written in Java. It is generated with [Stainless](https://www.stainless.com/). -The REST API documentation can be found on [docs.getalchemystai.com](https://docs.getalchemystai.com). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.alchemystai.sdk/alchemyst-ai-java/0.0.1). + + +The REST API documentation can be found on [getalchemystai.com](https://getalchemystai.com/docs). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.alchemystai.sdk/alchemyst-ai-java/0.1.0). + + ## Installation + + ### Gradle ```kotlin -implementation("com.alchemystai.sdk:alchemyst-ai-java:0.0.1") +implementation("com.alchemystai.sdk:alchemyst-ai-java:0.1.0") ``` ### Maven @@ -23,10 +33,12 @@ implementation("com.alchemystai.sdk:alchemyst-ai-java:0.0.1") com.alchemystai.sdk alchemyst-ai-java - 0.0.1 + 0.1.0 ``` + + ## Requirements This library requires Java 8 or later. @@ -48,14 +60,14 @@ ContextAddParams params = ContextAddParams.builder() .addDocument(ContextAddParams.Document.builder() .content("The content of the document") .build()) + .scope(ContextAddParams.Scope.INTERNAL) + .source("platform.api.context.add") .metadata(ContextAddParams.Metadata.builder() .fileName("notes.txt") .fileType("text/plain") .lastModified("2025-10-01T18:42:40.419Z") .fileSize(1024.0) .build()) - .scope(ContextAddParams.Scope.INTERNAL) - .source("platform.api.context.add") .build(); ContextAddResponse response = client.v1().context().add(params); ``` @@ -160,14 +172,14 @@ ContextAddParams params = ContextAddParams.builder() .addDocument(ContextAddParams.Document.builder() .content("The content of the document") .build()) + .scope(ContextAddParams.Scope.INTERNAL) + .source("platform.api.context.add") .metadata(ContextAddParams.Metadata.builder() .fileName("notes.txt") .fileType("text/plain") .lastModified("2025-10-01T18:42:40.419Z") .fileSize(1024.0) .build()) - .scope(ContextAddParams.Scope.INTERNAL) - .source("platform.api.context.add") .build(); CompletableFuture response = client.async().v1().context().add(params); ``` @@ -190,14 +202,14 @@ ContextAddParams params = ContextAddParams.builder() .addDocument(ContextAddParams.Document.builder() .content("The content of the document") .build()) + .scope(ContextAddParams.Scope.INTERNAL) + .source("platform.api.context.add") .metadata(ContextAddParams.Metadata.builder() .fileName("notes.txt") .fileType("text/plain") .lastModified("2025-10-01T18:42:40.419Z") .fileSize(1024.0) .build()) - .scope(ContextAddParams.Scope.INTERNAL) - .source("platform.api.context.add") .build(); CompletableFuture response = client.v1().context().add(params); ``` @@ -221,14 +233,14 @@ ContextAddParams params = ContextAddParams.builder() .addDocument(ContextAddParams.Document.builder() .content("The content of the document") .build()) + .scope(ContextAddParams.Scope.INTERNAL) + .source("platform.api.context.add") .metadata(ContextAddParams.Metadata.builder() .fileName("notes.txt") .fileType("text/plain") .lastModified("2025-10-01T18:42:40.419Z") .fileSize(1024.0) .build()) - .scope(ContextAddParams.Scope.INTERNAL) - .source("platform.api.context.add") .build(); HttpResponseFor response = client.v1().context().withRawResponse().add(params); @@ -276,13 +288,13 @@ The SDK uses the standard [OkHttp logging interceptor](https://github.com/square Enable logging by setting the `ALCHEMYST_AI_LOG` environment variable to `info`: ```sh -$ export ALCHEMYST_AI_LOG=info +export ALCHEMYST_AI_LOG=info ``` Or to `debug` for more verbose logging: ```sh -$ export ALCHEMYST_AI_LOG=debug +export ALCHEMYST_AI_LOG=debug ``` ## ProGuard and R8 @@ -302,6 +314,8 @@ If the SDK threw an exception, but you're _certain_ the version is compatible, t > [!CAUTION] > We make no guarantee that the SDK works correctly when the Jackson version check is disabled. +Also note that there are bugs in older Jackson versions that can affect the SDK. We don't work around all Jackson bugs ([example](https://github.com/FasterXML/jackson-databind/issues/3240)) and expect users to upgrade Jackson for those instead. + ## Network options ### Retries @@ -339,7 +353,9 @@ To set a custom timeout, configure the method call using the `timeout` method: ```java import com.alchemystai.sdk.models.v1.context.ContextAddResponse; -ContextAddResponse response = client.v1().context().add(RequestOptions.builder().timeout(Duration.ofSeconds(30)).build()); +ContextAddResponse response = client.v1().context().add( + params, RequestOptions.builder().timeout(Duration.ofSeconds(30)).build() +); ``` Or configure the default for all method calls at the client level: @@ -479,14 +495,14 @@ ContextAddParams params = ContextAddParams.builder() .addDocument(ContextAddParams.Document.builder() .content("The content of the document") .build()) + .scope(ContextAddParams.Scope.INTERNAL) + .source("platform.api.context.add") .metadata(ContextAddParams.Metadata.builder() .fileName("notes.txt") .fileType("text/plain") .lastModified("2025-10-01T18:42:40.419Z") .fileSize(1024.0) .build()) - .scope(ContextAddParams.Scope.INTERNAL) - .source("platform.api.context.add") .build(); ``` @@ -536,12 +552,12 @@ To forcibly omit a required parameter or property, pass [`JsonMissing`](alchemys ```java import com.alchemystai.sdk.core.JsonMissing; import com.alchemystai.sdk.models.v1.context.ContextAddParams; -import com.alchemystai.sdk.models.v1.context.ContextSearchParams; -ContextAddParams params = ContextSearchParams.builder() - .query("search query for user preferences") - .similarityThreshold(0.8) - .minimumSimilarityThreshold(JsonMissing.of()) +ContextAddParams params = ContextAddParams.builder() + .addDocument(ContextAddParams.Document.builder().build()) + .scope(ContextAddParams.Scope.INTERNAL) + .source("support-inbox") + .contextType(JsonMissing.of()) .build(); ``` @@ -553,7 +569,7 @@ To access undocumented response properties, call the `_additionalProperties()` m import com.alchemystai.sdk.core.JsonValue; import java.util.Map; -Map additionalProperties = client.v1().context().search(params)._additionalProperties(); +Map additionalProperties = client.v1().context().add(params)._additionalProperties(); JsonValue secretPropertyValue = additionalProperties.get("secretProperty"); String result = secretPropertyValue.accept(new JsonValue.Visitor<>() { @@ -581,21 +597,22 @@ To access a property's raw JSON value, which may be undocumented, call its `_` p ```java import com.alchemystai.sdk.core.JsonField; +import com.alchemystai.sdk.models.v1.context.ContextAddParams; import java.util.Optional; -JsonField minimumSimilarityThreshold = client.v1().context().search(params)._minimumSimilarityThreshold(); +JsonField contextType = client.v1().context().add(params)._contextType(); -if (minimumSimilarityThreshold.isMissing()) { +if (contextType.isMissing()) { // The property is absent from the JSON response -} else if (minimumSimilarityThreshold.isNull()) { +} else if (contextType.isNull()) { // The property was set to literal null } else { // Check if value was provided as a string // Other methods include `asNumber()`, `asBoolean()`, etc. - Optional jsonString = minimumSimilarityThreshold.asString(); + Optional jsonString = contextType.asString(); // Try to deserialize into a custom type - MyClass myObject = minimumSimilarityThreshold.asUnknown().orElseThrow().convert(MyClass.class); + MyClass myObject = contextType.asUnknown().orElseThrow().convert(MyClass.class); } ``` @@ -608,9 +625,9 @@ By default, the SDK will not throw an exception in this case. It will throw [`Al If you would prefer to check that the response is completely well-typed upfront, then either call `validate()`: ```java -import com.alchemystai.sdk.models.v1.context.ContextSearchResponse; +import com.alchemystai.sdk.models.v1.context.ContextAddResponse; -ContextSearchResponse response = client.v1().context().search(params).validate(); +ContextAddResponse response = client.v1().context().add(params).validate(); ``` Or configure the method call to validate the response using the `responseValidation` method: @@ -618,7 +635,9 @@ Or configure the method call to validate the response using the `responseValidat ```java import com.alchemystai.sdk.models.v1.context.ContextAddResponse; -ContextAddResponse response = client.v1().context().add(RequestOptions.builder().responseValidation(true).build()); +ContextAddResponse response = client.v1().context().add( + params, RequestOptions.builder().responseValidation(true).build() +); ``` Or configure the default for all method calls at the client level: @@ -671,4 +690,4 @@ This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) con We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience. -We are keen for your feedback; please open an [issue](https://www.github.com/stainless-sdks/alchemyst-ai-sdk-java/issues) with questions, bugs, or suggestions. +We are keen for your feedback; please open an [issue](https://www.github.com/Alchemyst-ai/alchemyst-sdk-java/issues) with questions, bugs, or suggestions. diff --git a/alchemyst-ai-java-client-okhttp/build.gradle.kts b/alchemyst-ai-java-client-okhttp/build.gradle.kts index 61d36f6..cb06679 100644 --- a/alchemyst-ai-java-client-okhttp/build.gradle.kts +++ b/alchemyst-ai-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/alchemyst-ai-java-client-okhttp/src/main/kotlin/com/alchemystai/sdk/client/okhttp/AlchemystAiOkHttpClient.kt b/alchemyst-ai-java-client-okhttp/src/main/kotlin/com/alchemystai/sdk/client/okhttp/AlchemystAiOkHttpClient.kt index efb919f..f31b304 100644 --- a/alchemyst-ai-java-client-okhttp/src/main/kotlin/com/alchemystai/sdk/client/okhttp/AlchemystAiOkHttpClient.kt +++ b/alchemyst-ai-java-client-okhttp/src/main/kotlin/com/alchemystai/sdk/client/okhttp/AlchemystAiOkHttpClient.kt @@ -16,6 +16,7 @@ import java.net.Proxy import java.time.Clock import java.time.Duration import java.util.Optional +import java.util.concurrent.ExecutorService import javax.net.ssl.HostnameVerifier import javax.net.ssl.SSLSocketFactory import javax.net.ssl.X509TrustManager @@ -44,11 +45,31 @@ class AlchemystAiOkHttpClient 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 private var hostnameVerifier: HostnameVerifier? = 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)`. */ @@ -299,6 +320,7 @@ class AlchemystAiOkHttpClient private constructor() { OkHttpClient.builder() .timeout(clientOptions.timeout()) .proxy(proxy) + .dispatcherExecutorService(dispatcherExecutorService) .sslSocketFactory(sslSocketFactory) .trustManager(trustManager) .hostnameVerifier(hostnameVerifier) diff --git a/alchemyst-ai-java-client-okhttp/src/main/kotlin/com/alchemystai/sdk/client/okhttp/AlchemystAiOkHttpClientAsync.kt b/alchemyst-ai-java-client-okhttp/src/main/kotlin/com/alchemystai/sdk/client/okhttp/AlchemystAiOkHttpClientAsync.kt index 3eebe95..6d84070 100644 --- a/alchemyst-ai-java-client-okhttp/src/main/kotlin/com/alchemystai/sdk/client/okhttp/AlchemystAiOkHttpClientAsync.kt +++ b/alchemyst-ai-java-client-okhttp/src/main/kotlin/com/alchemystai/sdk/client/okhttp/AlchemystAiOkHttpClientAsync.kt @@ -16,6 +16,7 @@ import java.net.Proxy import java.time.Clock import java.time.Duration import java.util.Optional +import java.util.concurrent.ExecutorService import javax.net.ssl.HostnameVerifier import javax.net.ssl.SSLSocketFactory import javax.net.ssl.X509TrustManager @@ -44,11 +45,31 @@ class AlchemystAiOkHttpClientAsync 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 private var hostnameVerifier: HostnameVerifier? = 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)`. */ @@ -299,6 +320,7 @@ class AlchemystAiOkHttpClientAsync private constructor() { OkHttpClient.builder() .timeout(clientOptions.timeout()) .proxy(proxy) + .dispatcherExecutorService(dispatcherExecutorService) .sslSocketFactory(sslSocketFactory) .trustManager(trustManager) .hostnameVerifier(hostnameVerifier) diff --git a/alchemyst-ai-java-client-okhttp/src/main/kotlin/com/alchemystai/sdk/client/okhttp/OkHttpClient.kt b/alchemyst-ai-java-client-okhttp/src/main/kotlin/com/alchemystai/sdk/client/okhttp/OkHttpClient.kt index 42fdef0..1d6b555 100644 --- a/alchemyst-ai-java-client-okhttp/src/main/kotlin/com/alchemystai/sdk/client/okhttp/OkHttpClient.kt +++ b/alchemyst-ai-java-client-okhttp/src/main/kotlin/com/alchemystai/sdk/client/okhttp/OkHttpClient.kt @@ -13,12 +13,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 @@ -29,8 +32,8 @@ import okhttp3.Response import okhttp3.logging.HttpLoggingInterceptor import okio.BufferedSink -class OkHttpClient private constructor(private val okHttpClient: okhttp3.OkHttpClient) : - HttpClient { +class OkHttpClient +private constructor(@JvmSynthetic internal val okHttpClient: okhttp3.OkHttpClient) : HttpClient { override fun execute(request: HttpRequest, requestOptions: RequestOptions): HttpResponse { val call = newCall(request, requestOptions) @@ -50,20 +53,25 @@ class OkHttpClient private constructor(private val okHttpClient: okhttp3.OkHttpC ): CompletableFuture { val future = CompletableFuture() - request.body?.run { future.whenComplete { _, _ -> close() } } - - newCall(request, requestOptions) - .enqueue( - object : Callback { - override fun onResponse(call: Call, response: Response) { - future.complete(response.toResponse()) - } + val call = newCall(request, requestOptions) + call.enqueue( + object : Callback { + override fun onResponse(call: Call, response: Response) { + future.complete(response.toResponse()) + } - override fun onFailure(call: Call, e: IOException) { - future.completeExceptionally(AlchemystAiIoException("Request failed", e)) - } + override fun onFailure(call: Call, e: IOException) { + future.completeExceptionally(AlchemystAiIoException("Request failed", e)) } - ) + } + ) + + future.whenComplete { _, e -> + if (e is CancellationException) { + call.cancel() + } + request.body?.close() + } return future } @@ -109,19 +117,19 @@ class OkHttpClient private constructor(private val okHttpClient: okhttp3.OkHttpC val builder = Request.Builder().url(toUrl()).method(method.name, body) headers.names().forEach { name -> - headers.values(name).forEach { builder.header(name, it) } + headers.values(name).forEach { builder.addHeader(name, it) } } if ( !headers.names().contains("X-Stainless-Read-Timeout") && client.readTimeoutMillis != 0 ) { - builder.header( + builder.addHeader( "X-Stainless-Read-Timeout", Duration.ofMillis(client.readTimeoutMillis.toLong()).seconds.toString(), ) } if (!headers.names().contains("X-Stainless-Timeout") && client.callTimeoutMillis != 0) { - builder.header( + builder.addHeader( "X-Stainless-Timeout", Duration.ofMillis(client.callTimeoutMillis.toLong()).seconds.toString(), ) @@ -192,6 +200,7 @@ class OkHttpClient private constructor(private val okHttpClient: okhttp3.OkHttpC private var timeout: Timeout = Timeout.default() private var proxy: Proxy? = null + private var dispatcherExecutorService: ExecutorService? = null private var sslSocketFactory: SSLSocketFactory? = null private var trustManager: X509TrustManager? = null private var hostnameVerifier: HostnameVerifier? = null @@ -202,6 +211,10 @@ class OkHttpClient private constructor(private val okHttpClient: okhttp3.OkHttpC fun proxy(proxy: Proxy?) = apply { this.proxy = proxy } + fun dispatcherExecutorService(dispatcherExecutorService: ExecutorService?) = apply { + this.dispatcherExecutorService = dispatcherExecutorService + } + fun sslSocketFactory(sslSocketFactory: SSLSocketFactory?) = apply { this.sslSocketFactory = sslSocketFactory } @@ -217,12 +230,16 @@ class OkHttpClient private constructor(private val okHttpClient: okhttp3.OkHttpC fun build(): OkHttpClient = OkHttpClient( okhttp3.OkHttpClient.Builder() + // `RetryingHttpClient` handles retries if the user enabled them. + .retryOnConnectionFailure(false) .connectTimeout(timeout.connect()) .readTimeout(timeout.read()) .writeTimeout(timeout.write()) .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/alchemyst-ai-java-client-okhttp/src/test/kotlin/com/alchemystai/sdk/client/okhttp/OkHttpClientTest.kt b/alchemyst-ai-java-client-okhttp/src/test/kotlin/com/alchemystai/sdk/client/okhttp/OkHttpClientTest.kt new file mode 100644 index 0000000..41c0808 --- /dev/null +++ b/alchemyst-ai-java-client-okhttp/src/test/kotlin/com/alchemystai/sdk/client/okhttp/OkHttpClientTest.kt @@ -0,0 +1,44 @@ +package com.alchemystai.sdk.client.okhttp + +import com.alchemystai.sdk.core.http.HttpMethod +import com.alchemystai.sdk.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 lateinit var baseUrl: String + private lateinit var httpClient: OkHttpClient + + @BeforeEach + fun beforeEach(wmRuntimeInfo: WireMockRuntimeInfo) { + baseUrl = wmRuntimeInfo.httpBaseUrl + httpClient = OkHttpClient.builder().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/alchemyst-ai-java-core/build.gradle.kts b/alchemyst-ai-java-core/build.gradle.kts index 8b506bc..f8b386b 100644 --- a/alchemyst-ai-java-core/build.gradle.kts +++ b/alchemyst-ai-java-core/build.gradle.kts @@ -5,14 +5,16 @@ plugins { configurations.all { resolutionStrategy { - // Compile and test against a lower Jackson version to ensure we're compatible with it. - // We publish with a higher version (see below) to ensure users depend on a secure version by default. - force("com.fasterxml.jackson.core:jackson-core:2.13.4") - force("com.fasterxml.jackson.core:jackson-databind:2.13.4") - force("com.fasterxml.jackson.core:jackson-annotations:2.13.4") - force("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.13.4") - force("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.4") - force("com.fasterxml.jackson.module:jackson-module-kotlin:2.13.4") + // Compile and test against a lower Jackson version to ensure we're compatible with it. Note that + // we generally support 2.13.4, but test against 2.14.0 because 2.13.4 has some annoying (but + // niche) bugs (users should upgrade if they encounter them). We publish with a higher version + // (see below) to ensure users depend on a secure version by default. + force("com.fasterxml.jackson.core:jackson-core:2.14.0") + force("com.fasterxml.jackson.core:jackson-databind:2.14.0") + force("com.fasterxml.jackson.core:jackson-annotations:2.14.0") + force("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.14.0") + force("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.0") + force("com.fasterxml.jackson.module:jackson-module-kotlin:2.14.0") } } diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/core/Check.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/core/Check.kt index d4478fa..b01d91d 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/core/Check.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/core/Check.kt @@ -77,7 +77,7 @@ This can happen if you are either: Double-check that you are depending on compatible Jackson versions. -See https://www.github.com/stainless-sdks/alchemyst-ai-sdk-java#jackson for more information. +See https://www.github.com/Alchemyst-ai/alchemyst-sdk-java#jackson for more information. """ .trimIndent() } diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/core/ClientOptions.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/core/ClientOptions.kt index 252d193..5a3db81 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/core/ClientOptions.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/core/ClientOptions.kt @@ -402,6 +402,7 @@ private constructor( headers.put("X-Stainless-Package-Version", getPackageVersion()) headers.put("X-Stainless-Runtime", "JRE") headers.put("X-Stainless-Runtime-Version", getJavaVersion()) + headers.put("X-Stainless-Kotlin-Version", KotlinVersion.CURRENT.toString()) apiKey?.let { if (!it.isEmpty()) { headers.put("Authorization", "Bearer $it") diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/core/ObjectMappers.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/core/ObjectMappers.kt index 50ca0d0..fc13ae7 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/core/ObjectMappers.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/core/ObjectMappers.kt @@ -24,7 +24,8 @@ import java.io.InputStream import java.time.DateTimeException import java.time.LocalDate import java.time.LocalDateTime -import java.time.ZonedDateTime +import java.time.OffsetDateTime +import java.time.ZoneId import java.time.format.DateTimeFormatter import java.time.temporal.ChronoField @@ -36,7 +37,7 @@ fun jsonMapper(): JsonMapper = .addModule( SimpleModule() .addSerializer(InputStreamSerializer) - .addDeserializer(LocalDateTime::class.java, LenientLocalDateTimeDeserializer()) + .addDeserializer(OffsetDateTime::class.java, LenientOffsetDateTimeDeserializer()) ) .withCoercionConfig(LogicalType.Boolean) { it.setCoercion(CoercionInputShape.Integer, CoercionAction.Fail) @@ -47,6 +48,7 @@ fun jsonMapper(): JsonMapper = } .withCoercionConfig(LogicalType.Integer) { it.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Float, CoercionAction.Fail) .setCoercion(CoercionInputShape.String, CoercionAction.Fail) .setCoercion(CoercionInputShape.Array, CoercionAction.Fail) .setCoercion(CoercionInputShape.Object, CoercionAction.Fail) @@ -64,6 +66,12 @@ fun jsonMapper(): JsonMapper = .setCoercion(CoercionInputShape.Array, CoercionAction.Fail) .setCoercion(CoercionInputShape.Object, CoercionAction.Fail) } + .withCoercionConfig(LogicalType.DateTime) { + it.setCoercion(CoercionInputShape.Integer, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Float, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Array, CoercionAction.Fail) + .setCoercion(CoercionInputShape.Object, CoercionAction.Fail) + } .withCoercionConfig(LogicalType.Array) { it.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail) .setCoercion(CoercionInputShape.Integer, CoercionAction.Fail) @@ -124,10 +132,10 @@ private object InputStreamSerializer : BaseSerializer(InputStream:: } /** - * A deserializer that can deserialize [LocalDateTime] from datetimes, dates, and zoned datetimes. + * A deserializer that can deserialize [OffsetDateTime] from datetimes, dates, and zoned datetimes. */ -private class LenientLocalDateTimeDeserializer : - StdDeserializer(LocalDateTime::class.java) { +private class LenientOffsetDateTimeDeserializer : + StdDeserializer(OffsetDateTime::class.java) { companion object { @@ -141,7 +149,7 @@ private class LenientLocalDateTimeDeserializer : override fun logicalType(): LogicalType = LogicalType.DateTime - override fun deserialize(p: JsonParser, context: DeserializationContext?): LocalDateTime { + override fun deserialize(p: JsonParser, context: DeserializationContext): OffsetDateTime { val exceptions = mutableListOf() for (formatter in DATE_TIME_FORMATTERS) { @@ -150,17 +158,20 @@ private class LenientLocalDateTimeDeserializer : return when { !temporal.isSupported(ChronoField.HOUR_OF_DAY) -> - LocalDate.from(temporal).atStartOfDay() + LocalDate.from(temporal) + .atStartOfDay() + .atZone(ZoneId.of("UTC")) + .toOffsetDateTime() !temporal.isSupported(ChronoField.OFFSET_SECONDS) -> - LocalDateTime.from(temporal) - else -> ZonedDateTime.from(temporal).toLocalDateTime() + LocalDateTime.from(temporal).atZone(ZoneId.of("UTC")).toOffsetDateTime() + else -> OffsetDateTime.from(temporal) } } catch (e: DateTimeException) { exceptions.add(e) } } - throw JsonParseException(p, "Cannot parse `LocalDateTime` from value: ${p.text}").apply { + throw JsonParseException(p, "Cannot parse `OffsetDateTime` from value: ${p.text}").apply { exceptions.forEach { addSuppressed(it) } } } diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/core/http/HttpRequest.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/core/http/HttpRequest.kt index 04d9342..96b71d6 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/core/http/HttpRequest.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/core/http/HttpRequest.kt @@ -2,6 +2,7 @@ package com.alchemystai.sdk.core.http import com.alchemystai.sdk.core.checkRequired import com.alchemystai.sdk.core.toImmutable +import java.net.URLEncoder class HttpRequest private constructor( @@ -13,6 +14,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/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/core/http/RetryingHttpClient.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/core/http/RetryingHttpClient.kt index 13936be..a9a03cc 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/core/http/RetryingHttpClient.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/core/http/RetryingHttpClient.kt @@ -31,10 +31,6 @@ private constructor( ) : HttpClient { override fun execute(request: HttpRequest, requestOptions: RequestOptions): HttpResponse { - if (!isRetryable(request) || maxRetries <= 0) { - return httpClient.execute(request, requestOptions) - } - var modifiedRequest = maybeAddIdempotencyHeader(request) // Don't send the current retry count in the headers if the caller set their own value. @@ -48,6 +44,10 @@ private constructor( modifiedRequest = setRetryCountHeader(modifiedRequest, retries) } + if (!isRetryable(modifiedRequest)) { + return httpClient.execute(modifiedRequest, requestOptions) + } + val response = try { val response = httpClient.execute(modifiedRequest, requestOptions) @@ -75,10 +75,6 @@ private constructor( request: HttpRequest, requestOptions: RequestOptions, ): CompletableFuture { - if (!isRetryable(request) || maxRetries <= 0) { - return httpClient.executeAsync(request, requestOptions) - } - val modifiedRequest = maybeAddIdempotencyHeader(request) // Don't send the current retry count in the headers if the caller set their own value. @@ -94,8 +90,12 @@ private constructor( val requestWithRetryCount = if (shouldSendRetryCount) setRetryCountHeader(request, retries) else request - return httpClient - .executeAsync(requestWithRetryCount, requestOptions) + val responseFuture = httpClient.executeAsync(requestWithRetryCount, requestOptions) + if (!isRetryable(requestWithRetryCount)) { + return responseFuture + } + + return responseFuture .handleAsync( fun( response: HttpResponse?, diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/ContextAddParams.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/ContextAddParams.kt index f6ab212..aa8092c 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/ContextAddParams.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/ContextAddParams.kt @@ -9,6 +9,7 @@ import com.alchemystai.sdk.core.JsonMissing import com.alchemystai.sdk.core.JsonValue import com.alchemystai.sdk.core.Params import com.alchemystai.sdk.core.checkKnown +import com.alchemystai.sdk.core.checkRequired import com.alchemystai.sdk.core.http.Headers import com.alchemystai.sdk.core.http.QueryParams import com.alchemystai.sdk.core.toImmutable @@ -36,42 +37,42 @@ private constructor( /** * Type of context being added * - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun contextType(): Optional = body.contextType() + fun contextType(): ContextType = body.contextType() /** * Array of documents with content and additional metadata * - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun documents(): Optional> = body.documents() + fun documents(): List = body.documents() /** - * Additional metadata for the context + * Scope of the context * - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun metadata(): Optional = body.metadata() + fun scope(): Scope = body.scope() /** - * Scope of the context + * The source of the context data * - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun scope(): Optional = body.scope() + fun source(): String = body.source() /** - * The source of the context data + * Additional metadata for the context * * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun source(): Optional = body.source() + fun metadata(): Optional = body.metadata() /** * Returns the raw JSON value of [contextType]. @@ -87,13 +88,6 @@ private constructor( */ fun _documents(): JsonField> = body._documents() - /** - * Returns the raw JSON value of [metadata]. - * - * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. - */ - fun _metadata(): JsonField = body._metadata() - /** * Returns the raw JSON value of [scope]. * @@ -108,6 +102,13 @@ private constructor( */ fun _source(): JsonField = body._source() + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _metadata(): JsonField = body._metadata() + fun _additionalBodyProperties(): Map = body._additionalProperties() /** Additional headers to send with the request. */ @@ -120,9 +121,17 @@ private constructor( companion object { - @JvmStatic fun none(): ContextAddParams = builder().build() - - /** Returns a mutable builder for constructing an instance of [ContextAddParams]. */ + /** + * Returns a mutable builder for constructing an instance of [ContextAddParams]. + * + * The following fields are required: + * ```java + * .contextType() + * .documents() + * .scope() + * .source() + * ``` + */ @JvmStatic fun builder() = Builder() } @@ -147,9 +156,9 @@ private constructor( * Otherwise, it's more convenient to use the top-level setters instead: * - [contextType] * - [documents] - * - [metadata] * - [scope] * - [source] + * - [metadata] * - etc. */ fun body(body: Body) = apply { this.body = body.toBuilder() } @@ -187,18 +196,6 @@ private constructor( */ fun addDocument(document: Document) = apply { body.addDocument(document) } - /** Additional metadata for the context */ - fun metadata(metadata: Metadata) = apply { body.metadata(metadata) } - - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. - * This method is primarily for setting the field to an undocumented or not yet supported - * value. - */ - fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } - /** Scope of the context */ fun scope(scope: Scope) = apply { body.scope(scope) } @@ -221,6 +218,18 @@ private constructor( */ fun source(source: JsonField) = apply { body.source(source) } + /** Additional metadata for the context */ + fun metadata(metadata: Metadata) = apply { body.metadata(metadata) } + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { body.additionalProperties(additionalBodyProperties) } @@ -342,6 +351,16 @@ private constructor( * Returns an immutable instance of [ContextAddParams]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .contextType() + * .documents() + * .scope() + * .source() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): ContextAddParams = ContextAddParams(body.build(), additionalHeaders.build(), additionalQueryParams.build()) @@ -358,9 +377,9 @@ private constructor( private constructor( private val contextType: JsonField, private val documents: JsonField>, - private val metadata: JsonField, private val scope: JsonField, private val source: JsonField, + private val metadata: JsonField, private val additionalProperties: MutableMap, ) { @@ -372,52 +391,52 @@ private constructor( @JsonProperty("documents") @ExcludeMissing documents: JsonField> = JsonMissing.of(), + @JsonProperty("scope") @ExcludeMissing scope: JsonField = JsonMissing.of(), + @JsonProperty("source") @ExcludeMissing source: JsonField = JsonMissing.of(), @JsonProperty("metadata") @ExcludeMissing metadata: JsonField = JsonMissing.of(), - @JsonProperty("scope") @ExcludeMissing scope: JsonField = JsonMissing.of(), - @JsonProperty("source") @ExcludeMissing source: JsonField = JsonMissing.of(), - ) : this(contextType, documents, metadata, scope, source, mutableMapOf()) + ) : this(contextType, documents, scope, source, metadata, mutableMapOf()) /** * Type of context being added * - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun contextType(): Optional = contextType.getOptional("context_type") + fun contextType(): ContextType = contextType.getRequired("context_type") /** * Array of documents with content and additional metadata * - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun documents(): Optional> = documents.getOptional("documents") + fun documents(): List = documents.getRequired("documents") /** - * Additional metadata for the context + * Scope of the context * - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun metadata(): Optional = metadata.getOptional("metadata") + fun scope(): Scope = scope.getRequired("scope") /** - * Scope of the context + * The source of the context data * - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun scope(): Optional = scope.getOptional("scope") + fun source(): String = source.getRequired("source") /** - * The source of the context data + * Additional metadata for the context * * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun source(): Optional = source.getOptional("source") + fun metadata(): Optional = metadata.getOptional("metadata") /** * Returns the raw JSON value of [contextType]. @@ -437,13 +456,6 @@ private constructor( @ExcludeMissing fun _documents(): JsonField> = documents - /** - * Returns the raw JSON value of [metadata]. - * - * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata - /** * Returns the raw JSON value of [scope]. * @@ -458,6 +470,13 @@ private constructor( */ @JsonProperty("source") @ExcludeMissing fun _source(): JsonField = source + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -472,27 +491,37 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Body]. */ + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .contextType() + * .documents() + * .scope() + * .source() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Body]. */ class Builder internal constructor() { - private var contextType: JsonField = JsonMissing.of() + private var contextType: JsonField? = null private var documents: JsonField>? = null + private var scope: JsonField? = null + private var source: JsonField? = null private var metadata: JsonField = JsonMissing.of() - private var scope: JsonField = JsonMissing.of() - private var source: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(body: Body) = apply { contextType = body.contextType documents = body.documents.map { it.toMutableList() } - metadata = body.metadata scope = body.scope source = body.source + metadata = body.metadata additionalProperties = body.additionalProperties.toMutableMap() } @@ -536,18 +565,6 @@ private constructor( } } - /** Additional metadata for the context */ - fun metadata(metadata: Metadata) = metadata(JsonField.of(metadata)) - - /** - * Sets [Builder.metadata] to an arbitrary JSON value. - * - * You should usually call [Builder.metadata] with a well-typed [Metadata] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun metadata(metadata: JsonField) = apply { this.metadata = metadata } - /** Scope of the context */ fun scope(scope: Scope) = scope(JsonField.of(scope)) @@ -572,6 +589,18 @@ private constructor( */ fun source(source: JsonField) = apply { this.source = source } + /** Additional metadata for the context */ + fun metadata(metadata: Metadata) = metadata(JsonField.of(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -595,14 +624,24 @@ private constructor( * Returns an immutable instance of [Body]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .contextType() + * .documents() + * .scope() + * .source() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): Body = Body( - contextType, - (documents ?: JsonMissing.of()).map { it.toImmutable() }, + checkRequired("contextType", contextType), + checkRequired("documents", documents).map { it.toImmutable() }, + checkRequired("scope", scope), + checkRequired("source", source), metadata, - scope, - source, additionalProperties.toMutableMap(), ) } @@ -614,11 +653,11 @@ private constructor( return@apply } - contextType().ifPresent { it.validate() } - documents().ifPresent { it.forEach { it.validate() } } - metadata().ifPresent { it.validate() } - scope().ifPresent { it.validate() } + contextType().validate() + documents().forEach { it.validate() } + scope().validate() source() + metadata().ifPresent { it.validate() } validated = true } @@ -640,9 +679,9 @@ private constructor( internal fun validity(): Int = (contextType.asKnown().getOrNull()?.validity() ?: 0) + (documents.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + - (metadata.asKnown().getOrNull()?.validity() ?: 0) + (scope.asKnown().getOrNull()?.validity() ?: 0) + - (if (source.asKnown().isPresent) 1 else 0) + (if (source.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) override fun equals(other: Any?): Boolean { if (this === other) { @@ -652,20 +691,20 @@ private constructor( return other is Body && contextType == other.contextType && documents == other.documents && - metadata == other.metadata && scope == other.scope && source == other.source && + metadata == other.metadata && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(contextType, documents, metadata, scope, source, additionalProperties) + Objects.hash(contextType, documents, scope, source, metadata, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "Body{contextType=$contextType, documents=$documents, metadata=$metadata, scope=$scope, source=$source, additionalProperties=$additionalProperties}" + "Body{contextType=$contextType, documents=$documents, scope=$scope, source=$source, metadata=$metadata, additionalProperties=$additionalProperties}" } /** Type of context being added */ @@ -946,6 +985,134 @@ private constructor( "Document{content=$content, additionalProperties=$additionalProperties}" } + /** Scope of the context */ + class Scope @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 INTERNAL = of("internal") + + @JvmField val EXTERNAL = of("external") + + @JvmStatic fun of(value: String) = Scope(JsonField.of(value)) + } + + /** An enum containing [Scope]'s known values. */ + enum class Known { + INTERNAL, + EXTERNAL, + } + + /** + * An enum containing [Scope]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Scope] 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 { + INTERNAL, + EXTERNAL, + /** An enum member indicating that [Scope] 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) { + INTERNAL -> Value.INTERNAL + EXTERNAL -> Value.EXTERNAL + 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 AlchemystAiInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INTERNAL -> Known.INTERNAL + EXTERNAL -> Known.EXTERNAL + else -> throw AlchemystAiInvalidDataException("Unknown Scope: $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 AlchemystAiInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AlchemystAiInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Scope = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a 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 Scope && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + /** Additional metadata for the context */ class Metadata @JsonCreator(mode = JsonCreator.Mode.DISABLED) @@ -1274,134 +1441,6 @@ private constructor( "Metadata{fileName=$fileName, fileSize=$fileSize, fileType=$fileType, groupName=$groupName, lastModified=$lastModified, additionalProperties=$additionalProperties}" } - /** Scope of the context */ - class Scope @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 INTERNAL = of("internal") - - @JvmField val EXTERNAL = of("external") - - @JvmStatic fun of(value: String) = Scope(JsonField.of(value)) - } - - /** An enum containing [Scope]'s known values. */ - enum class Known { - INTERNAL, - EXTERNAL, - } - - /** - * An enum containing [Scope]'s known values, as well as an [_UNKNOWN] member. - * - * An instance of [Scope] 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 { - INTERNAL, - EXTERNAL, - /** An enum member indicating that [Scope] 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) { - INTERNAL -> Value.INTERNAL - EXTERNAL -> Value.EXTERNAL - 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 AlchemystAiInvalidDataException if this class instance's value is a not a known - * member. - */ - fun known(): Known = - when (this) { - INTERNAL -> Known.INTERNAL - EXTERNAL -> Known.EXTERNAL - else -> throw AlchemystAiInvalidDataException("Unknown Scope: $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 AlchemystAiInvalidDataException if this class instance's value does not have the - * expected primitive type. - */ - fun asString(): String = - _value().asString().orElseThrow { - AlchemystAiInvalidDataException("Value is not a String") - } - - private var validated: Boolean = false - - fun validate(): Scope = apply { - if (validated) { - return@apply - } - - known() - validated = true - } - - fun isValid(): Boolean = - try { - validate() - true - } catch (e: AlchemystAiInvalidDataException) { - false - } - - /** - * Returns a 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 Scope && value == other.value - } - - override fun hashCode() = value.hashCode() - - override fun toString() = value.toString() - } - override fun equals(other: Any?): Boolean { if (this === other) { return true diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/ContextAddResponse.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/ContextAddResponse.kt index 6bc83f7..767b1ad 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/ContextAddResponse.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/ContextAddResponse.kt @@ -3,19 +3,79 @@ package com.alchemystai.sdk.models.v1.context import com.alchemystai.sdk.core.ExcludeMissing +import com.alchemystai.sdk.core.JsonField +import com.alchemystai.sdk.core.JsonMissing import com.alchemystai.sdk.core.JsonValue +import com.alchemystai.sdk.core.checkRequired import com.alchemystai.sdk.errors.AlchemystAiInvalidDataException 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 class ContextAddResponse @JsonCreator(mode = JsonCreator.Mode.DISABLED) -private constructor(private val additionalProperties: MutableMap) { +private constructor( + private val contextId: JsonField, + private val success: JsonField, + private val processedDocuments: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("context_id") @ExcludeMissing contextId: JsonField = JsonMissing.of(), + @JsonProperty("success") @ExcludeMissing success: JsonField = JsonMissing.of(), + @JsonProperty("processed_documents") + @ExcludeMissing + processedDocuments: JsonField = JsonMissing.of(), + ) : this(contextId, success, processedDocuments, mutableMapOf()) - @JsonCreator private constructor() : this(mutableMapOf()) + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun contextId(): String = contextId.getRequired("context_id") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun success(): Boolean = success.getRequired("success") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun processedDocuments(): Optional = + processedDocuments.getOptional("processed_documents") + + /** + * Returns the raw JSON value of [contextId]. + * + * Unlike [contextId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("context_id") @ExcludeMissing fun _contextId(): JsonField = contextId + + /** + * Returns the raw JSON value of [success]. + * + * Unlike [success], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("success") @ExcludeMissing fun _success(): JsonField = success + + /** + * Returns the raw JSON value of [processedDocuments]. + * + * Unlike [processedDocuments], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("processed_documents") + @ExcludeMissing + fun _processedDocuments(): JsonField = processedDocuments @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -31,20 +91,69 @@ private constructor(private val additionalProperties: MutableMap? = null + private var success: JsonField? = null + private var processedDocuments: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(contextAddResponse: ContextAddResponse) = apply { + contextId = contextAddResponse.contextId + success = contextAddResponse.success + processedDocuments = contextAddResponse.processedDocuments additionalProperties = contextAddResponse.additionalProperties.toMutableMap() } + fun contextId(contextId: String) = contextId(JsonField.of(contextId)) + + /** + * Sets [Builder.contextId] to an arbitrary JSON value. + * + * You should usually call [Builder.contextId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun contextId(contextId: JsonField) = apply { this.contextId = contextId } + + fun success(success: Boolean) = success(JsonField.of(success)) + + /** + * Sets [Builder.success] to an arbitrary JSON value. + * + * You should usually call [Builder.success] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun success(success: JsonField) = apply { this.success = success } + + fun processedDocuments(processedDocuments: Double) = + processedDocuments(JsonField.of(processedDocuments)) + + /** + * Sets [Builder.processedDocuments] to an arbitrary JSON value. + * + * You should usually call [Builder.processedDocuments] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun processedDocuments(processedDocuments: JsonField) = apply { + this.processedDocuments = processedDocuments + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -68,8 +177,22 @@ private constructor(private val additionalProperties: MutableMap = body.byId() /** - * Optional organization ID + * Optional user ID * * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun organizationId(): Optional = body.organizationId() + @Deprecated("deprecated") fun userId(): Optional = body.userId() /** - * Source identifier for the context + * Returns the raw JSON value of [organizationId]. * - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected type. */ - fun source(): Optional = body.source() + fun _organizationId(): JsonField = body._organizationId() /** - * Optional user ID + * Returns the raw JSON value of [source]. * - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * Unlike [source], this method doesn't throw if the JSON field has an unexpected type. */ - fun userId(): Optional = body.userId() + fun _source(): JsonField = body._source() /** * Returns the raw JSON value of [byDoc]. @@ -81,26 +99,12 @@ private constructor( */ fun _byId(): JsonField = body._byId() - /** - * Returns the raw JSON value of [organizationId]. - * - * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected type. - */ - fun _organizationId(): JsonField = body._organizationId() - - /** - * Returns the raw JSON value of [source]. - * - * Unlike [source], this method doesn't throw if the JSON field has an unexpected type. - */ - fun _source(): JsonField = body._source() - /** * Returns the raw JSON value of [userId]. * * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. */ - fun _userId(): JsonField = body._userId() + @Deprecated("deprecated") fun _userId(): JsonField = body._userId() fun _additionalBodyProperties(): Map = body._additionalProperties() @@ -114,9 +118,15 @@ private constructor( companion object { - @JvmStatic fun none(): ContextDeleteParams = builder().build() - - /** Returns a mutable builder for constructing an instance of [ContextDeleteParams]. */ + /** + * Returns a mutable builder for constructing an instance of [ContextDeleteParams]. + * + * The following fields are required: + * ```java + * .organizationId() + * .source() + * ``` + */ @JvmStatic fun builder() = Builder() } @@ -139,15 +149,40 @@ private constructor( * * This is generally only useful if you are already constructing the body separately. * Otherwise, it's more convenient to use the top-level setters instead: - * - [byDoc] - * - [byId] * - [organizationId] * - [source] + * - [byDoc] + * - [byId] * - [userId] * - etc. */ fun body(body: Body) = apply { this.body = body.toBuilder() } + /** Organization ID */ + fun organizationId(organizationId: String) = apply { body.organizationId(organizationId) } + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + body.organizationId(organizationId) + } + + /** Source identifier for the context */ + fun source(source: String) = apply { body.source(source) } + + /** + * Sets [Builder.source] to an arbitrary JSON value. + * + * You should usually call [Builder.source] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun source(source: JsonField) = apply { body.source(source) } + /** Flag to delete by document */ fun byDoc(byDoc: Boolean?) = apply { body.byDoc(byDoc) } @@ -190,40 +225,11 @@ private constructor( */ fun byId(byId: JsonField) = apply { body.byId(byId) } - /** Optional organization ID */ - fun organizationId(organizationId: String?) = apply { body.organizationId(organizationId) } - - /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ - fun organizationId(organizationId: Optional) = - organizationId(organizationId.getOrNull()) - - /** - * Sets [Builder.organizationId] to an arbitrary JSON value. - * - * You should usually call [Builder.organizationId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun organizationId(organizationId: JsonField) = apply { - body.organizationId(organizationId) - } - - /** Source identifier for the context */ - fun source(source: String) = apply { body.source(source) } - - /** - * Sets [Builder.source] to an arbitrary JSON value. - * - * You should usually call [Builder.source] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. - */ - fun source(source: JsonField) = apply { body.source(source) } - /** Optional user ID */ - fun userId(userId: String?) = apply { body.userId(userId) } + @Deprecated("deprecated") fun userId(userId: String?) = apply { body.userId(userId) } /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ - fun userId(userId: Optional) = userId(userId.getOrNull()) + @Deprecated("deprecated") fun userId(userId: Optional) = userId(userId.getOrNull()) /** * Sets [Builder.userId] to an arbitrary JSON value. @@ -231,6 +237,7 @@ private constructor( * You should usually call [Builder.userId] with a well-typed [String] value instead. This * method is primarily for setting the field to an undocumented or not yet supported value. */ + @Deprecated("deprecated") fun userId(userId: JsonField) = apply { body.userId(userId) } fun additionalBodyProperties(additionalBodyProperties: Map) = apply { @@ -354,6 +361,14 @@ private constructor( * Returns an immutable instance of [ContextDeleteParams]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .organizationId() + * .source() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): ContextDeleteParams = ContextDeleteParams( @@ -372,56 +387,56 @@ private constructor( class Body @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val byDoc: JsonField, - private val byId: JsonField, private val organizationId: JsonField, private val source: JsonField, + private val byDoc: JsonField, + private val byId: JsonField, private val userId: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("by_doc") @ExcludeMissing byDoc: JsonField = JsonMissing.of(), - @JsonProperty("by_id") @ExcludeMissing byId: JsonField = JsonMissing.of(), @JsonProperty("organization_id") @ExcludeMissing organizationId: JsonField = JsonMissing.of(), @JsonProperty("source") @ExcludeMissing source: JsonField = JsonMissing.of(), + @JsonProperty("by_doc") @ExcludeMissing byDoc: JsonField = JsonMissing.of(), + @JsonProperty("by_id") @ExcludeMissing byId: JsonField = JsonMissing.of(), @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), - ) : this(byDoc, byId, organizationId, source, userId, mutableMapOf()) + ) : this(organizationId, source, byDoc, byId, userId, mutableMapOf()) /** - * Flag to delete by document + * Organization ID * - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun byDoc(): Optional = byDoc.getOptional("by_doc") + fun organizationId(): String = organizationId.getRequired("organization_id") /** - * Flag to delete by ID + * Source identifier for the context * - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun byId(): Optional = byId.getOptional("by_id") + fun source(): String = source.getRequired("source") /** - * Optional organization ID + * Flag to delete by document * * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun organizationId(): Optional = organizationId.getOptional("organization_id") + fun byDoc(): Optional = byDoc.getOptional("by_doc") /** - * Source identifier for the context + * Flag to delete by ID * * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun source(): Optional = source.getOptional("source") + fun byId(): Optional = byId.getOptional("by_id") /** * Optional user ID @@ -429,21 +444,7 @@ private constructor( * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun userId(): Optional = userId.getOptional("user_id") - - /** - * Returns the raw JSON value of [byDoc]. - * - * Unlike [byDoc], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("by_doc") @ExcludeMissing fun _byDoc(): JsonField = byDoc - - /** - * Returns the raw JSON value of [byId]. - * - * Unlike [byId], this method doesn't throw if the JSON field has an unexpected type. - */ - @JsonProperty("by_id") @ExcludeMissing fun _byId(): JsonField = byId + @Deprecated("deprecated") fun userId(): Optional = userId.getOptional("user_id") /** * Returns the raw JSON value of [organizationId]. @@ -462,12 +463,29 @@ private constructor( */ @JsonProperty("source") @ExcludeMissing fun _source(): JsonField = source + /** + * Returns the raw JSON value of [byDoc]. + * + * Unlike [byDoc], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("by_doc") @ExcludeMissing fun _byDoc(): JsonField = byDoc + + /** + * Returns the raw JSON value of [byId]. + * + * Unlike [byId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("by_id") @ExcludeMissing fun _byId(): JsonField = byId + /** * Returns the raw JSON value of [userId]. * * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + @Deprecated("deprecated") + @JsonProperty("user_id") + @ExcludeMissing + fun _userId(): JsonField = userId @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -483,30 +501,65 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Body]. */ + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .organizationId() + * .source() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Body]. */ class Builder internal constructor() { + private var organizationId: JsonField? = null + private var source: JsonField? = null private var byDoc: JsonField = JsonMissing.of() private var byId: JsonField = JsonMissing.of() - private var organizationId: JsonField = JsonMissing.of() - private var source: JsonField = JsonMissing.of() private var userId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(body: Body) = apply { - byDoc = body.byDoc - byId = body.byId organizationId = body.organizationId source = body.source + byDoc = body.byDoc + byId = body.byId userId = body.userId additionalProperties = body.additionalProperties.toMutableMap() } + /** Organization ID */ + fun organizationId(organizationId: String) = + organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + + /** Source identifier for the context */ + fun source(source: String) = source(JsonField.of(source)) + + /** + * Sets [Builder.source] to an arbitrary JSON value. + * + * You should usually call [Builder.source] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun source(source: JsonField) = apply { this.source = source } + /** Flag to delete by document */ fun byDoc(byDoc: Boolean?) = byDoc(JsonField.ofNullable(byDoc)) @@ -551,41 +604,12 @@ private constructor( */ fun byId(byId: JsonField) = apply { this.byId = byId } - /** Optional organization ID */ - fun organizationId(organizationId: String?) = - organizationId(JsonField.ofNullable(organizationId)) - - /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ - fun organizationId(organizationId: Optional) = - organizationId(organizationId.getOrNull()) - - /** - * Sets [Builder.organizationId] to an arbitrary JSON value. - * - * You should usually call [Builder.organizationId] with a well-typed [String] value - * instead. This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun organizationId(organizationId: JsonField) = apply { - this.organizationId = organizationId - } - - /** Source identifier for the context */ - fun source(source: String) = source(JsonField.of(source)) - - /** - * Sets [Builder.source] to an arbitrary JSON value. - * - * You should usually call [Builder.source] with a well-typed [String] value instead. - * This method is primarily for setting the field to an undocumented or not yet - * supported value. - */ - fun source(source: JsonField) = apply { this.source = source } - /** Optional user ID */ + @Deprecated("deprecated") fun userId(userId: String?) = userId(JsonField.ofNullable(userId)) /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ + @Deprecated("deprecated") fun userId(userId: Optional) = userId(userId.getOrNull()) /** @@ -595,6 +619,7 @@ private constructor( * This method is primarily for setting the field to an undocumented or not yet * supported value. */ + @Deprecated("deprecated") fun userId(userId: JsonField) = apply { this.userId = userId } fun additionalProperties(additionalProperties: Map) = apply { @@ -620,13 +645,21 @@ private constructor( * Returns an immutable instance of [Body]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .organizationId() + * .source() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): Body = Body( + checkRequired("organizationId", organizationId), + checkRequired("source", source), byDoc, byId, - organizationId, - source, userId, additionalProperties.toMutableMap(), ) @@ -639,10 +672,10 @@ private constructor( return@apply } - byDoc() - byId() organizationId() source() + byDoc() + byId() userId() validated = true } @@ -663,10 +696,10 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (if (byDoc.asKnown().isPresent) 1 else 0) + - (if (byId.asKnown().isPresent) 1 else 0) + - (if (organizationId.asKnown().isPresent) 1 else 0) + + (if (organizationId.asKnown().isPresent) 1 else 0) + (if (source.asKnown().isPresent) 1 else 0) + + (if (byDoc.asKnown().isPresent) 1 else 0) + + (if (byId.asKnown().isPresent) 1 else 0) + (if (userId.asKnown().isPresent) 1 else 0) override fun equals(other: Any?): Boolean { @@ -675,22 +708,22 @@ private constructor( } return other is Body && - byDoc == other.byDoc && - byId == other.byId && organizationId == other.organizationId && source == other.source && + byDoc == other.byDoc && + byId == other.byId && userId == other.userId && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(byDoc, byId, organizationId, source, userId, additionalProperties) + Objects.hash(organizationId, source, byDoc, byId, userId, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "Body{byDoc=$byDoc, byId=$byId, organizationId=$organizationId, source=$source, userId=$userId, additionalProperties=$additionalProperties}" + "Body{organizationId=$organizationId, source=$source, byDoc=$byDoc, byId=$byId, userId=$userId, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/ContextSearchParams.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/ContextSearchParams.kt index 3f885bf..8e57434 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/ContextSearchParams.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/ContextSearchParams.kt @@ -27,11 +27,28 @@ import kotlin.jvm.optionals.getOrNull */ class ContextSearchParams private constructor( + private val metadata: Metadata?, + private val mode: Mode?, private val body: Body, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { + /** + * Controls whether metadata is included in the response: + * - metadata=true → metadata will be included in each context item in the response. + * - metadata=false (or omitted) → metadata will be excluded from the response for better + * performance. + */ + fun metadata(): Optional = Optional.ofNullable(metadata) + + /** + * Controls the search mode: + * - mode=fast → prioritizes speed over completeness. + * - mode=standard → performs a comprehensive search (default if omitted). + */ + fun mode(): Optional = Optional.ofNullable(mode) + /** * Minimum similarity threshold * @@ -56,8 +73,15 @@ private constructor( */ fun similarityThreshold(): Double = body.similarityThreshold() - /** Additional metadata for the search */ - fun _metadata(): JsonValue = body._metadata() + /** + * Additional metadata for the search + * + * This arbitrary value can be deserialized into a custom type using the `convert` method: + * ```java + * MyClass myObject = contextSearchParams.bodyMetadata().convert(MyClass.class); + * ``` + */ + fun _bodyMetadata(): JsonValue = body._bodyMetadata() /** * Search scope @@ -73,7 +97,7 @@ private constructor( * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun userId(): Optional = body.userId() + @Deprecated("deprecated") fun userId(): Optional = body.userId() /** * Returns the raw JSON value of [minimumSimilarityThreshold]. @@ -110,7 +134,7 @@ private constructor( * * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. */ - fun _userId(): JsonField = body._userId() + @Deprecated("deprecated") fun _userId(): JsonField = body._userId() fun _additionalBodyProperties(): Map = body._additionalProperties() @@ -140,17 +164,42 @@ private constructor( /** A builder for [ContextSearchParams]. */ class Builder internal constructor() { + private var metadata: Metadata? = null + private var mode: Mode? = null private var body: Body.Builder = Body.builder() private var additionalHeaders: Headers.Builder = Headers.builder() private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(contextSearchParams: ContextSearchParams) = apply { + metadata = contextSearchParams.metadata + mode = contextSearchParams.mode body = contextSearchParams.body.toBuilder() additionalHeaders = contextSearchParams.additionalHeaders.toBuilder() additionalQueryParams = contextSearchParams.additionalQueryParams.toBuilder() } + /** + * Controls whether metadata is included in the response: + * - metadata=true → metadata will be included in each context item in the response. + * - metadata=false (or omitted) → metadata will be excluded from the response for better + * performance. + */ + fun metadata(metadata: Metadata?) = apply { this.metadata = metadata } + + /** Alias for calling [Builder.metadata] with `metadata.orElse(null)`. */ + fun metadata(metadata: Optional) = metadata(metadata.getOrNull()) + + /** + * Controls the search mode: + * - mode=fast → prioritizes speed over completeness. + * - mode=standard → performs a comprehensive search (default if omitted). + */ + fun mode(mode: Mode?) = apply { this.mode = mode } + + /** Alias for calling [Builder.mode] with `mode.orElse(null)`. */ + fun mode(mode: Optional) = mode(mode.getOrNull()) + /** * Sets the entire request body. * @@ -159,7 +208,7 @@ private constructor( * - [minimumSimilarityThreshold] * - [query] * - [similarityThreshold] - * - [metadata] + * - [bodyMetadata] * - [scope] * - etc. */ @@ -209,7 +258,7 @@ private constructor( } /** Additional metadata for the search */ - fun metadata(metadata: JsonValue) = apply { body.metadata(metadata) } + fun bodyMetadata(bodyMetadata: JsonValue) = apply { body.bodyMetadata(bodyMetadata) } /** Search scope */ fun scope(scope: Scope) = apply { body.scope(scope) } @@ -223,7 +272,7 @@ private constructor( fun scope(scope: JsonField) = apply { body.scope(scope) } /** The ID of the user making the request */ - fun userId(userId: String) = apply { body.userId(userId) } + @Deprecated("deprecated") fun userId(userId: String) = apply { body.userId(userId) } /** * Sets [Builder.userId] to an arbitrary JSON value. @@ -231,6 +280,7 @@ private constructor( * You should usually call [Builder.userId] with a well-typed [String] value instead. This * method is primarily for setting the field to an undocumented or not yet supported value. */ + @Deprecated("deprecated") fun userId(userId: JsonField) = apply { body.userId(userId) } fun additionalBodyProperties(additionalBodyProperties: Map) = apply { @@ -366,6 +416,8 @@ private constructor( */ fun build(): ContextSearchParams = ContextSearchParams( + metadata, + mode, body.build(), additionalHeaders.build(), additionalQueryParams.build(), @@ -376,7 +428,14 @@ private constructor( override fun _headers(): Headers = additionalHeaders - override fun _queryParams(): QueryParams = additionalQueryParams + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + metadata?.let { put("metadata", it.toString()) } + mode?.let { put("mode", it.toString()) } + putAll(additionalQueryParams) + } + .build() class Body @JsonCreator(mode = JsonCreator.Mode.DISABLED) @@ -384,7 +443,7 @@ private constructor( private val minimumSimilarityThreshold: JsonField, private val query: JsonField, private val similarityThreshold: JsonField, - private val metadata: JsonValue, + private val bodyMetadata: JsonValue, private val scope: JsonField, private val userId: JsonField, private val additionalProperties: MutableMap, @@ -399,14 +458,16 @@ private constructor( @JsonProperty("similarity_threshold") @ExcludeMissing similarityThreshold: JsonField = JsonMissing.of(), - @JsonProperty("metadata") @ExcludeMissing metadata: JsonValue = JsonMissing.of(), + @JsonProperty("body_metadata") + @ExcludeMissing + bodyMetadata: JsonValue = JsonMissing.of(), @JsonProperty("scope") @ExcludeMissing scope: JsonField = JsonMissing.of(), @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), ) : this( minimumSimilarityThreshold, query, similarityThreshold, - metadata, + bodyMetadata, scope, userId, mutableMapOf(), @@ -437,8 +498,15 @@ private constructor( */ fun similarityThreshold(): Double = similarityThreshold.getRequired("similarity_threshold") - /** Additional metadata for the search */ - @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonValue = metadata + /** + * Additional metadata for the search + * + * This arbitrary value can be deserialized into a custom type using the `convert` method: + * ```java + * MyClass myObject = body.bodyMetadata().convert(MyClass.class); + * ``` + */ + @JsonProperty("body_metadata") @ExcludeMissing fun _bodyMetadata(): JsonValue = bodyMetadata /** * Search scope @@ -454,7 +522,7 @@ private constructor( * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun userId(): Optional = userId.getOptional("user_id") + @Deprecated("deprecated") fun userId(): Optional = userId.getOptional("user_id") /** * Returns the raw JSON value of [minimumSimilarityThreshold]. @@ -495,7 +563,10 @@ private constructor( * * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + @Deprecated("deprecated") + @JsonProperty("user_id") + @ExcludeMissing + fun _userId(): JsonField = userId @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -530,7 +601,7 @@ private constructor( private var minimumSimilarityThreshold: JsonField? = null private var query: JsonField? = null private var similarityThreshold: JsonField? = null - private var metadata: JsonValue = JsonMissing.of() + private var bodyMetadata: JsonValue = JsonMissing.of() private var scope: JsonField = JsonMissing.of() private var userId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -540,7 +611,7 @@ private constructor( minimumSimilarityThreshold = body.minimumSimilarityThreshold query = body.query similarityThreshold = body.similarityThreshold - metadata = body.metadata + bodyMetadata = body.bodyMetadata scope = body.scope userId = body.userId additionalProperties = body.additionalProperties.toMutableMap() @@ -589,7 +660,7 @@ private constructor( } /** Additional metadata for the search */ - fun metadata(metadata: JsonValue) = apply { this.metadata = metadata } + fun bodyMetadata(bodyMetadata: JsonValue) = apply { this.bodyMetadata = bodyMetadata } /** Search scope */ fun scope(scope: Scope) = scope(JsonField.of(scope)) @@ -604,7 +675,7 @@ private constructor( fun scope(scope: JsonField) = apply { this.scope = scope } /** The ID of the user making the request */ - fun userId(userId: String) = userId(JsonField.of(userId)) + @Deprecated("deprecated") fun userId(userId: String) = userId(JsonField.of(userId)) /** * Sets [Builder.userId] to an arbitrary JSON value. @@ -613,6 +684,7 @@ private constructor( * This method is primarily for setting the field to an undocumented or not yet * supported value. */ + @Deprecated("deprecated") fun userId(userId: JsonField) = apply { this.userId = userId } fun additionalProperties(additionalProperties: Map) = apply { @@ -653,7 +725,7 @@ private constructor( checkRequired("minimumSimilarityThreshold", minimumSimilarityThreshold), checkRequired("query", query), checkRequired("similarityThreshold", similarityThreshold), - metadata, + bodyMetadata, scope, userId, additionalProperties.toMutableMap(), @@ -706,7 +778,7 @@ private constructor( minimumSimilarityThreshold == other.minimumSimilarityThreshold && query == other.query && similarityThreshold == other.similarityThreshold && - metadata == other.metadata && + bodyMetadata == other.bodyMetadata && scope == other.scope && userId == other.userId && additionalProperties == other.additionalProperties @@ -717,7 +789,7 @@ private constructor( minimumSimilarityThreshold, query, similarityThreshold, - metadata, + bodyMetadata, scope, userId, additionalProperties, @@ -727,7 +799,7 @@ private constructor( override fun hashCode(): Int = hashCode override fun toString() = - "Body{minimumSimilarityThreshold=$minimumSimilarityThreshold, query=$query, similarityThreshold=$similarityThreshold, metadata=$metadata, scope=$scope, userId=$userId, additionalProperties=$additionalProperties}" + "Body{minimumSimilarityThreshold=$minimumSimilarityThreshold, query=$query, similarityThreshold=$similarityThreshold, bodyMetadata=$bodyMetadata, scope=$scope, userId=$userId, additionalProperties=$additionalProperties}" } /** Search scope */ @@ -858,19 +930,287 @@ private constructor( override fun toString() = value.toString() } + /** + * Controls whether metadata is included in the response: + * - metadata=true → metadata will be included in each context item in the response. + * - metadata=false (or omitted) → metadata will be excluded from the response for better + * performance. + */ + class Metadata @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 TRUE = of("true") + + @JvmField val FALSE = of("false") + + @JvmStatic fun of(value: String) = Metadata(JsonField.of(value)) + } + + /** An enum containing [Metadata]'s known values. */ + enum class Known { + TRUE, + FALSE, + } + + /** + * An enum containing [Metadata]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Metadata] 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 { + TRUE, + FALSE, + /** An enum member indicating that [Metadata] 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) { + TRUE -> Value.TRUE + FALSE -> Value.FALSE + 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 AlchemystAiInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + TRUE -> Known.TRUE + FALSE -> Known.FALSE + else -> throw AlchemystAiInvalidDataException("Unknown Metadata: $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 AlchemystAiInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AlchemystAiInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a 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 Metadata && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** + * Controls the search mode: + * - mode=fast → prioritizes speed over completeness. + * - mode=standard → performs a comprehensive search (default if omitted). + */ + class Mode @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val FAST = of("fast") + + @JvmField val STANDARD = of("standard") + + @JvmStatic fun of(value: String) = Mode(JsonField.of(value)) + } + + /** An enum containing [Mode]'s known values. */ + enum class Known { + FAST, + STANDARD, + } + + /** + * An enum containing [Mode]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Mode] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + FAST, + STANDARD, + /** An enum member indicating that [Mode] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + FAST -> Value.FAST + STANDARD -> Value.STANDARD + 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 AlchemystAiInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + FAST -> Known.FAST + STANDARD -> Known.STANDARD + else -> throw AlchemystAiInvalidDataException("Unknown Mode: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws AlchemystAiInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AlchemystAiInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Mode = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Mode && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + override fun equals(other: Any?): Boolean { if (this === other) { return true } return other is ContextSearchParams && + metadata == other.metadata && + mode == other.mode && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) + override fun hashCode(): Int = + Objects.hash(metadata, mode, body, additionalHeaders, additionalQueryParams) override fun toString() = - "ContextSearchParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" + "ContextSearchParams{metadata=$metadata, mode=$mode, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/ContextSearchResponse.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/ContextSearchResponse.kt index f44c895..f502ff2 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/ContextSearchResponse.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/ContextSearchResponse.kt @@ -196,6 +196,14 @@ private constructor( */ fun createdAt(): Optional = createdAt.getOptional("createdAt") + /** + * Only included when query parameter metadata=true + * + * This arbitrary value can be deserialized into a custom type using the `convert` method: + * ```java + * MyClass myObject = context.metadata().convert(MyClass.class); + * ``` + */ @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonValue = metadata /** @@ -304,6 +312,7 @@ private constructor( this.createdAt = createdAt } + /** Only included when query parameter metadata=true */ fun metadata(metadata: JsonValue) = apply { this.metadata = metadata } fun score(score: Double) = score(JsonField.of(score)) diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/addasync/AddAsyncCancelParams.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/addasync/AddAsyncCancelParams.kt new file mode 100644 index 0000000..b6b5034 --- /dev/null +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/addasync/AddAsyncCancelParams.kt @@ -0,0 +1,234 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.models.v1.context.addasync + +import com.alchemystai.sdk.core.JsonValue +import com.alchemystai.sdk.core.Params +import com.alchemystai.sdk.core.http.Headers +import com.alchemystai.sdk.core.http.QueryParams +import com.alchemystai.sdk.core.toImmutable +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Attempts to cancel a context add job by job id. + * - If the job is already completed or failed, returns 404. + * - If the job is currently running ("active"), returns 409 and cannot be cancelled. + * - Only jobs in "waiting" or "delayed" state can be cancelled. + */ +class AddAsyncCancelParams +private constructor( + private val id: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun id(): Optional = Optional.ofNullable(id) + + /** Additional body properties to send with the request. */ + fun _additionalBodyProperties(): Map = additionalBodyProperties + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): AddAsyncCancelParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [AddAsyncCancelParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AddAsyncCancelParams]. */ + class Builder internal constructor() { + + private var id: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(addAsyncCancelParams: AddAsyncCancelParams) = apply { + id = addAsyncCancelParams.id + additionalHeaders = addAsyncCancelParams.additionalHeaders.toBuilder() + additionalQueryParams = addAsyncCancelParams.additionalQueryParams.toBuilder() + additionalBodyProperties = addAsyncCancelParams.additionalBodyProperties.toMutableMap() + } + + fun id(id: String?) = apply { this.id = id } + + /** Alias for calling [Builder.id] with `id.orElse(null)`. */ + fun id(id: Optional) = id(id.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + this.additionalBodyProperties.clear() + putAllAdditionalBodyProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + additionalBodyProperties.put(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + + /** + * Returns an immutable instance of [AddAsyncCancelParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): AddAsyncCancelParams = + AddAsyncCancelParams( + id, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> id ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AddAsyncCancelParams && + id == other.id && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash(id, additionalHeaders, additionalQueryParams, additionalBodyProperties) + + override fun toString() = + "AddAsyncCancelParams{id=$id, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/addasync/AddAsyncCancelResponse.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/addasync/AddAsyncCancelResponse.kt new file mode 100644 index 0000000..e44fa1c --- /dev/null +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/addasync/AddAsyncCancelResponse.kt @@ -0,0 +1,273 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.models.v1.context.addasync + +import com.alchemystai.sdk.core.ExcludeMissing +import com.alchemystai.sdk.core.JsonField +import com.alchemystai.sdk.core.JsonMissing +import com.alchemystai.sdk.core.JsonValue +import com.alchemystai.sdk.core.checkRequired +import com.alchemystai.sdk.errors.AlchemystAiInvalidDataException +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 AddAsyncCancelResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val jobId: JsonField, + private val message: JsonField, + private val status: JsonField, + private val success: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("jobId") @ExcludeMissing jobId: JsonField = JsonMissing.of(), + @JsonProperty("message") @ExcludeMissing message: JsonField = JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("success") @ExcludeMissing success: JsonField = JsonMissing.of(), + ) : this(jobId, message, status, success, mutableMapOf()) + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun jobId(): String = jobId.getRequired("jobId") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun message(): String = message.getRequired("message") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun status(): String = status.getRequired("status") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun success(): Boolean = success.getRequired("success") + + /** + * Returns the raw JSON value of [jobId]. + * + * Unlike [jobId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("jobId") @ExcludeMissing fun _jobId(): JsonField = jobId + + /** + * Returns the raw JSON value of [message]. + * + * Unlike [message], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("message") @ExcludeMissing fun _message(): JsonField = message + + /** + * Returns the raw JSON value of [status]. + * + * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + /** + * Returns the raw JSON value of [success]. + * + * Unlike [success], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("success") @ExcludeMissing fun _success(): JsonField = success + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [AddAsyncCancelResponse]. + * + * The following fields are required: + * ```java + * .jobId() + * .message() + * .status() + * .success() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AddAsyncCancelResponse]. */ + class Builder internal constructor() { + + private var jobId: JsonField? = null + private var message: JsonField? = null + private var status: JsonField? = null + private var success: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(addAsyncCancelResponse: AddAsyncCancelResponse) = apply { + jobId = addAsyncCancelResponse.jobId + message = addAsyncCancelResponse.message + status = addAsyncCancelResponse.status + success = addAsyncCancelResponse.success + additionalProperties = addAsyncCancelResponse.additionalProperties.toMutableMap() + } + + fun jobId(jobId: String) = jobId(JsonField.of(jobId)) + + /** + * Sets [Builder.jobId] to an arbitrary JSON value. + * + * You should usually call [Builder.jobId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun jobId(jobId: JsonField) = apply { this.jobId = jobId } + + fun message(message: String) = message(JsonField.of(message)) + + /** + * Sets [Builder.message] to an arbitrary JSON value. + * + * You should usually call [Builder.message] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun message(message: JsonField) = apply { this.message = message } + + fun status(status: String) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun status(status: JsonField) = apply { this.status = status } + + fun success(success: Boolean) = success(JsonField.of(success)) + + /** + * Sets [Builder.success] to an arbitrary JSON value. + * + * You should usually call [Builder.success] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun success(success: JsonField) = apply { this.success = success } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [AddAsyncCancelResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .jobId() + * .message() + * .status() + * .success() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AddAsyncCancelResponse = + AddAsyncCancelResponse( + checkRequired("jobId", jobId), + checkRequired("message", message), + checkRequired("status", status), + checkRequired("success", success), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): AddAsyncCancelResponse = apply { + if (validated) { + return@apply + } + + jobId() + message() + status() + success() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (jobId.asKnown().isPresent) 1 else 0) + + (if (message.asKnown().isPresent) 1 else 0) + + (if (status.asKnown().isPresent) 1 else 0) + + (if (success.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AddAsyncCancelResponse && + jobId == other.jobId && + message == other.message && + status == other.status && + success == other.success && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(jobId, message, status, success, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AddAsyncCancelResponse{jobId=$jobId, message=$message, status=$status, success=$success, additionalProperties=$additionalProperties}" +} diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/addasync/AddAsyncCreateParams.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/addasync/AddAsyncCreateParams.kt new file mode 100644 index 0000000..ff6d71c --- /dev/null +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/addasync/AddAsyncCreateParams.kt @@ -0,0 +1,1463 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.models.v1.context.addasync + +import com.alchemystai.sdk.core.Enum +import com.alchemystai.sdk.core.ExcludeMissing +import com.alchemystai.sdk.core.JsonField +import com.alchemystai.sdk.core.JsonMissing +import com.alchemystai.sdk.core.JsonValue +import com.alchemystai.sdk.core.Params +import com.alchemystai.sdk.core.checkKnown +import com.alchemystai.sdk.core.checkRequired +import com.alchemystai.sdk.core.http.Headers +import com.alchemystai.sdk.core.http.QueryParams +import com.alchemystai.sdk.core.toImmutable +import com.alchemystai.sdk.errors.AlchemystAiInvalidDataException +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 + +/** + * This endpoint accepts context data and queues it for asynchronous processing by the context + * processor. It returns a success or error response depending on the queuing result. + */ +class AddAsyncCreateParams +private constructor( + private val body: Body, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** + * Type of context being added + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun contextType(): ContextType = body.contextType() + + /** + * Array of documents with content and additional metadata + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun documents(): List = body.documents() + + /** + * Scope of the context + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun scope(): Scope = body.scope() + + /** + * The source of the context data + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun source(): String = body.source() + + /** + * Additional metadata for the context + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun metadata(): Optional = body.metadata() + + /** + * Returns the raw JSON value of [contextType]. + * + * Unlike [contextType], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _contextType(): JsonField = body._contextType() + + /** + * Returns the raw JSON value of [documents]. + * + * Unlike [documents], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _documents(): JsonField> = body._documents() + + /** + * Returns the raw JSON value of [scope]. + * + * Unlike [scope], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _scope(): JsonField = body._scope() + + /** + * Returns the raw JSON value of [source]. + * + * Unlike [source], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _source(): JsonField = body._source() + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _metadata(): JsonField = body._metadata() + + fun _additionalBodyProperties(): Map = body._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [AddAsyncCreateParams]. + * + * The following fields are required: + * ```java + * .contextType() + * .documents() + * .scope() + * .source() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AddAsyncCreateParams]. */ + class Builder internal constructor() { + + private var body: Body.Builder = Body.builder() + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(addAsyncCreateParams: AddAsyncCreateParams) = apply { + body = addAsyncCreateParams.body.toBuilder() + additionalHeaders = addAsyncCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = addAsyncCreateParams.additionalQueryParams.toBuilder() + } + + /** + * Sets the entire request body. + * + * This is generally only useful if you are already constructing the body separately. + * Otherwise, it's more convenient to use the top-level setters instead: + * - [contextType] + * - [documents] + * - [scope] + * - [source] + * - [metadata] + * - etc. + */ + fun body(body: Body) = apply { this.body = body.toBuilder() } + + /** Type of context being added */ + fun contextType(contextType: ContextType) = apply { body.contextType(contextType) } + + /** + * Sets [Builder.contextType] to an arbitrary JSON value. + * + * You should usually call [Builder.contextType] with a well-typed [ContextType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun contextType(contextType: JsonField) = apply { + body.contextType(contextType) + } + + /** Array of documents with content and additional metadata */ + fun documents(documents: List) = apply { body.documents(documents) } + + /** + * Sets [Builder.documents] to an arbitrary JSON value. + * + * You should usually call [Builder.documents] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun documents(documents: JsonField>) = apply { body.documents(documents) } + + /** + * Adds a single [Document] to [documents]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addDocument(document: Document) = apply { body.addDocument(document) } + + /** Scope of the context */ + fun scope(scope: Scope) = apply { body.scope(scope) } + + /** + * Sets [Builder.scope] to an arbitrary JSON value. + * + * You should usually call [Builder.scope] with a well-typed [Scope] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun scope(scope: JsonField) = apply { body.scope(scope) } + + /** The source of the context data */ + fun source(source: String) = apply { body.source(source) } + + /** + * Sets [Builder.source] to an arbitrary JSON value. + * + * You should usually call [Builder.source] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun source(source: JsonField) = apply { body.source(source) } + + /** Additional metadata for the context */ + fun metadata(metadata: Metadata) = apply { body.metadata(metadata) } + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + body.additionalProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + body.putAdditionalProperty(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + body.putAllAdditionalProperties(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { body.removeAdditionalProperty(key) } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + body.removeAllAdditionalProperties(keys) + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [AddAsyncCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .contextType() + * .documents() + * .scope() + * .source() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AddAsyncCreateParams = + AddAsyncCreateParams( + body.build(), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): Body = body + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + class Body + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val contextType: JsonField, + private val documents: JsonField>, + private val scope: JsonField, + private val source: JsonField, + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("context_type") + @ExcludeMissing + contextType: JsonField = JsonMissing.of(), + @JsonProperty("documents") + @ExcludeMissing + documents: JsonField> = JsonMissing.of(), + @JsonProperty("scope") @ExcludeMissing scope: JsonField = JsonMissing.of(), + @JsonProperty("source") @ExcludeMissing source: JsonField = JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this(contextType, documents, scope, source, metadata, mutableMapOf()) + + /** + * Type of context being added + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun contextType(): ContextType = contextType.getRequired("context_type") + + /** + * Array of documents with content and additional metadata + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun documents(): List = documents.getRequired("documents") + + /** + * Scope of the context + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun scope(): Scope = scope.getRequired("scope") + + /** + * The source of the context data + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun source(): String = source.getRequired("source") + + /** + * Additional metadata for the context + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Optional = metadata.getOptional("metadata") + + /** + * Returns the raw JSON value of [contextType]. + * + * Unlike [contextType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("context_type") + @ExcludeMissing + fun _contextType(): JsonField = contextType + + /** + * Returns the raw JSON value of [documents]. + * + * Unlike [documents], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("documents") + @ExcludeMissing + fun _documents(): JsonField> = documents + + /** + * Returns the raw JSON value of [scope]. + * + * Unlike [scope], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("scope") @ExcludeMissing fun _scope(): JsonField = scope + + /** + * Returns the raw JSON value of [source]. + * + * Unlike [source], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("source") @ExcludeMissing fun _source(): JsonField = source + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .contextType() + * .documents() + * .scope() + * .source() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Body]. */ + class Builder internal constructor() { + + private var contextType: JsonField? = null + private var documents: JsonField>? = null + private var scope: JsonField? = null + private var source: JsonField? = null + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(body: Body) = apply { + contextType = body.contextType + documents = body.documents.map { it.toMutableList() } + scope = body.scope + source = body.source + metadata = body.metadata + additionalProperties = body.additionalProperties.toMutableMap() + } + + /** Type of context being added */ + fun contextType(contextType: ContextType) = contextType(JsonField.of(contextType)) + + /** + * Sets [Builder.contextType] to an arbitrary JSON value. + * + * You should usually call [Builder.contextType] with a well-typed [ContextType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun contextType(contextType: JsonField) = apply { + this.contextType = contextType + } + + /** Array of documents with content and additional metadata */ + fun documents(documents: List) = documents(JsonField.of(documents)) + + /** + * Sets [Builder.documents] to an arbitrary JSON value. + * + * You should usually call [Builder.documents] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun documents(documents: JsonField>) = apply { + this.documents = documents.map { it.toMutableList() } + } + + /** + * Adds a single [Document] to [documents]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addDocument(document: Document) = apply { + documents = + (documents ?: JsonField.of(mutableListOf())).also { + checkKnown("documents", it).add(document) + } + } + + /** Scope of the context */ + fun scope(scope: Scope) = scope(JsonField.of(scope)) + + /** + * Sets [Builder.scope] to an arbitrary JSON value. + * + * You should usually call [Builder.scope] with a well-typed [Scope] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun scope(scope: JsonField) = apply { this.scope = scope } + + /** The source of the context data */ + fun source(source: String) = source(JsonField.of(source)) + + /** + * Sets [Builder.source] to an arbitrary JSON value. + * + * You should usually call [Builder.source] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun source(source: JsonField) = apply { this.source = source } + + /** Additional metadata for the context */ + fun metadata(metadata: Metadata) = metadata(JsonField.of(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Body]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .contextType() + * .documents() + * .scope() + * .source() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Body = + Body( + checkRequired("contextType", contextType), + checkRequired("documents", documents).map { it.toImmutable() }, + checkRequired("scope", scope), + checkRequired("source", source), + metadata, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Body = apply { + if (validated) { + return@apply + } + + contextType().validate() + documents().forEach { it.validate() } + scope().validate() + source() + metadata().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (contextType.asKnown().getOrNull()?.validity() ?: 0) + + (documents.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (scope.asKnown().getOrNull()?.validity() ?: 0) + + (if (source.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Body && + contextType == other.contextType && + documents == other.documents && + scope == other.scope && + source == other.source && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(contextType, documents, scope, source, metadata, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Body{contextType=$contextType, documents=$documents, scope=$scope, source=$source, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + /** Type of context being added */ + class ContextType @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 RESOURCE = of("resource") + + @JvmField val CONVERSATION = of("conversation") + + @JvmField val INSTRUCTION = of("instruction") + + @JvmStatic fun of(value: String) = ContextType(JsonField.of(value)) + } + + /** An enum containing [ContextType]'s known values. */ + enum class Known { + RESOURCE, + CONVERSATION, + INSTRUCTION, + } + + /** + * An enum containing [ContextType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [ContextType] 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 { + RESOURCE, + CONVERSATION, + INSTRUCTION, + /** + * An enum member indicating that [ContextType] 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) { + RESOURCE -> Value.RESOURCE + CONVERSATION -> Value.CONVERSATION + INSTRUCTION -> Value.INSTRUCTION + 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 AlchemystAiInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + RESOURCE -> Known.RESOURCE + CONVERSATION -> Known.CONVERSATION + INSTRUCTION -> Known.INSTRUCTION + else -> throw AlchemystAiInvalidDataException("Unknown ContextType: $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 AlchemystAiInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AlchemystAiInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): ContextType = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a 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 ContextType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Document + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val content: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("content") @ExcludeMissing content: JsonField = JsonMissing.of() + ) : this(content, mutableMapOf()) + + /** + * The content of the document + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun content(): Optional = content.getOptional("content") + + /** + * Returns the raw JSON value of [content]. + * + * Unlike [content], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("content") @ExcludeMissing fun _content(): JsonField = content + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Document]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Document]. */ + class Builder internal constructor() { + + private var content: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(document: Document) = apply { + content = document.content + additionalProperties = document.additionalProperties.toMutableMap() + } + + /** The content of the document */ + fun content(content: String) = content(JsonField.of(content)) + + /** + * Sets [Builder.content] to an arbitrary JSON value. + * + * You should usually call [Builder.content] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun content(content: JsonField) = apply { this.content = content } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Document]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Document = Document(content, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Document = apply { + if (validated) { + return@apply + } + + content() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (if (content.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Document && + content == other.content && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(content, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Document{content=$content, additionalProperties=$additionalProperties}" + } + + /** Scope of the context */ + class Scope @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 INTERNAL = of("internal") + + @JvmField val EXTERNAL = of("external") + + @JvmStatic fun of(value: String) = Scope(JsonField.of(value)) + } + + /** An enum containing [Scope]'s known values. */ + enum class Known { + INTERNAL, + EXTERNAL, + } + + /** + * An enum containing [Scope]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Scope] 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 { + INTERNAL, + EXTERNAL, + /** An enum member indicating that [Scope] 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) { + INTERNAL -> Value.INTERNAL + EXTERNAL -> Value.EXTERNAL + 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 AlchemystAiInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + INTERNAL -> Known.INTERNAL + EXTERNAL -> Known.EXTERNAL + else -> throw AlchemystAiInvalidDataException("Unknown Scope: $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 AlchemystAiInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AlchemystAiInvalidDataException("Value is not a String") + } + + private var validated: Boolean = false + + fun validate(): Scope = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a 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 Scope && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Additional metadata for the context */ + class Metadata + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val fileName: JsonField, + private val fileSize: JsonField, + private val fileType: JsonField, + private val groupName: JsonField>, + private val lastModified: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("fileName") + @ExcludeMissing + fileName: JsonField = JsonMissing.of(), + @JsonProperty("fileSize") + @ExcludeMissing + fileSize: JsonField = JsonMissing.of(), + @JsonProperty("fileType") + @ExcludeMissing + fileType: JsonField = JsonMissing.of(), + @JsonProperty("groupName") + @ExcludeMissing + groupName: JsonField> = JsonMissing.of(), + @JsonProperty("lastModified") + @ExcludeMissing + lastModified: JsonField = JsonMissing.of(), + ) : this(fileName, fileSize, fileType, groupName, lastModified, mutableMapOf()) + + /** + * Name of the file + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fileName(): Optional = fileName.getOptional("fileName") + + /** + * Size of the file in bytes + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fileSize(): Optional = fileSize.getOptional("fileSize") + + /** + * Type/MIME of the file + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun fileType(): Optional = fileType.getOptional("fileType") + + /** + * Array of Group Name to which the file belongs to + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun groupName(): Optional> = groupName.getOptional("groupName") + + /** + * Last modified timestamp + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun lastModified(): Optional = lastModified.getOptional("lastModified") + + /** + * Returns the raw JSON value of [fileName]. + * + * Unlike [fileName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("fileName") @ExcludeMissing fun _fileName(): JsonField = fileName + + /** + * Returns the raw JSON value of [fileSize]. + * + * Unlike [fileSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("fileSize") @ExcludeMissing fun _fileSize(): JsonField = fileSize + + /** + * Returns the raw JSON value of [fileType]. + * + * Unlike [fileType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("fileType") @ExcludeMissing fun _fileType(): JsonField = fileType + + /** + * Returns the raw JSON value of [groupName]. + * + * Unlike [groupName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("groupName") + @ExcludeMissing + fun _groupName(): JsonField> = groupName + + /** + * Returns the raw JSON value of [lastModified]. + * + * Unlike [lastModified], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("lastModified") + @ExcludeMissing + fun _lastModified(): JsonField = lastModified + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var fileName: JsonField = JsonMissing.of() + private var fileSize: JsonField = JsonMissing.of() + private var fileType: JsonField = JsonMissing.of() + private var groupName: JsonField>? = null + private var lastModified: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(metadata: Metadata) = apply { + fileName = metadata.fileName + fileSize = metadata.fileSize + fileType = metadata.fileType + groupName = metadata.groupName.map { it.toMutableList() } + lastModified = metadata.lastModified + additionalProperties = metadata.additionalProperties.toMutableMap() + } + + /** Name of the file */ + fun fileName(fileName: String) = fileName(JsonField.of(fileName)) + + /** + * Sets [Builder.fileName] to an arbitrary JSON value. + * + * You should usually call [Builder.fileName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fileName(fileName: JsonField) = apply { this.fileName = fileName } + + /** Size of the file in bytes */ + fun fileSize(fileSize: Double) = fileSize(JsonField.of(fileSize)) + + /** + * Sets [Builder.fileSize] to an arbitrary JSON value. + * + * You should usually call [Builder.fileSize] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fileSize(fileSize: JsonField) = apply { this.fileSize = fileSize } + + /** Type/MIME of the file */ + fun fileType(fileType: String) = fileType(JsonField.of(fileType)) + + /** + * Sets [Builder.fileType] to an arbitrary JSON value. + * + * You should usually call [Builder.fileType] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fileType(fileType: JsonField) = apply { this.fileType = fileType } + + /** Array of Group Name to which the file belongs to */ + fun groupName(groupName: List) = groupName(JsonField.of(groupName)) + + /** + * Sets [Builder.groupName] to an arbitrary JSON value. + * + * You should usually call [Builder.groupName] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun groupName(groupName: JsonField>) = apply { + this.groupName = groupName.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [Builder.groupName]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addGroupName(groupName: String) = apply { + this.groupName = + (this.groupName ?: JsonField.of(mutableListOf())).also { + checkKnown("groupName", it).add(groupName) + } + } + + /** Last modified timestamp */ + fun lastModified(lastModified: String) = lastModified(JsonField.of(lastModified)) + + /** + * Sets [Builder.lastModified] to an arbitrary JSON value. + * + * You should usually call [Builder.lastModified] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun lastModified(lastModified: JsonField) = apply { + this.lastModified = lastModified + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = + Metadata( + fileName, + fileSize, + fileType, + (groupName ?: JsonMissing.of()).map { it.toImmutable() }, + lastModified, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + fileName() + fileSize() + fileType() + groupName() + lastModified() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (fileName.asKnown().isPresent) 1 else 0) + + (if (fileSize.asKnown().isPresent) 1 else 0) + + (if (fileType.asKnown().isPresent) 1 else 0) + + (groupName.asKnown().getOrNull()?.size ?: 0) + + (if (lastModified.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Metadata && + fileName == other.fileName && + fileSize == other.fileSize && + fileType == other.fileType && + groupName == other.groupName && + lastModified == other.lastModified && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + fileName, + fileSize, + fileType, + groupName, + lastModified, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Metadata{fileName=$fileName, fileSize=$fileSize, fileType=$fileType, groupName=$groupName, lastModified=$lastModified, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AddAsyncCreateParams && + body == other.body && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams) + + override fun toString() = + "AddAsyncCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/addasync/AddAsyncCreateResponse.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/addasync/AddAsyncCreateResponse.kt new file mode 100644 index 0000000..096f98b --- /dev/null +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/addasync/AddAsyncCreateResponse.kt @@ -0,0 +1,204 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.models.v1.context.addasync + +import com.alchemystai.sdk.core.ExcludeMissing +import com.alchemystai.sdk.core.JsonField +import com.alchemystai.sdk.core.JsonMissing +import com.alchemystai.sdk.core.JsonValue +import com.alchemystai.sdk.core.checkRequired +import com.alchemystai.sdk.errors.AlchemystAiInvalidDataException +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 AddAsyncCreateResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val jobId: JsonField, + private val queued: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("jobId") @ExcludeMissing jobId: JsonField = JsonMissing.of(), + @JsonProperty("queued") @ExcludeMissing queued: JsonField = JsonMissing.of(), + ) : this(jobId, queued, mutableMapOf()) + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun jobId(): String = jobId.getRequired("jobId") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun queued(): Boolean = queued.getRequired("queued") + + /** + * Returns the raw JSON value of [jobId]. + * + * Unlike [jobId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("jobId") @ExcludeMissing fun _jobId(): JsonField = jobId + + /** + * Returns the raw JSON value of [queued]. + * + * Unlike [queued], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("queued") @ExcludeMissing fun _queued(): JsonField = queued + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [AddAsyncCreateResponse]. + * + * The following fields are required: + * ```java + * .jobId() + * .queued() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AddAsyncCreateResponse]. */ + class Builder internal constructor() { + + private var jobId: JsonField? = null + private var queued: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(addAsyncCreateResponse: AddAsyncCreateResponse) = apply { + jobId = addAsyncCreateResponse.jobId + queued = addAsyncCreateResponse.queued + additionalProperties = addAsyncCreateResponse.additionalProperties.toMutableMap() + } + + fun jobId(jobId: String) = jobId(JsonField.of(jobId)) + + /** + * Sets [Builder.jobId] to an arbitrary JSON value. + * + * You should usually call [Builder.jobId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun jobId(jobId: JsonField) = apply { this.jobId = jobId } + + fun queued(queued: Boolean) = queued(JsonField.of(queued)) + + /** + * Sets [Builder.queued] to an arbitrary JSON value. + * + * You should usually call [Builder.queued] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun queued(queued: JsonField) = apply { this.queued = queued } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [AddAsyncCreateResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .jobId() + * .queued() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AddAsyncCreateResponse = + AddAsyncCreateResponse( + checkRequired("jobId", jobId), + checkRequired("queued", queued), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): AddAsyncCreateResponse = apply { + if (validated) { + return@apply + } + + jobId() + queued() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (jobId.asKnown().isPresent) 1 else 0) + (if (queued.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AddAsyncCreateResponse && + jobId == other.jobId && + queued == other.queued && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(jobId, queued, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AddAsyncCreateResponse{jobId=$jobId, queued=$queued, additionalProperties=$additionalProperties}" +} diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/addasync/status/StatusListParams.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/addasync/status/StatusListParams.kt new file mode 100644 index 0000000..20485be --- /dev/null +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/addasync/status/StatusListParams.kt @@ -0,0 +1,373 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.models.v1.context.addasync.status + +import com.alchemystai.sdk.core.Enum +import com.alchemystai.sdk.core.JsonField +import com.alchemystai.sdk.core.Params +import com.alchemystai.sdk.core.http.Headers +import com.alchemystai.sdk.core.http.QueryParams +import com.alchemystai.sdk.errors.AlchemystAiInvalidDataException +import com.fasterxml.jackson.annotation.JsonCreator +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Returns all jobs (active, waiting, delayed, failed, completed) belonging to the authenticated + * user. + */ +class StatusListParams +private constructor( + private val limit: String?, + private val offset: String?, + private val type: Type?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** Maximum number of jobs to return */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** Number of jobs to skip before starting to collect the result set */ + fun offset(): Optional = Optional.ofNullable(offset) + + /** Type of jobs to list */ + fun type(): Optional = Optional.ofNullable(type) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): StatusListParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [StatusListParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [StatusListParams]. */ + class Builder internal constructor() { + + private var limit: String? = null + private var offset: String? = null + private var type: Type? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(statusListParams: StatusListParams) = apply { + limit = statusListParams.limit + offset = statusListParams.offset + type = statusListParams.type + additionalHeaders = statusListParams.additionalHeaders.toBuilder() + additionalQueryParams = statusListParams.additionalQueryParams.toBuilder() + } + + /** Maximum number of jobs to return */ + fun limit(limit: String?) = apply { this.limit = limit } + + /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ + fun limit(limit: Optional) = limit(limit.getOrNull()) + + /** Number of jobs to skip before starting to collect the result set */ + fun offset(offset: String?) = apply { this.offset = offset } + + /** Alias for calling [Builder.offset] with `offset.orElse(null)`. */ + fun offset(offset: Optional) = offset(offset.getOrNull()) + + /** Type of jobs to list */ + fun type(type: Type?) = apply { this.type = type } + + /** Alias for calling [Builder.type] with `type.orElse(null)`. */ + fun type(type: Optional) = type(type.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [StatusListParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): StatusListParams = + StatusListParams( + limit, + offset, + type, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + limit?.let { put("limit", it) } + offset?.let { put("offset", it) } + type?.let { put("type", it.toString()) } + putAll(additionalQueryParams) + } + .build() + + /** Type of jobs to list */ + 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 ALL = of("all") + + @JvmField val ACTIVE = of("active") + + @JvmField val FAILED = of("failed") + + @JvmField val COMPLETED = of("completed") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + ALL, + ACTIVE, + FAILED, + COMPLETED, + } + + /** + * 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 { + ALL, + ACTIVE, + FAILED, + COMPLETED, + /** 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) { + ALL -> Value.ALL + ACTIVE -> Value.ACTIVE + FAILED -> Value.FAILED + COMPLETED -> Value.COMPLETED + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws AlchemystAiInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + ALL -> Known.ALL + ACTIVE -> Known.ACTIVE + FAILED -> Known.FAILED + COMPLETED -> Known.COMPLETED + else -> throw AlchemystAiInvalidDataException("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 AlchemystAiInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { + AlchemystAiInvalidDataException("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: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Type && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is StatusListParams && + limit == other.limit && + offset == other.offset && + type == other.type && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(limit, offset, type, additionalHeaders, additionalQueryParams) + + override fun toString() = + "StatusListParams{limit=$limit, offset=$offset, type=$type, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/addasync/status/StatusListResponse.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/addasync/status/StatusListResponse.kt new file mode 100644 index 0000000..67d9e9a --- /dev/null +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/addasync/status/StatusListResponse.kt @@ -0,0 +1,602 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.models.v1.context.addasync.status + +import com.alchemystai.sdk.core.ExcludeMissing +import com.alchemystai.sdk.core.JsonField +import com.alchemystai.sdk.core.JsonMissing +import com.alchemystai.sdk.core.JsonValue +import com.alchemystai.sdk.core.checkKnown +import com.alchemystai.sdk.core.checkRequired +import com.alchemystai.sdk.core.toImmutable +import com.alchemystai.sdk.errors.AlchemystAiInvalidDataException +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 StatusListResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val jobs: JsonField>, + private val success: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("jobs") @ExcludeMissing jobs: JsonField> = JsonMissing.of(), + @JsonProperty("success") @ExcludeMissing success: JsonField = JsonMissing.of(), + ) : this(jobs, success, mutableMapOf()) + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun jobs(): List = jobs.getRequired("jobs") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun success(): Boolean = success.getRequired("success") + + /** + * Returns the raw JSON value of [jobs]. + * + * Unlike [jobs], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("jobs") @ExcludeMissing fun _jobs(): JsonField> = jobs + + /** + * Returns the raw JSON value of [success]. + * + * Unlike [success], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("success") @ExcludeMissing fun _success(): JsonField = success + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [StatusListResponse]. + * + * The following fields are required: + * ```java + * .jobs() + * .success() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [StatusListResponse]. */ + class Builder internal constructor() { + + private var jobs: JsonField>? = null + private var success: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(statusListResponse: StatusListResponse) = apply { + jobs = statusListResponse.jobs.map { it.toMutableList() } + success = statusListResponse.success + additionalProperties = statusListResponse.additionalProperties.toMutableMap() + } + + fun jobs(jobs: List) = jobs(JsonField.of(jobs)) + + /** + * Sets [Builder.jobs] to an arbitrary JSON value. + * + * You should usually call [Builder.jobs] with a well-typed `List` value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun jobs(jobs: JsonField>) = apply { this.jobs = jobs.map { it.toMutableList() } } + + /** + * Adds a single [Job] to [jobs]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addJob(job: Job) = apply { + jobs = (jobs ?: JsonField.of(mutableListOf())).also { checkKnown("jobs", it).add(job) } + } + + fun success(success: Boolean) = success(JsonField.of(success)) + + /** + * Sets [Builder.success] to an arbitrary JSON value. + * + * You should usually call [Builder.success] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun success(success: JsonField) = apply { this.success = success } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [StatusListResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .jobs() + * .success() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): StatusListResponse = + StatusListResponse( + checkRequired("jobs", jobs).map { it.toImmutable() }, + checkRequired("success", success), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): StatusListResponse = apply { + if (validated) { + return@apply + } + + jobs().forEach { it.validate() } + success() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (jobs.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (success.asKnown().isPresent) 1 else 0) + + class Job + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val attemptsMade: JsonField, + private val data: JsonValue, + private val jobId: JsonField, + private val status: JsonField, + private val failedReason: JsonField, + private val finishedOn: JsonField, + private val processedOn: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("attemptsMade") + @ExcludeMissing + attemptsMade: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing data: JsonValue = JsonMissing.of(), + @JsonProperty("jobId") @ExcludeMissing jobId: JsonField = JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("failedReason") + @ExcludeMissing + failedReason: JsonField = JsonMissing.of(), + @JsonProperty("finishedOn") + @ExcludeMissing + finishedOn: JsonField = JsonMissing.of(), + @JsonProperty("processedOn") + @ExcludeMissing + processedOn: JsonField = JsonMissing.of(), + ) : this( + attemptsMade, + data, + jobId, + status, + failedReason, + finishedOn, + processedOn, + mutableMapOf(), + ) + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun attemptsMade(): Double = attemptsMade.getRequired("attemptsMade") + + /** + * This arbitrary value can be deserialized into a custom type using the `convert` method: + * ```java + * MyClass myObject = job.data().convert(MyClass.class); + * ``` + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonValue = data + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun jobId(): String = jobId.getRequired("jobId") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun status(): String = status.getRequired("status") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun failedReason(): Optional = failedReason.getOptional("failedReason") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun finishedOn(): Optional = finishedOn.getOptional("finishedOn") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun processedOn(): Optional = processedOn.getOptional("processedOn") + + /** + * Returns the raw JSON value of [attemptsMade]. + * + * Unlike [attemptsMade], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("attemptsMade") + @ExcludeMissing + fun _attemptsMade(): JsonField = attemptsMade + + /** + * Returns the raw JSON value of [jobId]. + * + * Unlike [jobId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("jobId") @ExcludeMissing fun _jobId(): JsonField = jobId + + /** + * Returns the raw JSON value of [status]. + * + * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + /** + * Returns the raw JSON value of [failedReason]. + * + * Unlike [failedReason], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("failedReason") + @ExcludeMissing + fun _failedReason(): JsonField = failedReason + + /** + * Returns the raw JSON value of [finishedOn]. + * + * Unlike [finishedOn], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("finishedOn") + @ExcludeMissing + fun _finishedOn(): JsonField = finishedOn + + /** + * Returns the raw JSON value of [processedOn]. + * + * Unlike [processedOn], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("processedOn") + @ExcludeMissing + fun _processedOn(): JsonField = processedOn + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Job]. + * + * The following fields are required: + * ```java + * .attemptsMade() + * .data() + * .jobId() + * .status() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Job]. */ + class Builder internal constructor() { + + private var attemptsMade: JsonField? = null + private var data: JsonValue? = null + private var jobId: JsonField? = null + private var status: JsonField? = null + private var failedReason: JsonField = JsonMissing.of() + private var finishedOn: JsonField = JsonMissing.of() + private var processedOn: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(job: Job) = apply { + attemptsMade = job.attemptsMade + data = job.data + jobId = job.jobId + status = job.status + failedReason = job.failedReason + finishedOn = job.finishedOn + processedOn = job.processedOn + additionalProperties = job.additionalProperties.toMutableMap() + } + + fun attemptsMade(attemptsMade: Double) = attemptsMade(JsonField.of(attemptsMade)) + + /** + * Sets [Builder.attemptsMade] to an arbitrary JSON value. + * + * You should usually call [Builder.attemptsMade] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun attemptsMade(attemptsMade: JsonField) = apply { + this.attemptsMade = attemptsMade + } + + fun data(data: JsonValue) = apply { this.data = data } + + fun jobId(jobId: String) = jobId(JsonField.of(jobId)) + + /** + * Sets [Builder.jobId] to an arbitrary JSON value. + * + * You should usually call [Builder.jobId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun jobId(jobId: JsonField) = apply { this.jobId = jobId } + + fun status(status: String) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun status(status: JsonField) = apply { this.status = status } + + fun failedReason(failedReason: String) = failedReason(JsonField.of(failedReason)) + + /** + * Sets [Builder.failedReason] to an arbitrary JSON value. + * + * You should usually call [Builder.failedReason] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun failedReason(failedReason: JsonField) = apply { + this.failedReason = failedReason + } + + fun finishedOn(finishedOn: Double) = finishedOn(JsonField.of(finishedOn)) + + /** + * Sets [Builder.finishedOn] to an arbitrary JSON value. + * + * You should usually call [Builder.finishedOn] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun finishedOn(finishedOn: JsonField) = apply { this.finishedOn = finishedOn } + + fun processedOn(processedOn: Double) = processedOn(JsonField.of(processedOn)) + + /** + * Sets [Builder.processedOn] to an arbitrary JSON value. + * + * You should usually call [Builder.processedOn] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun processedOn(processedOn: JsonField) = apply { + this.processedOn = processedOn + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Job]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .attemptsMade() + * .data() + * .jobId() + * .status() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Job = + Job( + checkRequired("attemptsMade", attemptsMade), + checkRequired("data", data), + checkRequired("jobId", jobId), + checkRequired("status", status), + failedReason, + finishedOn, + processedOn, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Job = apply { + if (validated) { + return@apply + } + + attemptsMade() + jobId() + status() + failedReason() + finishedOn() + processedOn() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (attemptsMade.asKnown().isPresent) 1 else 0) + + (if (jobId.asKnown().isPresent) 1 else 0) + + (if (status.asKnown().isPresent) 1 else 0) + + (if (failedReason.asKnown().isPresent) 1 else 0) + + (if (finishedOn.asKnown().isPresent) 1 else 0) + + (if (processedOn.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Job && + attemptsMade == other.attemptsMade && + data == other.data && + jobId == other.jobId && + status == other.status && + failedReason == other.failedReason && + finishedOn == other.finishedOn && + processedOn == other.processedOn && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + attemptsMade, + data, + jobId, + status, + failedReason, + finishedOn, + processedOn, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Job{attemptsMade=$attemptsMade, data=$data, jobId=$jobId, status=$status, failedReason=$failedReason, finishedOn=$finishedOn, processedOn=$processedOn, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is StatusListResponse && + jobs == other.jobs && + success == other.success && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(jobs, success, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "StatusListResponse{jobs=$jobs, success=$success, additionalProperties=$additionalProperties}" +} diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/addasync/status/StatusRetrieveParams.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/addasync/status/StatusRetrieveParams.kt new file mode 100644 index 0000000..a036249 --- /dev/null +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/addasync/status/StatusRetrieveParams.kt @@ -0,0 +1,189 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.models.v1.context.addasync.status + +import com.alchemystai.sdk.core.Params +import com.alchemystai.sdk.core.http.Headers +import com.alchemystai.sdk.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Returns the status and result of a context add job by job id. */ +class StatusRetrieveParams +private constructor( + private val id: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun id(): Optional = Optional.ofNullable(id) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): StatusRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [StatusRetrieveParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [StatusRetrieveParams]. */ + class Builder internal constructor() { + + private var id: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(statusRetrieveParams: StatusRetrieveParams) = apply { + id = statusRetrieveParams.id + additionalHeaders = statusRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = statusRetrieveParams.additionalQueryParams.toBuilder() + } + + fun id(id: String?) = apply { this.id = id } + + /** Alias for calling [Builder.id] with `id.orElse(null)`. */ + fun id(id: Optional) = id(id.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [StatusRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): StatusRetrieveParams = + StatusRetrieveParams(id, additionalHeaders.build(), additionalQueryParams.build()) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> id ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is StatusRetrieveParams && + id == other.id && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(id, additionalHeaders, additionalQueryParams) + + override fun toString() = + "StatusRetrieveParams{id=$id, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/addasync/status/StatusRetrieveResponse.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/addasync/status/StatusRetrieveResponse.kt new file mode 100644 index 0000000..52e24a4 --- /dev/null +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/addasync/status/StatusRetrieveResponse.kt @@ -0,0 +1,424 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.models.v1.context.addasync.status + +import com.alchemystai.sdk.core.ExcludeMissing +import com.alchemystai.sdk.core.JsonField +import com.alchemystai.sdk.core.JsonMissing +import com.alchemystai.sdk.core.JsonValue +import com.alchemystai.sdk.core.checkRequired +import com.alchemystai.sdk.errors.AlchemystAiInvalidDataException +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 + +class StatusRetrieveResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val jobId: JsonField, + private val status: JsonField, + private val success: JsonField, + private val attemptsMade: JsonField, + private val failedReason: JsonField, + private val finishedOn: JsonField, + private val processedOn: JsonField, + private val result: JsonValue, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("jobId") @ExcludeMissing jobId: JsonField = JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("success") @ExcludeMissing success: JsonField = JsonMissing.of(), + @JsonProperty("attemptsMade") + @ExcludeMissing + attemptsMade: JsonField = JsonMissing.of(), + @JsonProperty("failedReason") + @ExcludeMissing + failedReason: JsonField = JsonMissing.of(), + @JsonProperty("finishedOn") + @ExcludeMissing + finishedOn: JsonField = JsonMissing.of(), + @JsonProperty("processedOn") + @ExcludeMissing + processedOn: JsonField = JsonMissing.of(), + @JsonProperty("result") @ExcludeMissing result: JsonValue = JsonMissing.of(), + ) : this( + jobId, + status, + success, + attemptsMade, + failedReason, + finishedOn, + processedOn, + result, + mutableMapOf(), + ) + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun jobId(): String = jobId.getRequired("jobId") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun status(): String = status.getRequired("status") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun success(): Boolean = success.getRequired("success") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun attemptsMade(): Optional = attemptsMade.getOptional("attemptsMade") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun failedReason(): Optional = failedReason.getOptional("failedReason") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun finishedOn(): Optional = finishedOn.getOptional("finishedOn") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun processedOn(): Optional = processedOn.getOptional("processedOn") + + /** + * Result of the job (if available) + * + * This arbitrary value can be deserialized into a custom type using the `convert` method: + * ```java + * MyClass myObject = statusRetrieveResponse.result().convert(MyClass.class); + * ``` + */ + @JsonProperty("result") @ExcludeMissing fun _result(): JsonValue = result + + /** + * Returns the raw JSON value of [jobId]. + * + * Unlike [jobId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("jobId") @ExcludeMissing fun _jobId(): JsonField = jobId + + /** + * Returns the raw JSON value of [status]. + * + * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + /** + * Returns the raw JSON value of [success]. + * + * Unlike [success], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("success") @ExcludeMissing fun _success(): JsonField = success + + /** + * Returns the raw JSON value of [attemptsMade]. + * + * Unlike [attemptsMade], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("attemptsMade") + @ExcludeMissing + fun _attemptsMade(): JsonField = attemptsMade + + /** + * Returns the raw JSON value of [failedReason]. + * + * Unlike [failedReason], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("failedReason") + @ExcludeMissing + fun _failedReason(): JsonField = failedReason + + /** + * Returns the raw JSON value of [finishedOn]. + * + * Unlike [finishedOn], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("finishedOn") @ExcludeMissing fun _finishedOn(): JsonField = finishedOn + + /** + * Returns the raw JSON value of [processedOn]. + * + * Unlike [processedOn], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("processedOn") @ExcludeMissing fun _processedOn(): JsonField = processedOn + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [StatusRetrieveResponse]. + * + * The following fields are required: + * ```java + * .jobId() + * .status() + * .success() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [StatusRetrieveResponse]. */ + class Builder internal constructor() { + + private var jobId: JsonField? = null + private var status: JsonField? = null + private var success: JsonField? = null + private var attemptsMade: JsonField = JsonMissing.of() + private var failedReason: JsonField = JsonMissing.of() + private var finishedOn: JsonField = JsonMissing.of() + private var processedOn: JsonField = JsonMissing.of() + private var result: JsonValue = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(statusRetrieveResponse: StatusRetrieveResponse) = apply { + jobId = statusRetrieveResponse.jobId + status = statusRetrieveResponse.status + success = statusRetrieveResponse.success + attemptsMade = statusRetrieveResponse.attemptsMade + failedReason = statusRetrieveResponse.failedReason + finishedOn = statusRetrieveResponse.finishedOn + processedOn = statusRetrieveResponse.processedOn + result = statusRetrieveResponse.result + additionalProperties = statusRetrieveResponse.additionalProperties.toMutableMap() + } + + fun jobId(jobId: String) = jobId(JsonField.of(jobId)) + + /** + * Sets [Builder.jobId] to an arbitrary JSON value. + * + * You should usually call [Builder.jobId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun jobId(jobId: JsonField) = apply { this.jobId = jobId } + + fun status(status: String) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun status(status: JsonField) = apply { this.status = status } + + fun success(success: Boolean) = success(JsonField.of(success)) + + /** + * Sets [Builder.success] to an arbitrary JSON value. + * + * You should usually call [Builder.success] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun success(success: JsonField) = apply { this.success = success } + + fun attemptsMade(attemptsMade: Double) = attemptsMade(JsonField.of(attemptsMade)) + + /** + * Sets [Builder.attemptsMade] to an arbitrary JSON value. + * + * You should usually call [Builder.attemptsMade] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun attemptsMade(attemptsMade: JsonField) = apply { + this.attemptsMade = attemptsMade + } + + fun failedReason(failedReason: String) = failedReason(JsonField.of(failedReason)) + + /** + * Sets [Builder.failedReason] to an arbitrary JSON value. + * + * You should usually call [Builder.failedReason] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun failedReason(failedReason: JsonField) = apply { + this.failedReason = failedReason + } + + fun finishedOn(finishedOn: Double) = finishedOn(JsonField.of(finishedOn)) + + /** + * Sets [Builder.finishedOn] to an arbitrary JSON value. + * + * You should usually call [Builder.finishedOn] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun finishedOn(finishedOn: JsonField) = apply { this.finishedOn = finishedOn } + + fun processedOn(processedOn: Double) = processedOn(JsonField.of(processedOn)) + + /** + * Sets [Builder.processedOn] to an arbitrary JSON value. + * + * You should usually call [Builder.processedOn] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun processedOn(processedOn: JsonField) = apply { this.processedOn = processedOn } + + /** Result of the job (if available) */ + fun result(result: JsonValue) = apply { this.result = result } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [StatusRetrieveResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .jobId() + * .status() + * .success() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): StatusRetrieveResponse = + StatusRetrieveResponse( + checkRequired("jobId", jobId), + checkRequired("status", status), + checkRequired("success", success), + attemptsMade, + failedReason, + finishedOn, + processedOn, + result, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): StatusRetrieveResponse = apply { + if (validated) { + return@apply + } + + jobId() + status() + success() + attemptsMade() + failedReason() + finishedOn() + processedOn() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (jobId.asKnown().isPresent) 1 else 0) + + (if (status.asKnown().isPresent) 1 else 0) + + (if (success.asKnown().isPresent) 1 else 0) + + (if (attemptsMade.asKnown().isPresent) 1 else 0) + + (if (failedReason.asKnown().isPresent) 1 else 0) + + (if (finishedOn.asKnown().isPresent) 1 else 0) + + (if (processedOn.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is StatusRetrieveResponse && + jobId == other.jobId && + status == other.status && + success == other.success && + attemptsMade == other.attemptsMade && + failedReason == other.failedReason && + finishedOn == other.finishedOn && + processedOn == other.processedOn && + result == other.result && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + jobId, + status, + success, + attemptsMade, + failedReason, + finishedOn, + processedOn, + result, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "StatusRetrieveResponse{jobId=$jobId, status=$status, success=$success, attemptsMade=$attemptsMade, failedReason=$failedReason, finishedOn=$finishedOn, processedOn=$processedOn, result=$result, additionalProperties=$additionalProperties}" +} diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryAddParams.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryAddParams.kt index d90efd6..2cdf929 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryAddParams.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryAddParams.kt @@ -8,6 +8,7 @@ import com.alchemystai.sdk.core.JsonMissing import com.alchemystai.sdk.core.JsonValue import com.alchemystai.sdk.core.Params import com.alchemystai.sdk.core.checkKnown +import com.alchemystai.sdk.core.checkRequired import com.alchemystai.sdk.core.http.Headers import com.alchemystai.sdk.core.http.QueryParams import com.alchemystai.sdk.core.toImmutable @@ -21,7 +22,7 @@ import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -/** This endpoint adds memory context data, fetching chat history if needed. */ +/** This endpoint adds memory (chat history) as context. */ class MemoryAddParams private constructor( private val body: Body, @@ -30,20 +31,29 @@ private constructor( ) : Params { /** - * Array of content objects with additional properties allowed + * Array of content objects. Each object must contain at least the 'content' field. Additional + * properties are allowed. * - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun contents(): List = body.contents() + + /** + * The ID of the session + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun contents(): Optional> = body.contents() + fun sessionId(): String = body.sessionId() /** - * The ID of the memory + * Optional metadata for the memory context. Defaults to ["default"] if not provided. * * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun memoryId(): Optional = body.memoryId() + fun metadata(): Optional = body.metadata() /** * Returns the raw JSON value of [contents]. @@ -53,11 +63,18 @@ private constructor( fun _contents(): JsonField> = body._contents() /** - * Returns the raw JSON value of [memoryId]. + * Returns the raw JSON value of [sessionId]. + * + * Unlike [sessionId], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _sessionId(): JsonField = body._sessionId() + + /** + * Returns the raw JSON value of [metadata]. * - * Unlike [memoryId], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. */ - fun _memoryId(): JsonField = body._memoryId() + fun _metadata(): JsonField = body._metadata() fun _additionalBodyProperties(): Map = body._additionalProperties() @@ -71,9 +88,15 @@ private constructor( companion object { - @JvmStatic fun none(): MemoryAddParams = builder().build() - - /** Returns a mutable builder for constructing an instance of [MemoryAddParams]. */ + /** + * Returns a mutable builder for constructing an instance of [MemoryAddParams]. + * + * The following fields are required: + * ```java + * .contents() + * .sessionId() + * ``` + */ @JvmStatic fun builder() = Builder() } @@ -97,11 +120,15 @@ private constructor( * This is generally only useful if you are already constructing the body separately. * Otherwise, it's more convenient to use the top-level setters instead: * - [contents] - * - [memoryId] + * - [sessionId] + * - [metadata] */ fun body(body: Body) = apply { this.body = body.toBuilder() } - /** Array of content objects with additional properties allowed */ + /** + * Array of content objects. Each object must contain at least the 'content' field. + * Additional properties are allowed. + */ fun contents(contents: List) = apply { body.contents(contents) } /** @@ -120,16 +147,29 @@ private constructor( */ fun addContent(content: Content) = apply { body.addContent(content) } - /** The ID of the memory */ - fun memoryId(memoryId: String) = apply { body.memoryId(memoryId) } + /** The ID of the session */ + fun sessionId(sessionId: String) = apply { body.sessionId(sessionId) } /** - * Sets [Builder.memoryId] to an arbitrary JSON value. + * Sets [Builder.sessionId] to an arbitrary JSON value. * - * You should usually call [Builder.memoryId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * You should usually call [Builder.sessionId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun memoryId(memoryId: JsonField) = apply { body.memoryId(memoryId) } + fun sessionId(sessionId: JsonField) = apply { body.sessionId(sessionId) } + + /** Optional metadata for the memory context. Defaults to ["default"] if not provided. */ + fun metadata(metadata: Metadata) = apply { body.metadata(metadata) } + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun metadata(metadata: JsonField) = apply { body.metadata(metadata) } fun additionalBodyProperties(additionalBodyProperties: Map) = apply { body.additionalProperties(additionalBodyProperties) @@ -252,6 +292,14 @@ private constructor( * Returns an immutable instance of [MemoryAddParams]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .contents() + * .sessionId() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): MemoryAddParams = MemoryAddParams(body.build(), additionalHeaders.build(), additionalQueryParams.build()) @@ -267,7 +315,8 @@ private constructor( @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val contents: JsonField>, - private val memoryId: JsonField, + private val sessionId: JsonField, + private val metadata: JsonField, private val additionalProperties: MutableMap, ) { @@ -276,24 +325,38 @@ private constructor( @JsonProperty("contents") @ExcludeMissing contents: JsonField> = JsonMissing.of(), - @JsonProperty("memoryId") @ExcludeMissing memoryId: JsonField = JsonMissing.of(), - ) : this(contents, memoryId, mutableMapOf()) + @JsonProperty("sessionId") + @ExcludeMissing + sessionId: JsonField = JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this(contents, sessionId, metadata, mutableMapOf()) /** - * Array of content objects with additional properties allowed + * Array of content objects. Each object must contain at least the 'content' field. + * Additional properties are allowed. * - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun contents(): List = contents.getRequired("contents") + + /** + * The ID of the session + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun contents(): Optional> = contents.getOptional("contents") + fun sessionId(): String = sessionId.getRequired("sessionId") /** - * The ID of the memory + * Optional metadata for the memory context. Defaults to ["default"] if not provided. * * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun memoryId(): Optional = memoryId.getOptional("memoryId") + fun metadata(): Optional = metadata.getOptional("metadata") /** * Returns the raw JSON value of [contents]. @@ -305,11 +368,18 @@ private constructor( fun _contents(): JsonField> = contents /** - * Returns the raw JSON value of [memoryId]. + * Returns the raw JSON value of [sessionId]. * - * Unlike [memoryId], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [sessionId], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("memoryId") @ExcludeMissing fun _memoryId(): JsonField = memoryId + @JsonProperty("sessionId") @ExcludeMissing fun _sessionId(): JsonField = sessionId + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -325,7 +395,15 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Body]. */ + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .contents() + * .sessionId() + * ``` + */ @JvmStatic fun builder() = Builder() } @@ -333,17 +411,22 @@ private constructor( class Builder internal constructor() { private var contents: JsonField>? = null - private var memoryId: JsonField = JsonMissing.of() + private var sessionId: JsonField? = null + private var metadata: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(body: Body) = apply { contents = body.contents.map { it.toMutableList() } - memoryId = body.memoryId + sessionId = body.sessionId + metadata = body.metadata additionalProperties = body.additionalProperties.toMutableMap() } - /** Array of content objects with additional properties allowed */ + /** + * Array of content objects. Each object must contain at least the 'content' field. + * Additional properties are allowed. + */ fun contents(contents: List) = contents(JsonField.of(contents)) /** @@ -369,17 +452,31 @@ private constructor( } } - /** The ID of the memory */ - fun memoryId(memoryId: String) = memoryId(JsonField.of(memoryId)) + /** The ID of the session */ + fun sessionId(sessionId: String) = sessionId(JsonField.of(sessionId)) /** - * Sets [Builder.memoryId] to an arbitrary JSON value. + * Sets [Builder.sessionId] to an arbitrary JSON value. * - * You should usually call [Builder.memoryId] with a well-typed [String] value instead. + * You should usually call [Builder.sessionId] with a well-typed [String] value instead. * This method is primarily for setting the field to an undocumented or not yet * supported value. */ - fun memoryId(memoryId: JsonField) = apply { this.memoryId = memoryId } + fun sessionId(sessionId: JsonField) = apply { this.sessionId = sessionId } + + /** + * Optional metadata for the memory context. Defaults to ["default"] if not provided. + */ + fun metadata(metadata: Metadata) = metadata(JsonField.of(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -404,11 +501,20 @@ private constructor( * Returns an immutable instance of [Body]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .contents() + * .sessionId() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): Body = Body( - (contents ?: JsonMissing.of()).map { it.toImmutable() }, - memoryId, + checkRequired("contents", contents).map { it.toImmutable() }, + checkRequired("sessionId", sessionId), + metadata, additionalProperties.toMutableMap(), ) } @@ -420,8 +526,9 @@ private constructor( return@apply } - contents().ifPresent { it.forEach { it.validate() } } - memoryId() + contents().forEach { it.validate() } + sessionId() + metadata().ifPresent { it.validate() } validated = true } @@ -442,7 +549,8 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (contents.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + - (if (memoryId.asKnown().isPresent) 1 else 0) + (if (sessionId.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) override fun equals(other: Any?): Boolean { if (this === other) { @@ -451,35 +559,52 @@ private constructor( return other is Body && contents == other.contents && - memoryId == other.memoryId && + sessionId == other.sessionId && + metadata == other.metadata && additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { Objects.hash(contents, memoryId, additionalProperties) } + private val hashCode: Int by lazy { + Objects.hash(contents, sessionId, metadata, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "Body{contents=$contents, memoryId=$memoryId, additionalProperties=$additionalProperties}" + "Body{contents=$contents, sessionId=$sessionId, metadata=$metadata, additionalProperties=$additionalProperties}" } class Content @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val content: JsonField, + private val metadata: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("content") @ExcludeMissing content: JsonField = JsonMissing.of() - ) : this(content, mutableMapOf()) + @JsonProperty("content") @ExcludeMissing content: JsonField = JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this(content, metadata, mutableMapOf()) /** + * The content of the memory message + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun content(): String = content.getRequired("content") + + /** + * Additional metadata for the message (optional) + * * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun content(): Optional = content.getOptional("content") + fun metadata(): Optional = metadata.getOptional("metadata") /** * Returns the raw JSON value of [content]. @@ -488,6 +613,13 @@ private constructor( */ @JsonProperty("content") @ExcludeMissing fun _content(): JsonField = content + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -502,22 +634,32 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Content]. */ + /** + * Returns a mutable builder for constructing an instance of [Content]. + * + * The following fields are required: + * ```java + * .content() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Content]. */ class Builder internal constructor() { - private var content: JsonField = JsonMissing.of() + private var content: JsonField? = null + private var metadata: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(content: Content) = apply { this.content = content.content + metadata = content.metadata additionalProperties = content.additionalProperties.toMutableMap() } + /** The content of the memory message */ fun content(content: String) = content(JsonField.of(content)) /** @@ -529,6 +671,18 @@ private constructor( */ fun content(content: JsonField) = apply { this.content = content } + /** Additional metadata for the message (optional) */ + fun metadata(metadata: Metadata) = metadata(JsonField.of(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -552,8 +706,20 @@ private constructor( * Returns an immutable instance of [Content]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .content() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ - fun build(): Content = Content(content, additionalProperties.toMutableMap()) + fun build(): Content = + Content( + checkRequired("content", content), + metadata, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -564,6 +730,7 @@ private constructor( } content() + metadata().ifPresent { it.validate() } validated = true } @@ -581,7 +748,161 @@ private constructor( * * Used for best match union deserialization. */ - @JvmSynthetic internal fun validity(): Int = (if (content.asKnown().isPresent) 1 else 0) + @JvmSynthetic + internal fun validity(): Int = + (if (content.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + /** Additional metadata for the message (optional) */ + class Metadata + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val messageId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("messageId") + @ExcludeMissing + messageId: JsonField = JsonMissing.of() + ) : this(messageId, mutableMapOf()) + + /** + * Unique message ID + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun messageId(): Optional = messageId.getOptional("messageId") + + /** + * Returns the raw JSON value of [messageId]. + * + * Unlike [messageId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("messageId") + @ExcludeMissing + fun _messageId(): JsonField = messageId + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var messageId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(metadata: Metadata) = apply { + messageId = metadata.messageId + additionalProperties = metadata.additionalProperties.toMutableMap() + } + + /** Unique message ID */ + fun messageId(messageId: String) = messageId(JsonField.of(messageId)) + + /** + * Sets [Builder.messageId] to an arbitrary JSON value. + * + * You should usually call [Builder.messageId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun messageId(messageId: JsonField) = apply { this.messageId = messageId } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(messageId, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + messageId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = (if (messageId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Metadata && + messageId == other.messageId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(messageId, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Metadata{messageId=$messageId, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { @@ -590,15 +911,182 @@ private constructor( return other is Content && content == other.content && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(content, metadata, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Content{content=$content, metadata=$metadata, additionalProperties=$additionalProperties}" + } + + /** Optional metadata for the memory context. Defaults to ["default"] if not provided. */ + class Metadata + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val groupName: JsonField>, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("groupName") + @ExcludeMissing + groupName: JsonField> = JsonMissing.of() + ) : this(groupName, mutableMapOf()) + + /** + * Optional group names for the memory context. Defaults to ["default"] if not provided. + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun groupName(): Optional> = groupName.getOptional("groupName") + + /** + * Returns the raw JSON value of [groupName]. + * + * Unlike [groupName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("groupName") + @ExcludeMissing + fun _groupName(): JsonField> = groupName + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var groupName: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(metadata: Metadata) = apply { + groupName = metadata.groupName.map { it.toMutableList() } + additionalProperties = metadata.additionalProperties.toMutableMap() + } + + /** + * Optional group names for the memory context. Defaults to ["default"] if not provided. + */ + fun groupName(groupName: List) = groupName(JsonField.of(groupName)) + + /** + * Sets [Builder.groupName] to an arbitrary JSON value. + * + * You should usually call [Builder.groupName] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun groupName(groupName: JsonField>) = apply { + this.groupName = groupName.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [Builder.groupName]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addGroupName(groupName: String) = apply { + this.groupName = + (this.groupName ?: JsonField.of(mutableListOf())).also { + checkKnown("groupName", it).add(groupName) + } + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = + Metadata( + (groupName ?: JsonMissing.of()).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + groupName() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic internal fun validity(): Int = (groupName.asKnown().getOrNull()?.size ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Metadata && + groupName == other.groupName && additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { Objects.hash(content, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(groupName, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "Content{content=$content, additionalProperties=$additionalProperties}" + "Metadata{groupName=$groupName, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryAddResponse.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryAddResponse.kt new file mode 100644 index 0000000..e367785 --- /dev/null +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryAddResponse.kt @@ -0,0 +1,250 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.models.v1.context.memory + +import com.alchemystai.sdk.core.ExcludeMissing +import com.alchemystai.sdk.core.JsonField +import com.alchemystai.sdk.core.JsonMissing +import com.alchemystai.sdk.core.JsonValue +import com.alchemystai.sdk.core.checkRequired +import com.alchemystai.sdk.errors.AlchemystAiInvalidDataException +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 + +class MemoryAddResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val contextId: JsonField, + private val success: JsonField, + private val processedDocuments: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("context_id") @ExcludeMissing contextId: JsonField = JsonMissing.of(), + @JsonProperty("success") @ExcludeMissing success: JsonField = JsonMissing.of(), + @JsonProperty("processed_documents") + @ExcludeMissing + processedDocuments: JsonField = JsonMissing.of(), + ) : this(contextId, success, processedDocuments, mutableMapOf()) + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun contextId(): String = contextId.getRequired("context_id") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun success(): Boolean = success.getRequired("success") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun processedDocuments(): Optional = + processedDocuments.getOptional("processed_documents") + + /** + * Returns the raw JSON value of [contextId]. + * + * Unlike [contextId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("context_id") @ExcludeMissing fun _contextId(): JsonField = contextId + + /** + * Returns the raw JSON value of [success]. + * + * Unlike [success], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("success") @ExcludeMissing fun _success(): JsonField = success + + /** + * Returns the raw JSON value of [processedDocuments]. + * + * Unlike [processedDocuments], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("processed_documents") + @ExcludeMissing + fun _processedDocuments(): JsonField = processedDocuments + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [MemoryAddResponse]. + * + * The following fields are required: + * ```java + * .contextId() + * .success() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [MemoryAddResponse]. */ + class Builder internal constructor() { + + private var contextId: JsonField? = null + private var success: JsonField? = null + private var processedDocuments: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(memoryAddResponse: MemoryAddResponse) = apply { + contextId = memoryAddResponse.contextId + success = memoryAddResponse.success + processedDocuments = memoryAddResponse.processedDocuments + additionalProperties = memoryAddResponse.additionalProperties.toMutableMap() + } + + fun contextId(contextId: String) = contextId(JsonField.of(contextId)) + + /** + * Sets [Builder.contextId] to an arbitrary JSON value. + * + * You should usually call [Builder.contextId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun contextId(contextId: JsonField) = apply { this.contextId = contextId } + + fun success(success: Boolean) = success(JsonField.of(success)) + + /** + * Sets [Builder.success] to an arbitrary JSON value. + * + * You should usually call [Builder.success] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun success(success: JsonField) = apply { this.success = success } + + fun processedDocuments(processedDocuments: Double) = + processedDocuments(JsonField.of(processedDocuments)) + + /** + * Sets [Builder.processedDocuments] to an arbitrary JSON value. + * + * You should usually call [Builder.processedDocuments] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun processedDocuments(processedDocuments: JsonField) = apply { + this.processedDocuments = processedDocuments + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [MemoryAddResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .contextId() + * .success() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MemoryAddResponse = + MemoryAddResponse( + checkRequired("contextId", contextId), + checkRequired("success", success), + processedDocuments, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): MemoryAddResponse = apply { + if (validated) { + return@apply + } + + contextId() + success() + processedDocuments() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (contextId.asKnown().isPresent) 1 else 0) + + (if (success.asKnown().isPresent) 1 else 0) + + (if (processedDocuments.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is MemoryAddResponse && + contextId == other.contextId && + success == other.success && + processedDocuments == other.processedDocuments && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(contextId, success, processedDocuments, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "MemoryAddResponse{contextId=$contextId, success=$success, processedDocuments=$processedDocuments, additionalProperties=$additionalProperties}" +} diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryDeleteParams.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryDeleteParams.kt index 54ba22a..446433e 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryDeleteParams.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryDeleteParams.kt @@ -7,6 +7,7 @@ import com.alchemystai.sdk.core.JsonField import com.alchemystai.sdk.core.JsonMissing import com.alchemystai.sdk.core.JsonValue import com.alchemystai.sdk.core.Params +import com.alchemystai.sdk.core.checkRequired import com.alchemystai.sdk.core.http.Headers import com.alchemystai.sdk.core.http.QueryParams import com.alchemystai.sdk.errors.AlchemystAiInvalidDataException @@ -19,7 +20,7 @@ import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -/** Deletes memory context data based on provided parameters */ +/** Deletes memory context data based on provided parameters. */ class MemoryDeleteParams private constructor( private val body: Body, @@ -30,18 +31,34 @@ private constructor( /** * The ID of the memory to delete * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun memoryId(): String = body.memoryId() + + /** + * Organization ID + * * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun memoryId(): Optional = body.memoryId() + fun organizationId(): Optional = body.organizationId() /** - * Optional organization ID + * Delete by document flag * * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun organizationId(): Optional = body.organizationId() + fun byDoc(): Optional = body.byDoc() + + /** + * Delete by ID flag + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun byId(): Optional = body.byId() /** * Optional user ID @@ -49,7 +66,7 @@ private constructor( * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the * server responded with an unexpected value). */ - fun userId(): Optional = body.userId() + @Deprecated("deprecated") fun userId(): Optional = body.userId() /** * Returns the raw JSON value of [memoryId]. @@ -65,12 +82,26 @@ private constructor( */ fun _organizationId(): JsonField = body._organizationId() + /** + * Returns the raw JSON value of [byDoc]. + * + * Unlike [byDoc], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _byDoc(): JsonField = body._byDoc() + + /** + * Returns the raw JSON value of [byId]. + * + * Unlike [byId], this method doesn't throw if the JSON field has an unexpected type. + */ + fun _byId(): JsonField = body._byId() + /** * Returns the raw JSON value of [userId]. * * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. */ - fun _userId(): JsonField = body._userId() + @Deprecated("deprecated") fun _userId(): JsonField = body._userId() fun _additionalBodyProperties(): Map = body._additionalProperties() @@ -84,9 +115,15 @@ private constructor( companion object { - @JvmStatic fun none(): MemoryDeleteParams = builder().build() - - /** Returns a mutable builder for constructing an instance of [MemoryDeleteParams]. */ + /** + * Returns a mutable builder for constructing an instance of [MemoryDeleteParams]. + * + * The following fields are required: + * ```java + * .memoryId() + * .organizationId() + * ``` + */ @JvmStatic fun builder() = Builder() } @@ -111,7 +148,10 @@ private constructor( * Otherwise, it's more convenient to use the top-level setters instead: * - [memoryId] * - [organizationId] + * - [byDoc] + * - [byId] * - [userId] + * - etc. */ fun body(body: Body) = apply { this.body = body.toBuilder() } @@ -126,7 +166,7 @@ private constructor( */ fun memoryId(memoryId: JsonField) = apply { body.memoryId(memoryId) } - /** Optional organization ID */ + /** Organization ID */ fun organizationId(organizationId: String?) = apply { body.organizationId(organizationId) } /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */ @@ -144,11 +184,53 @@ private constructor( body.organizationId(organizationId) } + /** Delete by document flag */ + fun byDoc(byDoc: Boolean?) = apply { body.byDoc(byDoc) } + + /** + * Alias for [Builder.byDoc]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun byDoc(byDoc: Boolean) = byDoc(byDoc as Boolean?) + + /** Alias for calling [Builder.byDoc] with `byDoc.orElse(null)`. */ + fun byDoc(byDoc: Optional) = byDoc(byDoc.getOrNull()) + + /** + * Sets [Builder.byDoc] to an arbitrary JSON value. + * + * You should usually call [Builder.byDoc] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun byDoc(byDoc: JsonField) = apply { body.byDoc(byDoc) } + + /** Delete by ID flag */ + fun byId(byId: Boolean?) = apply { body.byId(byId) } + + /** + * Alias for [Builder.byId]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun byId(byId: Boolean) = byId(byId as Boolean?) + + /** Alias for calling [Builder.byId] with `byId.orElse(null)`. */ + fun byId(byId: Optional) = byId(byId.getOrNull()) + + /** + * Sets [Builder.byId] to an arbitrary JSON value. + * + * You should usually call [Builder.byId] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun byId(byId: JsonField) = apply { body.byId(byId) } + /** Optional user ID */ - fun userId(userId: String?) = apply { body.userId(userId) } + @Deprecated("deprecated") fun userId(userId: String?) = apply { body.userId(userId) } /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ - fun userId(userId: Optional) = userId(userId.getOrNull()) + @Deprecated("deprecated") fun userId(userId: Optional) = userId(userId.getOrNull()) /** * Sets [Builder.userId] to an arbitrary JSON value. @@ -156,6 +238,7 @@ private constructor( * You should usually call [Builder.userId] with a well-typed [String] value instead. This * method is primarily for setting the field to an undocumented or not yet supported value. */ + @Deprecated("deprecated") fun userId(userId: JsonField) = apply { body.userId(userId) } fun additionalBodyProperties(additionalBodyProperties: Map) = apply { @@ -279,6 +362,14 @@ private constructor( * Returns an immutable instance of [MemoryDeleteParams]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .memoryId() + * .organizationId() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): MemoryDeleteParams = MemoryDeleteParams( @@ -299,6 +390,8 @@ private constructor( private constructor( private val memoryId: JsonField, private val organizationId: JsonField, + private val byDoc: JsonField, + private val byId: JsonField, private val userId: JsonField, private val additionalProperties: MutableMap, ) { @@ -311,24 +404,42 @@ private constructor( @JsonProperty("organization_id") @ExcludeMissing organizationId: JsonField = JsonMissing.of(), + @JsonProperty("by_doc") @ExcludeMissing byDoc: JsonField = JsonMissing.of(), + @JsonProperty("by_id") @ExcludeMissing byId: JsonField = JsonMissing.of(), @JsonProperty("user_id") @ExcludeMissing userId: JsonField = JsonMissing.of(), - ) : this(memoryId, organizationId, userId, mutableMapOf()) + ) : this(memoryId, organizationId, byDoc, byId, userId, mutableMapOf()) /** * The ID of the memory to delete * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun memoryId(): String = memoryId.getRequired("memoryId") + + /** + * Organization ID + * * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun memoryId(): Optional = memoryId.getOptional("memoryId") + fun organizationId(): Optional = organizationId.getOptional("organization_id") /** - * Optional organization ID + * Delete by document flag * * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun organizationId(): Optional = organizationId.getOptional("organization_id") + fun byDoc(): Optional = byDoc.getOptional("by_doc") + + /** + * Delete by ID flag + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun byId(): Optional = byId.getOptional("by_id") /** * Optional user ID @@ -336,7 +447,7 @@ private constructor( * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ - fun userId(): Optional = userId.getOptional("user_id") + @Deprecated("deprecated") fun userId(): Optional = userId.getOptional("user_id") /** * Returns the raw JSON value of [memoryId]. @@ -355,12 +466,29 @@ private constructor( @ExcludeMissing fun _organizationId(): JsonField = organizationId + /** + * Returns the raw JSON value of [byDoc]. + * + * Unlike [byDoc], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("by_doc") @ExcludeMissing fun _byDoc(): JsonField = byDoc + + /** + * Returns the raw JSON value of [byId]. + * + * Unlike [byId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("by_id") @ExcludeMissing fun _byId(): JsonField = byId + /** * Returns the raw JSON value of [userId]. * * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("user_id") @ExcludeMissing fun _userId(): JsonField = userId + @Deprecated("deprecated") + @JsonProperty("user_id") + @ExcludeMissing + fun _userId(): JsonField = userId @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -376,15 +504,25 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Body]. */ + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .memoryId() + * .organizationId() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Body]. */ class Builder internal constructor() { - private var memoryId: JsonField = JsonMissing.of() - private var organizationId: JsonField = JsonMissing.of() + private var memoryId: JsonField? = null + private var organizationId: JsonField? = null + private var byDoc: JsonField = JsonMissing.of() + private var byId: JsonField = JsonMissing.of() private var userId: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @@ -392,6 +530,8 @@ private constructor( internal fun from(body: Body) = apply { memoryId = body.memoryId organizationId = body.organizationId + byDoc = body.byDoc + byId = body.byId userId = body.userId additionalProperties = body.additionalProperties.toMutableMap() } @@ -408,7 +548,7 @@ private constructor( */ fun memoryId(memoryId: JsonField) = apply { this.memoryId = memoryId } - /** Optional organization ID */ + /** Organization ID */ fun organizationId(organizationId: String?) = organizationId(JsonField.ofNullable(organizationId)) @@ -427,10 +567,56 @@ private constructor( this.organizationId = organizationId } + /** Delete by document flag */ + fun byDoc(byDoc: Boolean?) = byDoc(JsonField.ofNullable(byDoc)) + + /** + * Alias for [Builder.byDoc]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun byDoc(byDoc: Boolean) = byDoc(byDoc as Boolean?) + + /** Alias for calling [Builder.byDoc] with `byDoc.orElse(null)`. */ + fun byDoc(byDoc: Optional) = byDoc(byDoc.getOrNull()) + + /** + * Sets [Builder.byDoc] to an arbitrary JSON value. + * + * You should usually call [Builder.byDoc] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun byDoc(byDoc: JsonField) = apply { this.byDoc = byDoc } + + /** Delete by ID flag */ + fun byId(byId: Boolean?) = byId(JsonField.ofNullable(byId)) + + /** + * Alias for [Builder.byId]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun byId(byId: Boolean) = byId(byId as Boolean?) + + /** Alias for calling [Builder.byId] with `byId.orElse(null)`. */ + fun byId(byId: Optional) = byId(byId.getOrNull()) + + /** + * Sets [Builder.byId] to an arbitrary JSON value. + * + * You should usually call [Builder.byId] with a well-typed [Boolean] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun byId(byId: JsonField) = apply { this.byId = byId } + /** Optional user ID */ + @Deprecated("deprecated") fun userId(userId: String?) = userId(JsonField.ofNullable(userId)) /** Alias for calling [Builder.userId] with `userId.orElse(null)`. */ + @Deprecated("deprecated") fun userId(userId: Optional) = userId(userId.getOrNull()) /** @@ -440,6 +626,7 @@ private constructor( * This method is primarily for setting the field to an undocumented or not yet * supported value. */ + @Deprecated("deprecated") fun userId(userId: JsonField) = apply { this.userId = userId } fun additionalProperties(additionalProperties: Map) = apply { @@ -465,9 +652,24 @@ private constructor( * Returns an immutable instance of [Body]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .memoryId() + * .organizationId() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): Body = - Body(memoryId, organizationId, userId, additionalProperties.toMutableMap()) + Body( + checkRequired("memoryId", memoryId), + checkRequired("organizationId", organizationId), + byDoc, + byId, + userId, + additionalProperties.toMutableMap(), + ) } private var validated: Boolean = false @@ -479,6 +681,8 @@ private constructor( memoryId() organizationId() + byDoc() + byId() userId() validated = true } @@ -501,6 +705,8 @@ private constructor( internal fun validity(): Int = (if (memoryId.asKnown().isPresent) 1 else 0) + (if (organizationId.asKnown().isPresent) 1 else 0) + + (if (byDoc.asKnown().isPresent) 1 else 0) + + (if (byId.asKnown().isPresent) 1 else 0) + (if (userId.asKnown().isPresent) 1 else 0) override fun equals(other: Any?): Boolean { @@ -511,18 +717,20 @@ private constructor( return other is Body && memoryId == other.memoryId && organizationId == other.organizationId && + byDoc == other.byDoc && + byId == other.byId && userId == other.userId && additionalProperties == other.additionalProperties } private val hashCode: Int by lazy { - Objects.hash(memoryId, organizationId, userId, additionalProperties) + Objects.hash(memoryId, organizationId, byDoc, byId, userId, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "Body{memoryId=$memoryId, organizationId=$organizationId, userId=$userId, additionalProperties=$additionalProperties}" + "Body{memoryId=$memoryId, organizationId=$organizationId, byDoc=$byDoc, byId=$byId, userId=$userId, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryUpdateParams.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryUpdateParams.kt index a932a96..ab4fc15 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryUpdateParams.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryUpdateParams.kt @@ -8,6 +8,7 @@ import com.alchemystai.sdk.core.JsonMissing import com.alchemystai.sdk.core.JsonValue import com.alchemystai.sdk.core.Params import com.alchemystai.sdk.core.checkKnown +import com.alchemystai.sdk.core.checkRequired import com.alchemystai.sdk.core.http.Headers import com.alchemystai.sdk.core.http.QueryParams import com.alchemystai.sdk.core.toImmutable @@ -32,18 +33,18 @@ private constructor( /** * Array of updated content objects * - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun contents(): Optional> = body.contents() + fun contents(): List = body.contents() /** * The ID of the memory to update * - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun memoryId(): Optional = body.memoryId() + fun sessionId(): String = body.sessionId() /** * Returns the raw JSON value of [contents]. @@ -53,11 +54,11 @@ private constructor( fun _contents(): JsonField> = body._contents() /** - * Returns the raw JSON value of [memoryId]. + * Returns the raw JSON value of [sessionId]. * - * Unlike [memoryId], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [sessionId], this method doesn't throw if the JSON field has an unexpected type. */ - fun _memoryId(): JsonField = body._memoryId() + fun _sessionId(): JsonField = body._sessionId() fun _additionalBodyProperties(): Map = body._additionalProperties() @@ -71,9 +72,15 @@ private constructor( companion object { - @JvmStatic fun none(): MemoryUpdateParams = builder().build() - - /** Returns a mutable builder for constructing an instance of [MemoryUpdateParams]. */ + /** + * Returns a mutable builder for constructing an instance of [MemoryUpdateParams]. + * + * The following fields are required: + * ```java + * .contents() + * .sessionId() + * ``` + */ @JvmStatic fun builder() = Builder() } @@ -97,7 +104,7 @@ private constructor( * This is generally only useful if you are already constructing the body separately. * Otherwise, it's more convenient to use the top-level setters instead: * - [contents] - * - [memoryId] + * - [sessionId] */ fun body(body: Body) = apply { this.body = body.toBuilder() } @@ -121,15 +128,16 @@ private constructor( fun addContent(content: Content) = apply { body.addContent(content) } /** The ID of the memory to update */ - fun memoryId(memoryId: String) = apply { body.memoryId(memoryId) } + fun sessionId(sessionId: String) = apply { body.sessionId(sessionId) } /** - * Sets [Builder.memoryId] to an arbitrary JSON value. + * Sets [Builder.sessionId] to an arbitrary JSON value. * - * You should usually call [Builder.memoryId] with a well-typed [String] value instead. This - * method is primarily for setting the field to an undocumented or not yet supported value. + * You should usually call [Builder.sessionId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. */ - fun memoryId(memoryId: JsonField) = apply { body.memoryId(memoryId) } + fun sessionId(sessionId: JsonField) = apply { body.sessionId(sessionId) } fun additionalBodyProperties(additionalBodyProperties: Map) = apply { body.additionalProperties(additionalBodyProperties) @@ -252,6 +260,14 @@ private constructor( * Returns an immutable instance of [MemoryUpdateParams]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .contents() + * .sessionId() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): MemoryUpdateParams = MemoryUpdateParams( @@ -271,7 +287,7 @@ private constructor( @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( private val contents: JsonField>, - private val memoryId: JsonField, + private val sessionId: JsonField, private val additionalProperties: MutableMap, ) { @@ -280,24 +296,26 @@ private constructor( @JsonProperty("contents") @ExcludeMissing contents: JsonField> = JsonMissing.of(), - @JsonProperty("memoryId") @ExcludeMissing memoryId: JsonField = JsonMissing.of(), - ) : this(contents, memoryId, mutableMapOf()) + @JsonProperty("sessionId") + @ExcludeMissing + sessionId: JsonField = JsonMissing.of(), + ) : this(contents, sessionId, mutableMapOf()) /** * Array of updated content objects * - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun contents(): Optional> = contents.getOptional("contents") + fun contents(): List = contents.getRequired("contents") /** * The ID of the memory to update * - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun memoryId(): Optional = memoryId.getOptional("memoryId") + fun sessionId(): String = sessionId.getRequired("sessionId") /** * Returns the raw JSON value of [contents]. @@ -309,11 +327,11 @@ private constructor( fun _contents(): JsonField> = contents /** - * Returns the raw JSON value of [memoryId]. + * Returns the raw JSON value of [sessionId]. * - * Unlike [memoryId], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [sessionId], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("memoryId") @ExcludeMissing fun _memoryId(): JsonField = memoryId + @JsonProperty("sessionId") @ExcludeMissing fun _sessionId(): JsonField = sessionId @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -329,7 +347,15 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Body]. */ + /** + * Returns a mutable builder for constructing an instance of [Body]. + * + * The following fields are required: + * ```java + * .contents() + * .sessionId() + * ``` + */ @JvmStatic fun builder() = Builder() } @@ -337,13 +363,13 @@ private constructor( class Builder internal constructor() { private var contents: JsonField>? = null - private var memoryId: JsonField = JsonMissing.of() + private var sessionId: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(body: Body) = apply { contents = body.contents.map { it.toMutableList() } - memoryId = body.memoryId + sessionId = body.sessionId additionalProperties = body.additionalProperties.toMutableMap() } @@ -374,16 +400,16 @@ private constructor( } /** The ID of the memory to update */ - fun memoryId(memoryId: String) = memoryId(JsonField.of(memoryId)) + fun sessionId(sessionId: String) = sessionId(JsonField.of(sessionId)) /** - * Sets [Builder.memoryId] to an arbitrary JSON value. + * Sets [Builder.sessionId] to an arbitrary JSON value. * - * You should usually call [Builder.memoryId] with a well-typed [String] value instead. + * You should usually call [Builder.sessionId] with a well-typed [String] value instead. * This method is primarily for setting the field to an undocumented or not yet * supported value. */ - fun memoryId(memoryId: JsonField) = apply { this.memoryId = memoryId } + fun sessionId(sessionId: JsonField) = apply { this.sessionId = sessionId } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -408,11 +434,19 @@ private constructor( * Returns an immutable instance of [Body]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .contents() + * .sessionId() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): Body = Body( - (contents ?: JsonMissing.of()).map { it.toImmutable() }, - memoryId, + checkRequired("contents", contents).map { it.toImmutable() }, + checkRequired("sessionId", sessionId), additionalProperties.toMutableMap(), ) } @@ -424,8 +458,8 @@ private constructor( return@apply } - contents().ifPresent { it.forEach { it.validate() } } - memoryId() + contents().forEach { it.validate() } + sessionId() validated = true } @@ -446,7 +480,7 @@ private constructor( @JvmSynthetic internal fun validity(): Int = (contents.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + - (if (memoryId.asKnown().isPresent) 1 else 0) + (if (sessionId.asKnown().isPresent) 1 else 0) override fun equals(other: Any?): Boolean { if (this === other) { @@ -455,36 +489,91 @@ private constructor( return other is Body && contents == other.contents && - memoryId == other.memoryId && + sessionId == other.sessionId && additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { Objects.hash(contents, memoryId, additionalProperties) } + private val hashCode: Int by lazy { + Objects.hash(contents, sessionId, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "Body{contents=$contents, memoryId=$memoryId, additionalProperties=$additionalProperties}" + "Body{contents=$contents, sessionId=$sessionId, additionalProperties=$additionalProperties}" } class Content @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( + private val id: JsonField, private val content: JsonField, + private val createdAt: JsonField, + private val metadata: JsonField, + private val role: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("content") @ExcludeMissing content: JsonField = JsonMissing.of() - ) : this(content, mutableMapOf()) + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("content") @ExcludeMissing content: JsonField = JsonMissing.of(), + @JsonProperty("createdAt") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + @JsonProperty("role") @ExcludeMissing role: JsonField = JsonMissing.of(), + ) : this(id, content, createdAt, metadata, role, mutableMapOf()) /** + * Unique ID for the message + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun id(): Optional = id.getOptional("id") + + /** + * The content of the memory entry + * * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if * the server responded with an unexpected value). */ fun content(): Optional = content.getOptional("content") + /** + * Creation timestamp + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("createdAt") + + /** + * Additional metadata for the memory entry + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Optional = metadata.getOptional("metadata") + + /** + * Role of the message (e.g., user, assistant) + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun role(): Optional = role.getOptional("role") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + /** * Returns the raw JSON value of [content]. * @@ -492,6 +581,27 @@ private constructor( */ @JsonProperty("content") @ExcludeMissing fun _content(): JsonField = content + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("createdAt") @ExcludeMissing fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + + /** + * Returns the raw JSON value of [role]. + * + * Unlike [role], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("role") @ExcludeMissing fun _role(): JsonField = role + @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { additionalProperties.put(key, value) @@ -513,15 +623,36 @@ private constructor( /** A builder for [Content]. */ class Builder internal constructor() { + private var id: JsonField = JsonMissing.of() private var content: JsonField = JsonMissing.of() + private var createdAt: JsonField = JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var role: JsonField = JsonMissing.of() private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(content: Content) = apply { + id = content.id this.content = content.content + createdAt = content.createdAt + metadata = content.metadata + role = content.role additionalProperties = content.additionalProperties.toMutableMap() } + /** Unique ID for the message */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** The content of the memory entry */ fun content(content: String) = content(JsonField.of(content)) /** @@ -533,6 +664,42 @@ private constructor( */ fun content(content: JsonField) = apply { this.content = content } + /** Creation timestamp */ + fun createdAt(createdAt: String) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** Additional metadata for the memory entry */ + fun metadata(metadata: Metadata) = metadata(JsonField.of(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + /** Role of the message (e.g., user, assistant) */ + fun role(role: String) = role(JsonField.of(role)) + + /** + * Sets [Builder.role] to an arbitrary JSON value. + * + * You should usually call [Builder.role] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun role(role: JsonField) = apply { this.role = role } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -557,7 +724,8 @@ private constructor( * * Further updates to this [Builder] will not mutate the returned instance. */ - fun build(): Content = Content(content, additionalProperties.toMutableMap()) + fun build(): Content = + Content(id, content, createdAt, metadata, role, additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -567,7 +735,11 @@ private constructor( return@apply } + id() content() + createdAt() + metadata().ifPresent { it.validate() } + role() validated = true } @@ -585,7 +757,116 @@ private constructor( * * Used for best match union deserialization. */ - @JvmSynthetic internal fun validity(): Int = (if (content.asKnown().isPresent) 1 else 0) + @JvmSynthetic + internal fun validity(): Int = + (if (id.asKnown().isPresent) 1 else 0) + + (if (content.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + (if (role.asKnown().isPresent) 1 else 0) + + /** Additional metadata for the memory entry */ + class Metadata + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(metadata: Metadata) = apply { + additionalProperties = metadata.additionalProperties.toMutableMap() + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = Metadata(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Metadata && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Metadata{additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { @@ -593,16 +874,22 @@ private constructor( } return other is Content && + id == other.id && content == other.content && + createdAt == other.createdAt && + metadata == other.metadata && + role == other.role && additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { Objects.hash(content, additionalProperties) } + private val hashCode: Int by lazy { + Objects.hash(id, content, createdAt, metadata, role, additionalProperties) + } override fun hashCode(): Int = hashCode override fun toString() = - "Content{content=$content, additionalProperties=$additionalProperties}" + "Content{id=$id, content=$content, createdAt=$createdAt, metadata=$metadata, role=$role, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryUpdateResponse.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryUpdateResponse.kt new file mode 100644 index 0000000..0365cd5 --- /dev/null +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryUpdateResponse.kt @@ -0,0 +1,247 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.models.v1.context.memory + +import com.alchemystai.sdk.core.ExcludeMissing +import com.alchemystai.sdk.core.JsonField +import com.alchemystai.sdk.core.JsonMissing +import com.alchemystai.sdk.core.JsonValue +import com.alchemystai.sdk.core.checkRequired +import com.alchemystai.sdk.errors.AlchemystAiInvalidDataException +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 MemoryUpdateResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val memoryId: JsonField, + private val success: JsonField, + private val updatedEntries: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("memory_id") @ExcludeMissing memoryId: JsonField = JsonMissing.of(), + @JsonProperty("success") @ExcludeMissing success: JsonField = JsonMissing.of(), + @JsonProperty("updated_entries") + @ExcludeMissing + updatedEntries: JsonField = JsonMissing.of(), + ) : this(memoryId, success, updatedEntries, mutableMapOf()) + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun memoryId(): String = memoryId.getRequired("memory_id") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun success(): Boolean = success.getRequired("success") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun updatedEntries(): Double = updatedEntries.getRequired("updated_entries") + + /** + * Returns the raw JSON value of [memoryId]. + * + * Unlike [memoryId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("memory_id") @ExcludeMissing fun _memoryId(): JsonField = memoryId + + /** + * Returns the raw JSON value of [success]. + * + * Unlike [success], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("success") @ExcludeMissing fun _success(): JsonField = success + + /** + * Returns the raw JSON value of [updatedEntries]. + * + * Unlike [updatedEntries], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("updated_entries") + @ExcludeMissing + fun _updatedEntries(): JsonField = updatedEntries + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [MemoryUpdateResponse]. + * + * The following fields are required: + * ```java + * .memoryId() + * .success() + * .updatedEntries() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [MemoryUpdateResponse]. */ + class Builder internal constructor() { + + private var memoryId: JsonField? = null + private var success: JsonField? = null + private var updatedEntries: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(memoryUpdateResponse: MemoryUpdateResponse) = apply { + memoryId = memoryUpdateResponse.memoryId + success = memoryUpdateResponse.success + updatedEntries = memoryUpdateResponse.updatedEntries + additionalProperties = memoryUpdateResponse.additionalProperties.toMutableMap() + } + + fun memoryId(memoryId: String) = memoryId(JsonField.of(memoryId)) + + /** + * Sets [Builder.memoryId] to an arbitrary JSON value. + * + * You should usually call [Builder.memoryId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun memoryId(memoryId: JsonField) = apply { this.memoryId = memoryId } + + fun success(success: Boolean) = success(JsonField.of(success)) + + /** + * Sets [Builder.success] to an arbitrary JSON value. + * + * You should usually call [Builder.success] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun success(success: JsonField) = apply { this.success = success } + + fun updatedEntries(updatedEntries: Double) = updatedEntries(JsonField.of(updatedEntries)) + + /** + * Sets [Builder.updatedEntries] to an arbitrary JSON value. + * + * You should usually call [Builder.updatedEntries] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun updatedEntries(updatedEntries: JsonField) = apply { + this.updatedEntries = updatedEntries + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [MemoryUpdateResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .memoryId() + * .success() + * .updatedEntries() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): MemoryUpdateResponse = + MemoryUpdateResponse( + checkRequired("memoryId", memoryId), + checkRequired("success", success), + checkRequired("updatedEntries", updatedEntries), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): MemoryUpdateResponse = apply { + if (validated) { + return@apply + } + + memoryId() + success() + updatedEntries() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (memoryId.asKnown().isPresent) 1 else 0) + + (if (success.asKnown().isPresent) 1 else 0) + + (if (updatedEntries.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is MemoryUpdateResponse && + memoryId == other.memoryId && + success == other.success && + updatedEntries == other.updatedEntries && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(memoryId, success, updatedEntries, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "MemoryUpdateResponse{memoryId=$memoryId, success=$success, updatedEntries=$updatedEntries, additionalProperties=$additionalProperties}" +} diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceDeleteParams.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceDeleteParams.kt index 831c3c8..4a35757 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceDeleteParams.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceDeleteParams.kt @@ -11,7 +11,7 @@ import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -/** Deletes a data trace for the authenticated user with the specified trace ID */ +/** Deletes a data trace for the authenticated user with the specified trace ID. */ class TraceDeleteParams private constructor( private val traceId: String?, diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceDeleteResponse.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceDeleteResponse.kt index ac12495..bcd3d1b 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceDeleteResponse.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceDeleteResponse.kt @@ -3,30 +3,47 @@ package com.alchemystai.sdk.models.v1.context.traces import com.alchemystai.sdk.core.ExcludeMissing +import com.alchemystai.sdk.core.JsonField import com.alchemystai.sdk.core.JsonMissing import com.alchemystai.sdk.core.JsonValue +import com.alchemystai.sdk.core.checkRequired import com.alchemystai.sdk.errors.AlchemystAiInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter import com.fasterxml.jackson.annotation.JsonAnySetter import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import java.time.OffsetDateTime import java.util.Collections import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull class TraceDeleteResponse @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val trace: JsonValue, + private val trace: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("trace") @ExcludeMissing trace: JsonValue = JsonMissing.of() + @JsonProperty("trace") @ExcludeMissing trace: JsonField = JsonMissing.of() ) : this(trace, mutableMapOf()) - /** The deleted trace data */ - @JsonProperty("trace") @ExcludeMissing fun _trace(): JsonValue = trace + /** + * The deleted trace data + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun trace(): Trace = trace.getRequired("trace") + + /** + * Returns the raw JSON value of [trace]. + * + * Unlike [trace], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("trace") @ExcludeMissing fun _trace(): JsonField = trace @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -42,14 +59,21 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [TraceDeleteResponse]. */ + /** + * Returns a mutable builder for constructing an instance of [TraceDeleteResponse]. + * + * The following fields are required: + * ```java + * .trace() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [TraceDeleteResponse]. */ class Builder internal constructor() { - private var trace: JsonValue = JsonMissing.of() + private var trace: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -59,7 +83,15 @@ private constructor( } /** The deleted trace data */ - fun trace(trace: JsonValue) = apply { this.trace = trace } + fun trace(trace: Trace) = trace(JsonField.of(trace)) + + /** + * Sets [Builder.trace] to an arbitrary JSON value. + * + * You should usually call [Builder.trace] with a well-typed [Trace] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun trace(trace: JsonField) = apply { this.trace = trace } fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() @@ -84,9 +116,16 @@ private constructor( * Returns an immutable instance of [TraceDeleteResponse]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .trace() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): TraceDeleteResponse = - TraceDeleteResponse(trace, additionalProperties.toMutableMap()) + TraceDeleteResponse(checkRequired("trace", trace), additionalProperties.toMutableMap()) } private var validated: Boolean = false @@ -96,6 +135,7 @@ private constructor( return@apply } + trace().validate() validated = true } @@ -112,7 +152,586 @@ private constructor( * * Used for best match union deserialization. */ - @JvmSynthetic internal fun validity(): Int = 0 + @JvmSynthetic internal fun validity(): Int = (trace.asKnown().getOrNull()?.validity() ?: 0) + + /** The deleted trace data */ + class Trace + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val _id: JsonField, + private val createdAt: JsonField, + private val data: JsonField, + private val organizationId: JsonField, + private val type: JsonField, + private val updatedAt: JsonField, + private val userId: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("_id") @ExcludeMissing _id: JsonField = JsonMissing.of(), + @JsonProperty("createdAt") + @ExcludeMissing + createdAt: JsonField = JsonMissing.of(), + @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of(), + @JsonProperty("organizationId") + @ExcludeMissing + organizationId: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("updatedAt") + @ExcludeMissing + updatedAt: JsonField = JsonMissing.of(), + @JsonProperty("userId") @ExcludeMissing userId: JsonField = JsonMissing.of(), + ) : this(_id, createdAt, data, organizationId, type, updatedAt, userId, mutableMapOf()) + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun _id(): Optional = _id.getOptional("_id") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("createdAt") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun data(): Optional = data.getOptional("data") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun organizationId(): Optional = organizationId.getOptional("organizationId") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun type(): Optional = type.getOptional("type") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun updatedAt(): Optional = updatedAt.getOptional("updatedAt") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun userId(): Optional = userId.getOptional("userId") + + /** + * Returns the raw JSON value of [_id]. + * + * Unlike [_id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("_id") @ExcludeMissing fun __id(): JsonField = _id + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("createdAt") + @ExcludeMissing + fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [data]. + * + * Unlike [data], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("data") @ExcludeMissing fun _data(): JsonField = data + + /** + * Returns the raw JSON value of [organizationId]. + * + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("organizationId") + @ExcludeMissing + fun _organizationId(): JsonField = organizationId + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + /** + * Returns the raw JSON value of [updatedAt]. + * + * Unlike [updatedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("updatedAt") + @ExcludeMissing + fun _updatedAt(): JsonField = updatedAt + + /** + * Returns the raw JSON value of [userId]. + * + * Unlike [userId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("userId") @ExcludeMissing fun _userId(): JsonField = userId + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Trace]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Trace]. */ + class Builder internal constructor() { + + private var _id: JsonField = JsonMissing.of() + private var createdAt: JsonField = JsonMissing.of() + private var data: JsonField = JsonMissing.of() + private var organizationId: JsonField = JsonMissing.of() + private var type: JsonField = JsonMissing.of() + private var updatedAt: JsonField = JsonMissing.of() + private var userId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(trace: Trace) = apply { + _id = trace._id + createdAt = trace.createdAt + data = trace.data + organizationId = trace.organizationId + type = trace.type + updatedAt = trace.updatedAt + userId = trace.userId + additionalProperties = trace.additionalProperties.toMutableMap() + } + + fun _id(_id: String) = _id(JsonField.of(_id)) + + /** + * Sets [Builder._id] to an arbitrary JSON value. + * + * You should usually call [Builder._id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun _id(_id: JsonField) = apply { this._id = _id } + + fun createdAt(createdAt: OffsetDateTime) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun createdAt(createdAt: JsonField) = apply { + this.createdAt = createdAt + } + + fun data(data: Data) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed [Data] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun data(data: JsonField) = apply { this.data = data } + + fun organizationId(organizationId: String) = + organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + + fun type(type: String) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun type(type: JsonField) = apply { this.type = type } + + fun updatedAt(updatedAt: OffsetDateTime) = updatedAt(JsonField.of(updatedAt)) + + /** + * Sets [Builder.updatedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.updatedAt] with a well-typed [OffsetDateTime] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun updatedAt(updatedAt: JsonField) = apply { + this.updatedAt = updatedAt + } + + fun userId(userId: String) = userId(JsonField.of(userId)) + + /** + * Sets [Builder.userId] to an arbitrary JSON value. + * + * You should usually call [Builder.userId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun userId(userId: JsonField) = apply { this.userId = userId } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Trace]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Trace = + Trace( + _id, + createdAt, + data, + organizationId, + type, + updatedAt, + userId, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Trace = apply { + if (validated) { + return@apply + } + + _id() + createdAt() + data().ifPresent { it.validate() } + organizationId() + type() + updatedAt() + userId() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (_id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (data.asKnown().getOrNull()?.validity() ?: 0) + + (if (organizationId.asKnown().isPresent) 1 else 0) + + (if (type.asKnown().isPresent) 1 else 0) + + (if (updatedAt.asKnown().isPresent) 1 else 0) + + (if (userId.asKnown().isPresent) 1 else 0) + + class Data + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val fileName: JsonField, + private val query: JsonField, + private val source: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("fileName") + @ExcludeMissing + fileName: JsonField = JsonMissing.of(), + @JsonProperty("query") @ExcludeMissing query: JsonField = JsonMissing.of(), + @JsonProperty("source") @ExcludeMissing source: JsonField = JsonMissing.of(), + ) : this(fileName, query, source, mutableMapOf()) + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun fileName(): Optional = fileName.getOptional("fileName") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun query(): Optional = query.getOptional("query") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun source(): Optional = source.getOptional("source") + + /** + * Returns the raw JSON value of [fileName]. + * + * Unlike [fileName], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("fileName") @ExcludeMissing fun _fileName(): JsonField = fileName + + /** + * Returns the raw JSON value of [query]. + * + * Unlike [query], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("query") @ExcludeMissing fun _query(): JsonField = query + + /** + * Returns the raw JSON value of [source]. + * + * Unlike [source], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("source") @ExcludeMissing fun _source(): JsonField = source + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Data]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Data]. */ + class Builder internal constructor() { + + private var fileName: JsonField = JsonMissing.of() + private var query: JsonField = JsonMissing.of() + private var source: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(data: Data) = apply { + fileName = data.fileName + query = data.query + source = data.source + additionalProperties = data.additionalProperties.toMutableMap() + } + + fun fileName(fileName: String) = fileName(JsonField.of(fileName)) + + /** + * Sets [Builder.fileName] to an arbitrary JSON value. + * + * You should usually call [Builder.fileName] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun fileName(fileName: JsonField) = apply { this.fileName = fileName } + + fun query(query: String) = query(JsonField.of(query)) + + /** + * Sets [Builder.query] to an arbitrary JSON value. + * + * You should usually call [Builder.query] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun query(query: JsonField) = apply { this.query = query } + + fun source(source: String) = source(JsonField.of(source)) + + /** + * Sets [Builder.source] to an arbitrary JSON value. + * + * You should usually call [Builder.source] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun source(source: JsonField) = apply { this.source = source } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Data]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Data = + Data(fileName, query, source, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Data = apply { + if (validated) { + return@apply + } + + fileName() + query() + source() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (fileName.asKnown().isPresent) 1 else 0) + + (if (query.asKnown().isPresent) 1 else 0) + + (if (source.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Data && + fileName == other.fileName && + query == other.query && + source == other.source && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(fileName, query, source, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Data{fileName=$fileName, query=$query, source=$source, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Trace && + _id == other._id && + createdAt == other.createdAt && + data == other.data && + organizationId == other.organizationId && + type == other.type && + updatedAt == other.updatedAt && + userId == other.userId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + _id, + createdAt, + data, + organizationId, + type, + updatedAt, + userId, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Trace{_id=$_id, createdAt=$createdAt, data=$data, organizationId=$organizationId, type=$type, updatedAt=$updatedAt, userId=$userId, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceListParams.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceListParams.kt index e464e29..15b3ca9 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceListParams.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceListParams.kt @@ -6,14 +6,24 @@ import com.alchemystai.sdk.core.Params import com.alchemystai.sdk.core.http.Headers import com.alchemystai.sdk.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull -/** Retrieves a list of traces for the authenticated user */ +/** Returns paginated traces for the authenticated user within their organization. */ class TraceListParams private constructor( + private val limit: Long?, + private val page: Long?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { + /** Number of traces per page */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** Page number for pagination */ + fun page(): Optional = Optional.ofNullable(page) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders @@ -33,15 +43,45 @@ private constructor( /** A builder for [TraceListParams]. */ class Builder internal constructor() { + private var limit: Long? = null + private var page: Long? = null private var additionalHeaders: Headers.Builder = Headers.builder() private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(traceListParams: TraceListParams) = apply { + limit = traceListParams.limit + page = traceListParams.page additionalHeaders = traceListParams.additionalHeaders.toBuilder() additionalQueryParams = traceListParams.additionalQueryParams.toBuilder() } + /** Number of traces per page */ + fun limit(limit: Long?) = apply { this.limit = limit } + + /** + * Alias for [Builder.limit]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun limit(limit: Long) = limit(limit as Long?) + + /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ + fun limit(limit: Optional) = limit(limit.getOrNull()) + + /** Page number for pagination */ + fun page(page: Long?) = apply { this.page = page } + + /** + * Alias for [Builder.page]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun page(page: Long) = page(page as Long?) + + /** Alias for calling [Builder.page] with `page.orElse(null)`. */ + fun page(page: Optional) = page(page.getOrNull()) + fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() putAllAdditionalHeaders(additionalHeaders) @@ -146,12 +186,19 @@ private constructor( * Further updates to this [Builder] will not mutate the returned instance. */ fun build(): TraceListParams = - TraceListParams(additionalHeaders.build(), additionalQueryParams.build()) + TraceListParams(limit, page, additionalHeaders.build(), additionalQueryParams.build()) } override fun _headers(): Headers = additionalHeaders - override fun _queryParams(): QueryParams = additionalQueryParams + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + limit?.let { put("limit", it.toString()) } + page?.let { put("page", it.toString()) } + putAll(additionalQueryParams) + } + .build() override fun equals(other: Any?): Boolean { if (this === other) { @@ -159,12 +206,15 @@ private constructor( } return other is TraceListParams && + limit == other.limit && + page == other.page && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = Objects.hash(additionalHeaders, additionalQueryParams) + override fun hashCode(): Int = + Objects.hash(limit, page, additionalHeaders, additionalQueryParams) override fun toString() = - "TraceListParams{additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" + "TraceListParams{limit=$limit, page=$page, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceListResponse.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceListResponse.kt index 9a45c67..ac8200d 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceListResponse.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceListResponse.kt @@ -7,6 +7,7 @@ import com.alchemystai.sdk.core.JsonField import com.alchemystai.sdk.core.JsonMissing import com.alchemystai.sdk.core.JsonValue import com.alchemystai.sdk.core.checkKnown +import com.alchemystai.sdk.core.checkRequired import com.alchemystai.sdk.core.toImmutable import com.alchemystai.sdk.errors.AlchemystAiInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter @@ -16,26 +17,44 @@ import com.fasterxml.jackson.annotation.JsonProperty import java.time.OffsetDateTime import java.util.Collections import java.util.Objects -import java.util.Optional import kotlin.jvm.optionals.getOrNull class TraceListResponse @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( + private val pagination: JsonField, private val traces: JsonField>, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("traces") @ExcludeMissing traces: JsonField> = JsonMissing.of() - ) : this(traces, mutableMapOf()) + @JsonProperty("pagination") + @ExcludeMissing + pagination: JsonField = JsonMissing.of(), + @JsonProperty("traces") @ExcludeMissing traces: JsonField> = JsonMissing.of(), + ) : this(pagination, traces, mutableMapOf()) + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun pagination(): Pagination = pagination.getRequired("pagination") /** - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun traces(): List = traces.getRequired("traces") + + /** + * Returns the raw JSON value of [pagination]. + * + * Unlike [pagination], this method doesn't throw if the JSON field has an unexpected type. */ - fun traces(): Optional> = traces.getOptional("traces") + @JsonProperty("pagination") + @ExcludeMissing + fun _pagination(): JsonField = pagination /** * Returns the raw JSON value of [traces]. @@ -58,22 +77,43 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [TraceListResponse]. */ + /** + * Returns a mutable builder for constructing an instance of [TraceListResponse]. + * + * The following fields are required: + * ```java + * .pagination() + * .traces() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [TraceListResponse]. */ class Builder internal constructor() { + private var pagination: JsonField? = null private var traces: JsonField>? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(traceListResponse: TraceListResponse) = apply { + pagination = traceListResponse.pagination traces = traceListResponse.traces.map { it.toMutableList() } additionalProperties = traceListResponse.additionalProperties.toMutableMap() } + fun pagination(pagination: Pagination) = pagination(JsonField.of(pagination)) + + /** + * Sets [Builder.pagination] to an arbitrary JSON value. + * + * You should usually call [Builder.pagination] with a well-typed [Pagination] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun pagination(pagination: JsonField) = apply { this.pagination = pagination } + fun traces(traces: List) = traces(JsonField.of(traces)) /** @@ -122,10 +162,19 @@ private constructor( * Returns an immutable instance of [TraceListResponse]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .pagination() + * .traces() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): TraceListResponse = TraceListResponse( - (traces ?: JsonMissing.of()).map { it.toImmutable() }, + checkRequired("pagination", pagination), + checkRequired("traces", traces).map { it.toImmutable() }, additionalProperties.toMutableMap(), ) } @@ -137,7 +186,8 @@ private constructor( return@apply } - traces().ifPresent { it.forEach { it.validate() } } + pagination().validate() + traces().forEach { it.validate() } validated = true } @@ -156,7 +206,360 @@ private constructor( */ @JvmSynthetic internal fun validity(): Int = - (traces.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + (pagination.asKnown().getOrNull()?.validity() ?: 0) + + (traces.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + class Pagination + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val hasNextPage: JsonField, + private val hasPrevPage: JsonField, + private val limit: JsonField, + private val page: JsonField, + private val total: JsonField, + private val totalPages: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("hasNextPage") + @ExcludeMissing + hasNextPage: JsonField = JsonMissing.of(), + @JsonProperty("hasPrevPage") + @ExcludeMissing + hasPrevPage: JsonField = JsonMissing.of(), + @JsonProperty("limit") @ExcludeMissing limit: JsonField = JsonMissing.of(), + @JsonProperty("page") @ExcludeMissing page: JsonField = JsonMissing.of(), + @JsonProperty("total") @ExcludeMissing total: JsonField = JsonMissing.of(), + @JsonProperty("totalPages") + @ExcludeMissing + totalPages: JsonField = JsonMissing.of(), + ) : this(hasNextPage, hasPrevPage, limit, page, total, totalPages, mutableMapOf()) + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun hasNextPage(): Boolean = hasNextPage.getRequired("hasNextPage") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun hasPrevPage(): Boolean = hasPrevPage.getRequired("hasPrevPage") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun limit(): Long = limit.getRequired("limit") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun page(): Long = page.getRequired("page") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun total(): Long = total.getRequired("total") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun totalPages(): Long = totalPages.getRequired("totalPages") + + /** + * Returns the raw JSON value of [hasNextPage]. + * + * Unlike [hasNextPage], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("hasNextPage") + @ExcludeMissing + fun _hasNextPage(): JsonField = hasNextPage + + /** + * Returns the raw JSON value of [hasPrevPage]. + * + * Unlike [hasPrevPage], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("hasPrevPage") + @ExcludeMissing + fun _hasPrevPage(): JsonField = hasPrevPage + + /** + * Returns the raw JSON value of [limit]. + * + * Unlike [limit], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("limit") @ExcludeMissing fun _limit(): JsonField = limit + + /** + * Returns the raw JSON value of [page]. + * + * Unlike [page], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("page") @ExcludeMissing fun _page(): JsonField = page + + /** + * Returns the raw JSON value of [total]. + * + * Unlike [total], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("total") @ExcludeMissing fun _total(): JsonField = total + + /** + * Returns the raw JSON value of [totalPages]. + * + * Unlike [totalPages], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("totalPages") @ExcludeMissing fun _totalPages(): JsonField = totalPages + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Pagination]. + * + * The following fields are required: + * ```java + * .hasNextPage() + * .hasPrevPage() + * .limit() + * .page() + * .total() + * .totalPages() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Pagination]. */ + class Builder internal constructor() { + + private var hasNextPage: JsonField? = null + private var hasPrevPage: JsonField? = null + private var limit: JsonField? = null + private var page: JsonField? = null + private var total: JsonField? = null + private var totalPages: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(pagination: Pagination) = apply { + hasNextPage = pagination.hasNextPage + hasPrevPage = pagination.hasPrevPage + limit = pagination.limit + page = pagination.page + total = pagination.total + totalPages = pagination.totalPages + additionalProperties = pagination.additionalProperties.toMutableMap() + } + + fun hasNextPage(hasNextPage: Boolean) = hasNextPage(JsonField.of(hasNextPage)) + + /** + * Sets [Builder.hasNextPage] to an arbitrary JSON value. + * + * You should usually call [Builder.hasNextPage] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun hasNextPage(hasNextPage: JsonField) = apply { + this.hasNextPage = hasNextPage + } + + fun hasPrevPage(hasPrevPage: Boolean) = hasPrevPage(JsonField.of(hasPrevPage)) + + /** + * Sets [Builder.hasPrevPage] to an arbitrary JSON value. + * + * You should usually call [Builder.hasPrevPage] with a well-typed [Boolean] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun hasPrevPage(hasPrevPage: JsonField) = apply { + this.hasPrevPage = hasPrevPage + } + + fun limit(limit: Long) = limit(JsonField.of(limit)) + + /** + * Sets [Builder.limit] to an arbitrary JSON value. + * + * You should usually call [Builder.limit] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun limit(limit: JsonField) = apply { this.limit = limit } + + fun page(page: Long) = page(JsonField.of(page)) + + /** + * Sets [Builder.page] to an arbitrary JSON value. + * + * You should usually call [Builder.page] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun page(page: JsonField) = apply { this.page = page } + + fun total(total: Long) = total(JsonField.of(total)) + + /** + * Sets [Builder.total] to an arbitrary JSON value. + * + * You should usually call [Builder.total] with a well-typed [Long] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun total(total: JsonField) = apply { this.total = total } + + fun totalPages(totalPages: Long) = totalPages(JsonField.of(totalPages)) + + /** + * Sets [Builder.totalPages] to an arbitrary JSON value. + * + * You should usually call [Builder.totalPages] with a well-typed [Long] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun totalPages(totalPages: JsonField) = apply { this.totalPages = totalPages } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Pagination]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .hasNextPage() + * .hasPrevPage() + * .limit() + * .page() + * .total() + * .totalPages() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Pagination = + Pagination( + checkRequired("hasNextPage", hasNextPage), + checkRequired("hasPrevPage", hasPrevPage), + checkRequired("limit", limit), + checkRequired("page", page), + checkRequired("total", total), + checkRequired("totalPages", totalPages), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Pagination = apply { + if (validated) { + return@apply + } + + hasNextPage() + hasPrevPage() + limit() + page() + total() + totalPages() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (hasNextPage.asKnown().isPresent) 1 else 0) + + (if (hasPrevPage.asKnown().isPresent) 1 else 0) + + (if (limit.asKnown().isPresent) 1 else 0) + + (if (page.asKnown().isPresent) 1 else 0) + + (if (total.asKnown().isPresent) 1 else 0) + + (if (totalPages.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Pagination && + hasNextPage == other.hasNextPage && + hasPrevPage == other.hasPrevPage && + limit == other.limit && + page == other.page && + total == other.total && + totalPages == other.totalPages && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + hasNextPage, + hasPrevPage, + limit, + page, + total, + totalPages, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Pagination{hasNextPage=$hasNextPage, hasPrevPage=$hasPrevPage, limit=$limit, page=$page, total=$total, totalPages=$totalPages, additionalProperties=$additionalProperties}" + } class Trace @JsonCreator(mode = JsonCreator.Mode.DISABLED) @@ -164,6 +567,7 @@ private constructor( private val _id: JsonField, private val createdAt: JsonField, private val data: JsonValue, + private val organizationId: JsonField, private val type: JsonField, private val updatedAt: JsonField, private val userId: JsonField, @@ -177,44 +581,59 @@ private constructor( @ExcludeMissing createdAt: JsonField = JsonMissing.of(), @JsonProperty("data") @ExcludeMissing data: JsonValue = JsonMissing.of(), + @JsonProperty("organizationId") + @ExcludeMissing + organizationId: JsonField = JsonMissing.of(), @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), @JsonProperty("updatedAt") @ExcludeMissing updatedAt: JsonField = JsonMissing.of(), @JsonProperty("userId") @ExcludeMissing userId: JsonField = JsonMissing.of(), - ) : this(_id, createdAt, data, type, updatedAt, userId, mutableMapOf()) + ) : this(_id, createdAt, data, organizationId, type, updatedAt, userId, mutableMapOf()) /** - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun _id(): Optional = _id.getOptional("_id") + fun _id(): String = _id.getRequired("_id") /** - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun createdAt(): Optional = createdAt.getOptional("createdAt") + fun createdAt(): OffsetDateTime = createdAt.getRequired("createdAt") + /** + * This arbitrary value can be deserialized into a custom type using the `convert` method: + * ```java + * MyClass myObject = trace.data().convert(MyClass.class); + * ``` + */ @JsonProperty("data") @ExcludeMissing fun _data(): JsonValue = data /** - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * @throws AlchemystAiInvalidDataException if 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(): Optional = type.getOptional("type") + fun organizationId(): String = organizationId.getRequired("organizationId") /** - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun updatedAt(): Optional = updatedAt.getOptional("updatedAt") + fun type(): String = type.getRequired("type") /** - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if - * the server responded with an unexpected value). + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun userId(): Optional = userId.getOptional("userId") + fun updatedAt(): OffsetDateTime = updatedAt.getRequired("updatedAt") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun userId(): String = userId.getRequired("userId") /** * Returns the raw JSON value of [_id]. @@ -232,6 +651,16 @@ private constructor( @ExcludeMissing fun _createdAt(): JsonField = createdAt + /** + * Returns the raw JSON value of [organizationId]. + * + * Unlike [organizationId], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("organizationId") + @ExcludeMissing + fun _organizationId(): JsonField = organizationId + /** * Returns the raw JSON value of [type]. * @@ -269,19 +698,33 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [Trace]. */ + /** + * Returns a mutable builder for constructing an instance of [Trace]. + * + * The following fields are required: + * ```java + * ._id() + * .createdAt() + * .data() + * .organizationId() + * .type() + * .updatedAt() + * .userId() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [Trace]. */ class Builder internal constructor() { - private var _id: JsonField = JsonMissing.of() - private var createdAt: JsonField = JsonMissing.of() - private var data: JsonValue = JsonMissing.of() - private var type: JsonField = JsonMissing.of() - private var updatedAt: JsonField = JsonMissing.of() - private var userId: JsonField = JsonMissing.of() + private var _id: JsonField? = null + private var createdAt: JsonField? = null + private var data: JsonValue? = null + private var organizationId: JsonField? = null + private var type: JsonField? = null + private var updatedAt: JsonField? = null + private var userId: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic @@ -289,6 +732,7 @@ private constructor( _id = trace._id createdAt = trace.createdAt data = trace.data + organizationId = trace.organizationId type = trace.type updatedAt = trace.updatedAt userId = trace.userId @@ -321,6 +765,20 @@ private constructor( fun data(data: JsonValue) = apply { this.data = data } + fun organizationId(organizationId: String) = + organizationId(JsonField.of(organizationId)) + + /** + * Sets [Builder.organizationId] to an arbitrary JSON value. + * + * You should usually call [Builder.organizationId] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun organizationId(organizationId: JsonField) = apply { + this.organizationId = organizationId + } + fun type(type: String) = type(JsonField.of(type)) /** @@ -379,15 +837,29 @@ private constructor( * Returns an immutable instance of [Trace]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * ._id() + * .createdAt() + * .data() + * .organizationId() + * .type() + * .updatedAt() + * .userId() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): Trace = Trace( - _id, - createdAt, - data, - type, - updatedAt, - userId, + checkRequired("_id", _id), + checkRequired("createdAt", createdAt), + checkRequired("data", data), + checkRequired("organizationId", organizationId), + checkRequired("type", type), + checkRequired("updatedAt", updatedAt), + checkRequired("userId", userId), additionalProperties.toMutableMap(), ) } @@ -401,6 +873,7 @@ private constructor( _id() createdAt() + organizationId() type() updatedAt() userId() @@ -425,6 +898,7 @@ private constructor( internal fun validity(): Int = (if (_id.asKnown().isPresent) 1 else 0) + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (organizationId.asKnown().isPresent) 1 else 0) + (if (type.asKnown().isPresent) 1 else 0) + (if (updatedAt.asKnown().isPresent) 1 else 0) + (if (userId.asKnown().isPresent) 1 else 0) @@ -438,6 +912,7 @@ private constructor( _id == other._id && createdAt == other.createdAt && data == other.data && + organizationId == other.organizationId && type == other.type && updatedAt == other.updatedAt && userId == other.userId && @@ -445,13 +920,22 @@ private constructor( } private val hashCode: Int by lazy { - Objects.hash(_id, createdAt, data, type, updatedAt, userId, additionalProperties) + Objects.hash( + _id, + createdAt, + data, + organizationId, + type, + updatedAt, + userId, + additionalProperties, + ) } override fun hashCode(): Int = hashCode override fun toString() = - "Trace{_id=$_id, createdAt=$createdAt, data=$data, type=$type, updatedAt=$updatedAt, userId=$userId, additionalProperties=$additionalProperties}" + "Trace{_id=$_id, createdAt=$createdAt, data=$data, organizationId=$organizationId, type=$type, updatedAt=$updatedAt, userId=$userId, additionalProperties=$additionalProperties}" } override fun equals(other: Any?): Boolean { @@ -460,14 +944,15 @@ private constructor( } return other is TraceListResponse && + pagination == other.pagination && traces == other.traces && additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { Objects.hash(traces, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(pagination, traces, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "TraceListResponse{traces=$traces, additionalProperties=$additionalProperties}" + "TraceListResponse{pagination=$pagination, traces=$traces, additionalProperties=$additionalProperties}" } diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewDocsParams.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewDocsParams.kt index 5488c59..d6abfac 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewDocsParams.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewDocsParams.kt @@ -6,14 +6,20 @@ import com.alchemystai.sdk.core.Params import com.alchemystai.sdk.core.http.Headers import com.alchemystai.sdk.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull -/** Fetches documents view for authenticated user with optional organization context */ +/** Fetches documents view for authenticated user with optional organization context. */ class ViewDocsParams private constructor( + private val magicKey: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { + /** Optional magic key for special access or filtering */ + fun magicKey(): Optional = Optional.ofNullable(magicKey) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders @@ -33,15 +39,23 @@ private constructor( /** A builder for [ViewDocsParams]. */ class Builder internal constructor() { + private var magicKey: String? = null private var additionalHeaders: Headers.Builder = Headers.builder() private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(viewDocsParams: ViewDocsParams) = apply { + magicKey = viewDocsParams.magicKey additionalHeaders = viewDocsParams.additionalHeaders.toBuilder() additionalQueryParams = viewDocsParams.additionalQueryParams.toBuilder() } + /** Optional magic key for special access or filtering */ + fun magicKey(magicKey: String?) = apply { this.magicKey = magicKey } + + /** Alias for calling [Builder.magicKey] with `magicKey.orElse(null)`. */ + fun magicKey(magicKey: Optional) = magicKey(magicKey.getOrNull()) + fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() putAllAdditionalHeaders(additionalHeaders) @@ -146,12 +160,18 @@ private constructor( * Further updates to this [Builder] will not mutate the returned instance. */ fun build(): ViewDocsParams = - ViewDocsParams(additionalHeaders.build(), additionalQueryParams.build()) + ViewDocsParams(magicKey, additionalHeaders.build(), additionalQueryParams.build()) } override fun _headers(): Headers = additionalHeaders - override fun _queryParams(): QueryParams = additionalQueryParams + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + magicKey?.let { put("magic_key", it) } + putAll(additionalQueryParams) + } + .build() override fun equals(other: Any?): Boolean { if (this === other) { @@ -159,12 +179,13 @@ private constructor( } return other is ViewDocsParams && + magicKey == other.magicKey && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = Objects.hash(additionalHeaders, additionalQueryParams) + override fun hashCode(): Int = Objects.hash(magicKey, additionalHeaders, additionalQueryParams) override fun toString() = - "ViewDocsParams{additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" + "ViewDocsParams{magicKey=$magicKey, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewDocsResponse.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewDocsResponse.kt index 7beeeab..9d09e1d 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewDocsResponse.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewDocsResponse.kt @@ -3,19 +3,49 @@ package com.alchemystai.sdk.models.v1.context.view import com.alchemystai.sdk.core.ExcludeMissing +import com.alchemystai.sdk.core.JsonField +import com.alchemystai.sdk.core.JsonMissing import com.alchemystai.sdk.core.JsonValue +import com.alchemystai.sdk.core.checkKnown +import com.alchemystai.sdk.core.checkRequired +import com.alchemystai.sdk.core.toImmutable import com.alchemystai.sdk.errors.AlchemystAiInvalidDataException 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 ViewDocsResponse @JsonCreator(mode = JsonCreator.Mode.DISABLED) -private constructor(private val additionalProperties: MutableMap) { +private constructor( + private val documents: JsonField>, + private val additionalProperties: MutableMap, +) { - @JsonCreator private constructor() : this(mutableMapOf()) + @JsonCreator + private constructor( + @JsonProperty("documents") + @ExcludeMissing + documents: JsonField> = JsonMissing.of() + ) : this(documents, mutableMapOf()) + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun documents(): List = documents.getRequired("documents") + + /** + * Returns the raw JSON value of [documents]. + * + * Unlike [documents], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("documents") + @ExcludeMissing + fun _documents(): JsonField> = documents @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -31,20 +61,54 @@ private constructor(private val additionalProperties: MutableMap>? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(viewDocsResponse: ViewDocsResponse) = apply { + documents = viewDocsResponse.documents.map { it.toMutableList() } additionalProperties = viewDocsResponse.additionalProperties.toMutableMap() } + fun documents(documents: List) = documents(JsonField.of(documents)) + + /** + * Sets [Builder.documents] to an arbitrary JSON value. + * + * You should usually call [Builder.documents] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun documents(documents: JsonField>) = apply { + this.documents = documents.map { it.toMutableList() } + } + + /** + * Adds a single [Document] to [documents]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addDocument(document: Document) = apply { + documents = + (documents ?: JsonField.of(mutableListOf())).also { + checkKnown("documents", it).add(document) + } + } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -68,8 +132,19 @@ private constructor(private val additionalProperties: MutableMap, + private val fileSize: JsonField, + private val fileType: JsonField, + private val groupName: JsonField>, + private val lastModified: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("fileName") + @ExcludeMissing + fileName: JsonField = JsonMissing.of(), + @JsonProperty("fileSize") + @ExcludeMissing + fileSize: JsonField = JsonMissing.of(), + @JsonProperty("fileType") + @ExcludeMissing + fileType: JsonField = JsonMissing.of(), + @JsonProperty("groupName") + @ExcludeMissing + groupName: JsonField> = JsonMissing.of(), + @JsonProperty("lastModified") + @ExcludeMissing + lastModified: JsonField = JsonMissing.of(), + ) : this(fileName, fileSize, fileType, groupName, lastModified, mutableMapOf()) + + /** + * Name of the file + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun fileName(): String = fileName.getRequired("fileName") + + /** + * Size of the file in bytes + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun fileSize(): Double = fileSize.getRequired("fileSize") + + /** + * Type/MIME of the file + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun fileType(): String = fileType.getRequired("fileType") + + /** + * Array of group names to which the file belongs + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun groupName(): List = groupName.getRequired("groupName") + + /** + * Last modified timestamp (ISO format) + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun lastModified(): String = lastModified.getRequired("lastModified") + + /** + * Returns the raw JSON value of [fileName]. + * + * Unlike [fileName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("fileName") @ExcludeMissing fun _fileName(): JsonField = fileName + + /** + * Returns the raw JSON value of [fileSize]. + * + * Unlike [fileSize], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("fileSize") @ExcludeMissing fun _fileSize(): JsonField = fileSize + + /** + * Returns the raw JSON value of [fileType]. + * + * Unlike [fileType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("fileType") @ExcludeMissing fun _fileType(): JsonField = fileType + + /** + * Returns the raw JSON value of [groupName]. + * + * Unlike [groupName], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("groupName") + @ExcludeMissing + fun _groupName(): JsonField> = groupName + + /** + * Returns the raw JSON value of [lastModified]. + * + * Unlike [lastModified], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("lastModified") + @ExcludeMissing + fun _lastModified(): JsonField = lastModified + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [Document]. + * + * The following fields are required: + * ```java + * .fileName() + * .fileSize() + * .fileType() + * .groupName() + * .lastModified() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Document]. */ + class Builder internal constructor() { + + private var fileName: JsonField? = null + private var fileSize: JsonField? = null + private var fileType: JsonField? = null + private var groupName: JsonField>? = null + private var lastModified: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(document: Document) = apply { + fileName = document.fileName + fileSize = document.fileSize + fileType = document.fileType + groupName = document.groupName.map { it.toMutableList() } + lastModified = document.lastModified + additionalProperties = document.additionalProperties.toMutableMap() + } + + /** Name of the file */ + fun fileName(fileName: String) = fileName(JsonField.of(fileName)) + + /** + * Sets [Builder.fileName] to an arbitrary JSON value. + * + * You should usually call [Builder.fileName] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fileName(fileName: JsonField) = apply { this.fileName = fileName } + + /** Size of the file in bytes */ + fun fileSize(fileSize: Double) = fileSize(JsonField.of(fileSize)) + + /** + * Sets [Builder.fileSize] to an arbitrary JSON value. + * + * You should usually call [Builder.fileSize] with a well-typed [Double] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fileSize(fileSize: JsonField) = apply { this.fileSize = fileSize } + + /** Type/MIME of the file */ + fun fileType(fileType: String) = fileType(JsonField.of(fileType)) + + /** + * Sets [Builder.fileType] to an arbitrary JSON value. + * + * You should usually call [Builder.fileType] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun fileType(fileType: JsonField) = apply { this.fileType = fileType } + + /** Array of group names to which the file belongs */ + fun groupName(groupName: List) = groupName(JsonField.of(groupName)) + + /** + * Sets [Builder.groupName] to an arbitrary JSON value. + * + * You should usually call [Builder.groupName] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun groupName(groupName: JsonField>) = apply { + this.groupName = groupName.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [Builder.groupName]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addGroupName(groupName: String) = apply { + this.groupName = + (this.groupName ?: JsonField.of(mutableListOf())).also { + checkKnown("groupName", it).add(groupName) + } + } + + /** Last modified timestamp (ISO format) */ + fun lastModified(lastModified: String) = lastModified(JsonField.of(lastModified)) + + /** + * Sets [Builder.lastModified] to an arbitrary JSON value. + * + * You should usually call [Builder.lastModified] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun lastModified(lastModified: JsonField) = apply { + this.lastModified = lastModified + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Document]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .fileName() + * .fileSize() + * .fileType() + * .groupName() + * .lastModified() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Document = + Document( + checkRequired("fileName", fileName), + checkRequired("fileSize", fileSize), + checkRequired("fileType", fileType), + checkRequired("groupName", groupName).map { it.toImmutable() }, + checkRequired("lastModified", lastModified), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Document = apply { + if (validated) { + return@apply + } + + fileName() + fileSize() + fileType() + groupName() + lastModified() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (fileName.asKnown().isPresent) 1 else 0) + + (if (fileSize.asKnown().isPresent) 1 else 0) + + (if (fileType.asKnown().isPresent) 1 else 0) + + (groupName.asKnown().getOrNull()?.size ?: 0) + + (if (lastModified.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Document && + fileName == other.fileName && + fileSize == other.fileSize && + fileType == other.fileType && + groupName == other.groupName && + lastModified == other.lastModified && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + fileName, + fileSize, + fileType, + groupName, + lastModified, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Document{fileName=$fileName, fileSize=$fileSize, fileType=$fileType, groupName=$groupName, lastModified=$lastModified, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { return true } - return other is ViewDocsResponse && additionalProperties == other.additionalProperties + return other is ViewDocsResponse && + documents == other.documents && + additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(documents, additionalProperties) } override fun hashCode(): Int = hashCode - override fun toString() = "ViewDocsResponse{additionalProperties=$additionalProperties}" + override fun toString() = + "ViewDocsResponse{documents=$documents, additionalProperties=$additionalProperties}" } diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewRetrieveParams.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewRetrieveParams.kt index fa449b8..1c763de 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewRetrieveParams.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewRetrieveParams.kt @@ -6,14 +6,24 @@ import com.alchemystai.sdk.core.Params import com.alchemystai.sdk.core.http.Headers import com.alchemystai.sdk.core.http.QueryParams import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull -/** Gets the context information for the authenticated user */ +/** Gets the context information for the authenticated user. */ class ViewRetrieveParams private constructor( + private val fileName: String?, + private val magicKey: String?, private val additionalHeaders: Headers, private val additionalQueryParams: QueryParams, ) : Params { + /** Name of the file to retrieve context for */ + fun fileName(): Optional = Optional.ofNullable(fileName) + + /** Magic key for context retrieval */ + fun magicKey(): Optional = Optional.ofNullable(magicKey) + /** Additional headers to send with the request. */ fun _additionalHeaders(): Headers = additionalHeaders @@ -33,15 +43,31 @@ private constructor( /** A builder for [ViewRetrieveParams]. */ class Builder internal constructor() { + private var fileName: String? = null + private var magicKey: String? = null private var additionalHeaders: Headers.Builder = Headers.builder() private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() @JvmSynthetic internal fun from(viewRetrieveParams: ViewRetrieveParams) = apply { + fileName = viewRetrieveParams.fileName + magicKey = viewRetrieveParams.magicKey additionalHeaders = viewRetrieveParams.additionalHeaders.toBuilder() additionalQueryParams = viewRetrieveParams.additionalQueryParams.toBuilder() } + /** Name of the file to retrieve context for */ + fun fileName(fileName: String?) = apply { this.fileName = fileName } + + /** Alias for calling [Builder.fileName] with `fileName.orElse(null)`. */ + fun fileName(fileName: Optional) = fileName(fileName.getOrNull()) + + /** Magic key for context retrieval */ + fun magicKey(magicKey: String?) = apply { this.magicKey = magicKey } + + /** Alias for calling [Builder.magicKey] with `magicKey.orElse(null)`. */ + fun magicKey(magicKey: Optional) = magicKey(magicKey.getOrNull()) + fun additionalHeaders(additionalHeaders: Headers) = apply { this.additionalHeaders.clear() putAllAdditionalHeaders(additionalHeaders) @@ -146,12 +172,24 @@ private constructor( * Further updates to this [Builder] will not mutate the returned instance. */ fun build(): ViewRetrieveParams = - ViewRetrieveParams(additionalHeaders.build(), additionalQueryParams.build()) + ViewRetrieveParams( + fileName, + magicKey, + additionalHeaders.build(), + additionalQueryParams.build(), + ) } override fun _headers(): Headers = additionalHeaders - override fun _queryParams(): QueryParams = additionalQueryParams + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + fileName?.let { put("file_name", it) } + magicKey?.let { put("magic_key", it) } + putAll(additionalQueryParams) + } + .build() override fun equals(other: Any?): Boolean { if (this === other) { @@ -159,12 +197,15 @@ private constructor( } return other is ViewRetrieveParams && + fileName == other.fileName && + magicKey == other.magicKey && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams } - override fun hashCode(): Int = Objects.hash(additionalHeaders, additionalQueryParams) + override fun hashCode(): Int = + Objects.hash(fileName, magicKey, additionalHeaders, additionalQueryParams) override fun toString() = - "ViewRetrieveParams{additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" + "ViewRetrieveParams{fileName=$fileName, magicKey=$magicKey, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" } diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewRetrieveResponse.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewRetrieveResponse.kt index cea107b..0b8a3cd 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewRetrieveResponse.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewRetrieveResponse.kt @@ -7,6 +7,7 @@ import com.alchemystai.sdk.core.JsonField import com.alchemystai.sdk.core.JsonMissing import com.alchemystai.sdk.core.JsonValue import com.alchemystai.sdk.core.checkKnown +import com.alchemystai.sdk.core.checkRequired import com.alchemystai.sdk.core.toImmutable import com.alchemystai.sdk.errors.AlchemystAiInvalidDataException import com.fasterxml.jackson.annotation.JsonAnyGetter @@ -21,31 +22,46 @@ import kotlin.jvm.optionals.getOrNull class ViewRetrieveResponse @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( - private val context: JsonField>, + private val contexts: JsonField>, + private val success: JsonField, private val additionalProperties: MutableMap, ) { @JsonCreator private constructor( - @JsonProperty("context") + @JsonProperty("contexts") @ExcludeMissing - context: JsonField> = JsonMissing.of() - ) : this(context, mutableMapOf()) + contexts: JsonField> = JsonMissing.of(), + @JsonProperty("success") @ExcludeMissing success: JsonField = JsonMissing.of(), + ) : this(contexts, success, mutableMapOf()) /** * List of context items * - * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if the - * server responded with an unexpected value). + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun context(): Optional> = context.getOptional("context") + fun contexts(): List = contexts.getRequired("contexts") /** - * Returns the raw JSON value of [context]. + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun success(): Boolean = success.getRequired("success") + + /** + * Returns the raw JSON value of [contexts]. * - * Unlike [context], this method doesn't throw if the JSON field has an unexpected type. + * Unlike [contexts], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("context") @ExcludeMissing fun _context(): JsonField> = context + @JsonProperty("contexts") @ExcludeMissing fun _contexts(): JsonField> = contexts + + /** + * Returns the raw JSON value of [success]. + * + * Unlike [success], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("success") @ExcludeMissing fun _success(): JsonField = success @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -61,48 +77,68 @@ private constructor( companion object { - /** Returns a mutable builder for constructing an instance of [ViewRetrieveResponse]. */ + /** + * Returns a mutable builder for constructing an instance of [ViewRetrieveResponse]. + * + * The following fields are required: + * ```java + * .contexts() + * .success() + * ``` + */ @JvmStatic fun builder() = Builder() } /** A builder for [ViewRetrieveResponse]. */ class Builder internal constructor() { - private var context: JsonField>? = null + private var contexts: JsonField>? = null + private var success: JsonField? = null private var additionalProperties: MutableMap = mutableMapOf() @JvmSynthetic internal fun from(viewRetrieveResponse: ViewRetrieveResponse) = apply { - context = viewRetrieveResponse.context.map { it.toMutableList() } + contexts = viewRetrieveResponse.contexts.map { it.toMutableList() } + success = viewRetrieveResponse.success additionalProperties = viewRetrieveResponse.additionalProperties.toMutableMap() } /** List of context items */ - fun context(context: List) = context(JsonField.of(context)) + fun contexts(contexts: List) = contexts(JsonField.of(contexts)) /** - * Sets [Builder.context] to an arbitrary JSON value. + * Sets [Builder.contexts] to an arbitrary JSON value. * - * You should usually call [Builder.context] with a well-typed `List` value + * You should usually call [Builder.contexts] with a well-typed `List` value * instead. This method is primarily for setting the field to an undocumented or not yet * supported value. */ - fun context(context: JsonField>) = apply { - this.context = context.map { it.toMutableList() } + fun contexts(contexts: JsonField>) = apply { + this.contexts = contexts.map { it.toMutableList() } } /** - * Adds a single [JsonValue] to [Builder.context]. + * Adds a single [Context] to [contexts]. * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addContext(context: JsonValue) = apply { - this.context = - (this.context ?: JsonField.of(mutableListOf())).also { - checkKnown("context", it).add(context) + fun addContext(context: Context) = apply { + contexts = + (contexts ?: JsonField.of(mutableListOf())).also { + checkKnown("contexts", it).add(context) } } + fun success(success: Boolean) = success(JsonField.of(success)) + + /** + * Sets [Builder.success] to an arbitrary JSON value. + * + * You should usually call [Builder.success] with a well-typed [Boolean] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun success(success: JsonField) = apply { this.success = success } + fun additionalProperties(additionalProperties: Map) = apply { this.additionalProperties.clear() putAllAdditionalProperties(additionalProperties) @@ -126,10 +162,19 @@ private constructor( * Returns an immutable instance of [ViewRetrieveResponse]. * * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .contexts() + * .success() + * ``` + * + * @throws IllegalStateException if any required field is unset. */ fun build(): ViewRetrieveResponse = ViewRetrieveResponse( - (context ?: JsonMissing.of()).map { it.toImmutable() }, + checkRequired("contexts", contexts).map { it.toImmutable() }, + checkRequired("success", success), additionalProperties.toMutableMap(), ) } @@ -141,7 +186,8 @@ private constructor( return@apply } - context() + contexts().forEach { it.validate() } + success() validated = true } @@ -158,7 +204,509 @@ private constructor( * * Used for best match union deserialization. */ - @JvmSynthetic internal fun validity(): Int = (context.asKnown().getOrNull()?.size ?: 0) + @JvmSynthetic + internal fun validity(): Int = + (contexts.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (success.asKnown().isPresent) 1 else 0) + + class Context + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val content: JsonField, + private val metadata: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("content") @ExcludeMissing content: JsonField = JsonMissing.of(), + @JsonProperty("metadata") + @ExcludeMissing + metadata: JsonField = JsonMissing.of(), + ) : this(content, metadata, mutableMapOf()) + + /** + * The content of the context item + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun content(): Optional = content.getOptional("content") + + /** + * Additional metadata for the context + * + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type (e.g. if + * the server responded with an unexpected value). + */ + fun metadata(): Optional = metadata.getOptional("metadata") + + /** + * Returns the raw JSON value of [content]. + * + * Unlike [content], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("content") @ExcludeMissing fun _content(): JsonField = content + + /** + * Returns the raw JSON value of [metadata]. + * + * Unlike [metadata], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("metadata") @ExcludeMissing fun _metadata(): JsonField = metadata + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Context]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Context]. */ + class Builder internal constructor() { + + private var content: JsonField = JsonMissing.of() + private var metadata: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(context: Context) = apply { + content = context.content + metadata = context.metadata + additionalProperties = context.additionalProperties.toMutableMap() + } + + /** The content of the context item */ + fun content(content: String) = content(JsonField.of(content)) + + /** + * Sets [Builder.content] to an arbitrary JSON value. + * + * You should usually call [Builder.content] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun content(content: JsonField) = apply { this.content = content } + + /** Additional metadata for the context */ + fun metadata(metadata: Metadata) = metadata(JsonField.of(metadata)) + + /** + * Sets [Builder.metadata] to an arbitrary JSON value. + * + * You should usually call [Builder.metadata] with a well-typed [Metadata] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun metadata(metadata: JsonField) = apply { this.metadata = metadata } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Context]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Context = Context(content, metadata, additionalProperties.toMutableMap()) + } + + private var validated: Boolean = false + + fun validate(): Context = apply { + if (validated) { + return@apply + } + + content() + metadata().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (content.asKnown().isPresent) 1 else 0) + + (metadata.asKnown().getOrNull()?.validity() ?: 0) + + /** Additional metadata for the context */ + class Metadata + @JsonCreator(mode = JsonCreator.Mode.DISABLED) + private constructor( + private val fileName: JsonField, + private val fileSize: JsonField, + private val fileType: JsonField, + private val groupName: JsonField>, + private val lastModified: JsonField, + private val additionalProperties: MutableMap, + ) { + + @JsonCreator + private constructor( + @JsonProperty("fileName") + @ExcludeMissing + fileName: JsonField = JsonMissing.of(), + @JsonProperty("fileSize") + @ExcludeMissing + fileSize: JsonField = JsonMissing.of(), + @JsonProperty("fileType") + @ExcludeMissing + fileType: JsonField = JsonMissing.of(), + @JsonProperty("groupName") + @ExcludeMissing + groupName: JsonField> = JsonMissing.of(), + @JsonProperty("lastModified") + @ExcludeMissing + lastModified: JsonField = JsonMissing.of(), + ) : this(fileName, fileSize, fileType, groupName, lastModified, mutableMapOf()) + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun fileName(): Optional = fileName.getOptional("fileName") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun fileSize(): Optional = fileSize.getOptional("fileSize") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun fileType(): Optional = fileType.getOptional("fileType") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun groupName(): Optional> = groupName.getOptional("groupName") + + /** + * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type + * (e.g. if the server responded with an unexpected value). + */ + fun lastModified(): Optional = lastModified.getOptional("lastModified") + + /** + * Returns the raw JSON value of [fileName]. + * + * Unlike [fileName], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("fileName") @ExcludeMissing fun _fileName(): JsonField = fileName + + /** + * Returns the raw JSON value of [fileSize]. + * + * Unlike [fileSize], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("fileSize") @ExcludeMissing fun _fileSize(): JsonField = fileSize + + /** + * Returns the raw JSON value of [fileType]. + * + * Unlike [fileType], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("fileType") @ExcludeMissing fun _fileType(): JsonField = fileType + + /** + * Returns the raw JSON value of [groupName]. + * + * Unlike [groupName], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("groupName") + @ExcludeMissing + fun _groupName(): JsonField> = groupName + + /** + * Returns the raw JSON value of [lastModified]. + * + * Unlike [lastModified], this method doesn't throw if the JSON field has an unexpected + * type. + */ + @JsonProperty("lastModified") + @ExcludeMissing + fun _lastModified(): JsonField = lastModified + + @JsonAnySetter + private fun putAdditionalProperty(key: String, value: JsonValue) { + additionalProperties.put(key, value) + } + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = + Collections.unmodifiableMap(additionalProperties) + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Metadata]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Metadata]. */ + class Builder internal constructor() { + + private var fileName: JsonField = JsonMissing.of() + private var fileSize: JsonField = JsonMissing.of() + private var fileType: JsonField = JsonMissing.of() + private var groupName: JsonField>? = null + private var lastModified: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(metadata: Metadata) = apply { + fileName = metadata.fileName + fileSize = metadata.fileSize + fileType = metadata.fileType + groupName = metadata.groupName.map { it.toMutableList() } + lastModified = metadata.lastModified + additionalProperties = metadata.additionalProperties.toMutableMap() + } + + fun fileName(fileName: String) = fileName(JsonField.of(fileName)) + + /** + * Sets [Builder.fileName] to an arbitrary JSON value. + * + * You should usually call [Builder.fileName] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun fileName(fileName: JsonField) = apply { this.fileName = fileName } + + fun fileSize(fileSize: Double) = fileSize(JsonField.of(fileSize)) + + /** + * Sets [Builder.fileSize] to an arbitrary JSON value. + * + * You should usually call [Builder.fileSize] with a well-typed [Double] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun fileSize(fileSize: JsonField) = apply { this.fileSize = fileSize } + + fun fileType(fileType: String) = fileType(JsonField.of(fileType)) + + /** + * Sets [Builder.fileType] to an arbitrary JSON value. + * + * You should usually call [Builder.fileType] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun fileType(fileType: JsonField) = apply { this.fileType = fileType } + + fun groupName(groupName: List) = groupName(JsonField.of(groupName)) + + /** + * Sets [Builder.groupName] to an arbitrary JSON value. + * + * You should usually call [Builder.groupName] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented + * or not yet supported value. + */ + fun groupName(groupName: JsonField>) = apply { + this.groupName = groupName.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [Builder.groupName]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addGroupName(groupName: String) = apply { + this.groupName = + (this.groupName ?: JsonField.of(mutableListOf())).also { + checkKnown("groupName", it).add(groupName) + } + } + + fun lastModified(lastModified: String) = lastModified(JsonField.of(lastModified)) + + /** + * Sets [Builder.lastModified] to an arbitrary JSON value. + * + * You should usually call [Builder.lastModified] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun lastModified(lastModified: JsonField) = apply { + this.lastModified = lastModified + } + + fun additionalProperties(additionalProperties: Map) = apply { + this.additionalProperties.clear() + putAllAdditionalProperties(additionalProperties) + } + + fun putAdditionalProperty(key: String, value: JsonValue) = apply { + additionalProperties.put(key, value) + } + + fun putAllAdditionalProperties(additionalProperties: Map) = + apply { + this.additionalProperties.putAll(additionalProperties) + } + + fun removeAdditionalProperty(key: String) = apply { + additionalProperties.remove(key) + } + + fun removeAllAdditionalProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalProperty) + } + + /** + * Returns an immutable instance of [Metadata]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Metadata = + Metadata( + fileName, + fileSize, + fileType, + (groupName ?: JsonMissing.of()).map { it.toImmutable() }, + lastModified, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + fun validate(): Metadata = apply { + if (validated) { + return@apply + } + + fileName() + fileSize() + fileType() + groupName() + lastModified() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: AlchemystAiInvalidDataException) { + false + } + + /** + * Returns a score indicating how many valid values are contained in this object + * recursively. + * + * Used for best match union deserialization. + */ + @JvmSynthetic + internal fun validity(): Int = + (if (fileName.asKnown().isPresent) 1 else 0) + + (if (fileSize.asKnown().isPresent) 1 else 0) + + (if (fileType.asKnown().isPresent) 1 else 0) + + (groupName.asKnown().getOrNull()?.size ?: 0) + + (if (lastModified.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Metadata && + fileName == other.fileName && + fileSize == other.fileSize && + fileType == other.fileType && + groupName == other.groupName && + lastModified == other.lastModified && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + fileName, + fileSize, + fileType, + groupName, + lastModified, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Metadata{fileName=$fileName, fileSize=$fileSize, fileType=$fileType, groupName=$groupName, lastModified=$lastModified, additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Context && + content == other.content && + metadata == other.metadata && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(content, metadata, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Context{content=$content, metadata=$metadata, additionalProperties=$additionalProperties}" + } override fun equals(other: Any?): Boolean { if (this === other) { @@ -166,14 +714,15 @@ private constructor( } return other is ViewRetrieveResponse && - context == other.context && + contexts == other.contexts && + success == other.success && additionalProperties == other.additionalProperties } - private val hashCode: Int by lazy { Objects.hash(context, additionalProperties) } + private val hashCode: Int by lazy { Objects.hash(contexts, success, additionalProperties) } override fun hashCode(): Int = hashCode override fun toString() = - "ViewRetrieveResponse{context=$context, additionalProperties=$additionalProperties}" + "ViewRetrieveResponse{contexts=$contexts, success=$success, additionalProperties=$additionalProperties}" } diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/org/context/ContextViewParams.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/org/context/ContextViewParams.kt index 94a1351..5e981ae 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/org/context/ContextViewParams.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/org/context/ContextViewParams.kt @@ -33,14 +33,14 @@ private constructor( * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun userIds(): List = body.userIds() + @Deprecated("deprecated") fun userIds(): List = body.userIds() /** * Returns the raw JSON value of [userIds]. * * Unlike [userIds], this method doesn't throw if the JSON field has an unexpected type. */ - fun _userIds(): JsonField> = body._userIds() + @Deprecated("deprecated") fun _userIds(): JsonField> = body._userIds() fun _additionalBodyProperties(): Map = body._additionalProperties() @@ -88,6 +88,7 @@ private constructor( */ fun body(body: Body) = apply { this.body = body.toBuilder() } + @Deprecated("deprecated") fun userIds(userIds: List) = apply { body.userIds(userIds) } /** @@ -97,6 +98,7 @@ private constructor( * This method is primarily for setting the field to an undocumented or not yet supported * value. */ + @Deprecated("deprecated") fun userIds(userIds: JsonField>) = apply { body.userIds(userIds) } /** @@ -104,7 +106,7 @@ private constructor( * * @throws IllegalStateException if the field was previously set to a non-list. */ - fun addUserId(userId: String) = apply { body.addUserId(userId) } + @Deprecated("deprecated") fun addUserId(userId: String) = apply { body.addUserId(userId) } fun additionalBodyProperties(additionalBodyProperties: Map) = apply { body.additionalProperties(additionalBodyProperties) @@ -267,14 +269,17 @@ private constructor( * @throws AlchemystAiInvalidDataException if the JSON field has an unexpected type or is * unexpectedly missing or null (e.g. if the server responded with an unexpected value). */ - fun userIds(): List = userIds.getRequired("userIds") + @Deprecated("deprecated") fun userIds(): List = userIds.getRequired("userIds") /** * Returns the raw JSON value of [userIds]. * * Unlike [userIds], this method doesn't throw if the JSON field has an unexpected type. */ - @JsonProperty("userIds") @ExcludeMissing fun _userIds(): JsonField> = userIds + @Deprecated("deprecated") + @JsonProperty("userIds") + @ExcludeMissing + fun _userIds(): JsonField> = userIds @JsonAnySetter private fun putAdditionalProperty(key: String, value: JsonValue) { @@ -313,6 +318,7 @@ private constructor( additionalProperties = body.additionalProperties.toMutableMap() } + @Deprecated("deprecated") fun userIds(userIds: List) = userIds(JsonField.of(userIds)) /** @@ -322,6 +328,7 @@ private constructor( * instead. This method is primarily for setting the field to an undocumented or not yet * supported value. */ + @Deprecated("deprecated") fun userIds(userIds: JsonField>) = apply { this.userIds = userIds.map { it.toMutableList() } } @@ -331,6 +338,7 @@ private constructor( * * @throws IllegalStateException if the field was previously set to a non-list. */ + @Deprecated("deprecated") fun addUserId(userId: String) = apply { userIds = (userIds ?: JsonField.of(mutableListOf())).also { diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/org/context/ContextViewResponse.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/org/context/ContextViewResponse.kt index d5716d1..a1c6d68 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/org/context/ContextViewResponse.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/models/v1/org/context/ContextViewResponse.kt @@ -25,6 +25,12 @@ private constructor( @JsonProperty("contexts") @ExcludeMissing contexts: JsonValue = JsonMissing.of() ) : this(contexts, mutableMapOf()) + /** + * This arbitrary value can be deserialized into a custom type using the `convert` method: + * ```java + * MyClass myObject = contextViewResponse.contexts().convert(MyClass.class); + * ``` + */ @JsonProperty("contexts") @ExcludeMissing fun _contexts(): JsonValue = contexts @JsonAnySetter diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/ContextServiceAsync.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/ContextServiceAsync.kt index 1d9f700..6b5dc6b 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/ContextServiceAsync.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/ContextServiceAsync.kt @@ -11,6 +11,7 @@ import com.alchemystai.sdk.models.v1.context.ContextDeleteParams import com.alchemystai.sdk.models.v1.context.ContextDeleteResponse import com.alchemystai.sdk.models.v1.context.ContextSearchParams import com.alchemystai.sdk.models.v1.context.ContextSearchResponse +import com.alchemystai.sdk.services.async.v1.context.AddAsyncServiceAsync import com.alchemystai.sdk.services.async.v1.context.MemoryServiceAsync import com.alchemystai.sdk.services.async.v1.context.TraceServiceAsync import com.alchemystai.sdk.services.async.v1.context.ViewServiceAsync @@ -37,45 +38,34 @@ interface ContextServiceAsync { fun memory(): MemoryServiceAsync - /** Deletes context data based on provided parameters */ - fun delete(): CompletableFuture = delete(ContextDeleteParams.none()) + fun addAsync(): AddAsyncServiceAsync + + /** + * This endpoint deletes context data based on the provided parameters. It returns a success or + * error response depending on the result from the context processor. + */ + fun delete(params: ContextDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) /** @see delete */ fun delete( - params: ContextDeleteParams = ContextDeleteParams.none(), + params: ContextDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture - /** @see delete */ - fun delete( - params: ContextDeleteParams = ContextDeleteParams.none() - ): CompletableFuture = delete(params, RequestOptions.none()) - - /** @see delete */ - fun delete(requestOptions: RequestOptions): CompletableFuture = - delete(ContextDeleteParams.none(), requestOptions) - /** * This endpoint accepts context data and sends it to a context processor for further handling. * It returns a success or error response depending on the result from the context processor. */ - fun add(): CompletableFuture = add(ContextAddParams.none()) + fun add(params: ContextAddParams): CompletableFuture = + add(params, RequestOptions.none()) /** @see add */ fun add( - params: ContextAddParams = ContextAddParams.none(), + params: ContextAddParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture - /** @see add */ - fun add( - params: ContextAddParams = ContextAddParams.none() - ): CompletableFuture = add(params, RequestOptions.none()) - - /** @see add */ - fun add(requestOptions: RequestOptions): CompletableFuture = - add(ContextAddParams.none(), requestOptions) - /** * This endpoint sends a search request to the context processor to retrieve relevant context * data based on the provided query. @@ -109,56 +99,36 @@ interface ContextServiceAsync { fun memory(): MemoryServiceAsync.WithRawResponse + fun addAsync(): AddAsyncServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `post /api/v1/context/delete`, but is otherwise the same * as [ContextServiceAsync.delete]. */ - fun delete(): CompletableFuture> = - delete(ContextDeleteParams.none()) - - /** @see delete */ fun delete( - params: ContextDeleteParams = ContextDeleteParams.none(), - requestOptions: RequestOptions = RequestOptions.none(), - ): CompletableFuture> - - /** @see delete */ - fun delete( - params: ContextDeleteParams = ContextDeleteParams.none() + params: ContextDeleteParams ): CompletableFuture> = delete(params, RequestOptions.none()) /** @see delete */ fun delete( - requestOptions: RequestOptions - ): CompletableFuture> = - delete(ContextDeleteParams.none(), requestOptions) + params: ContextDeleteParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> /** * Returns a raw HTTP response for `post /api/v1/context/add`, but is otherwise the same as * [ContextServiceAsync.add]. */ - fun add(): CompletableFuture> = - add(ContextAddParams.none()) + fun add(params: ContextAddParams): CompletableFuture> = + add(params, RequestOptions.none()) /** @see add */ fun add( - params: ContextAddParams = ContextAddParams.none(), + params: ContextAddParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture> - /** @see add */ - fun add( - params: ContextAddParams = ContextAddParams.none() - ): CompletableFuture> = - add(params, RequestOptions.none()) - - /** @see add */ - fun add( - requestOptions: RequestOptions - ): CompletableFuture> = - add(ContextAddParams.none(), requestOptions) - /** * Returns a raw HTTP response for `post /api/v1/context/search`, but is otherwise the same * as [ContextServiceAsync.search]. diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/ContextServiceAsyncImpl.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/ContextServiceAsyncImpl.kt index 966cdf3..634f63f 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/ContextServiceAsyncImpl.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/ContextServiceAsyncImpl.kt @@ -21,6 +21,8 @@ import com.alchemystai.sdk.models.v1.context.ContextDeleteParams import com.alchemystai.sdk.models.v1.context.ContextDeleteResponse import com.alchemystai.sdk.models.v1.context.ContextSearchParams import com.alchemystai.sdk.models.v1.context.ContextSearchResponse +import com.alchemystai.sdk.services.async.v1.context.AddAsyncServiceAsync +import com.alchemystai.sdk.services.async.v1.context.AddAsyncServiceAsyncImpl import com.alchemystai.sdk.services.async.v1.context.MemoryServiceAsync import com.alchemystai.sdk.services.async.v1.context.MemoryServiceAsyncImpl import com.alchemystai.sdk.services.async.v1.context.TraceServiceAsync @@ -43,6 +45,8 @@ class ContextServiceAsyncImpl internal constructor(private val clientOptions: Cl private val memory: MemoryServiceAsync by lazy { MemoryServiceAsyncImpl(clientOptions) } + private val addAsync: AddAsyncServiceAsync by lazy { AddAsyncServiceAsyncImpl(clientOptions) } + override fun withRawResponse(): ContextServiceAsync.WithRawResponse = withRawResponse override fun withOptions(modifier: Consumer): ContextServiceAsync = @@ -54,6 +58,8 @@ class ContextServiceAsyncImpl internal constructor(private val clientOptions: Cl override fun memory(): MemoryServiceAsync = memory + override fun addAsync(): AddAsyncServiceAsync = addAsync + override fun delete( params: ContextDeleteParams, requestOptions: RequestOptions, @@ -93,6 +99,10 @@ class ContextServiceAsyncImpl internal constructor(private val clientOptions: Cl MemoryServiceAsyncImpl.WithRawResponseImpl(clientOptions) } + private val addAsync: AddAsyncServiceAsync.WithRawResponse by lazy { + AddAsyncServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + override fun withOptions( modifier: Consumer ): ContextServiceAsync.WithRawResponse = @@ -106,6 +116,8 @@ class ContextServiceAsyncImpl internal constructor(private val clientOptions: Cl override fun memory(): MemoryServiceAsync.WithRawResponse = memory + override fun addAsync(): AddAsyncServiceAsync.WithRawResponse = addAsync + private val deleteHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/AddAsyncServiceAsync.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/AddAsyncServiceAsync.kt new file mode 100644 index 0000000..0d22ad0 --- /dev/null +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/AddAsyncServiceAsync.kt @@ -0,0 +1,157 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.services.async.v1.context + +import com.alchemystai.sdk.core.ClientOptions +import com.alchemystai.sdk.core.RequestOptions +import com.alchemystai.sdk.core.http.HttpResponseFor +import com.alchemystai.sdk.models.v1.context.addasync.AddAsyncCancelParams +import com.alchemystai.sdk.models.v1.context.addasync.AddAsyncCancelResponse +import com.alchemystai.sdk.models.v1.context.addasync.AddAsyncCreateParams +import com.alchemystai.sdk.models.v1.context.addasync.AddAsyncCreateResponse +import com.alchemystai.sdk.services.async.v1.context.addasync.StatusServiceAsync +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +interface AddAsyncServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): AddAsyncServiceAsync + + fun status(): StatusServiceAsync + + /** + * This endpoint accepts context data and queues it for asynchronous processing by the context + * processor. It returns a success or error response depending on the queuing result. + */ + fun create(params: AddAsyncCreateParams): CompletableFuture = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: AddAsyncCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** + * Attempts to cancel a context add job by job id. + * - If the job is already completed or failed, returns 404. + * - If the job is currently running ("active"), returns 409 and cannot be cancelled. + * - Only jobs in "waiting" or "delayed" state can be cancelled. + */ + fun cancel(id: String): CompletableFuture = + cancel(id, AddAsyncCancelParams.none()) + + /** @see cancel */ + fun cancel( + id: String, + params: AddAsyncCancelParams = AddAsyncCancelParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + cancel(params.toBuilder().id(id).build(), requestOptions) + + /** @see cancel */ + fun cancel( + id: String, + params: AddAsyncCancelParams = AddAsyncCancelParams.none(), + ): CompletableFuture = cancel(id, params, RequestOptions.none()) + + /** @see cancel */ + fun cancel( + params: AddAsyncCancelParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see cancel */ + fun cancel(params: AddAsyncCancelParams): CompletableFuture = + cancel(params, RequestOptions.none()) + + /** @see cancel */ + fun cancel( + id: String, + requestOptions: RequestOptions, + ): CompletableFuture = + cancel(id, AddAsyncCancelParams.none(), requestOptions) + + /** + * A view of [AddAsyncServiceAsync] that provides access to raw HTTP responses for each method. + */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): AddAsyncServiceAsync.WithRawResponse + + fun status(): StatusServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `post /api/v1/context/add-async`, but is otherwise the + * same as [AddAsyncServiceAsync.create]. + */ + fun create( + params: AddAsyncCreateParams + ): CompletableFuture> = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: AddAsyncCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** + * Returns a raw HTTP response for `delete /api/v1/context/add-async/{id}/cancel`, but is + * otherwise the same as [AddAsyncServiceAsync.cancel]. + */ + fun cancel(id: String): CompletableFuture> = + cancel(id, AddAsyncCancelParams.none()) + + /** @see cancel */ + fun cancel( + id: String, + params: AddAsyncCancelParams = AddAsyncCancelParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + cancel(params.toBuilder().id(id).build(), requestOptions) + + /** @see cancel */ + fun cancel( + id: String, + params: AddAsyncCancelParams = AddAsyncCancelParams.none(), + ): CompletableFuture> = + cancel(id, params, RequestOptions.none()) + + /** @see cancel */ + fun cancel( + params: AddAsyncCancelParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see cancel */ + fun cancel( + params: AddAsyncCancelParams + ): CompletableFuture> = + cancel(params, RequestOptions.none()) + + /** @see cancel */ + fun cancel( + id: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + cancel(id, AddAsyncCancelParams.none(), requestOptions) + } +} diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/AddAsyncServiceAsyncImpl.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/AddAsyncServiceAsyncImpl.kt new file mode 100644 index 0000000..2fdae72 --- /dev/null +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/AddAsyncServiceAsyncImpl.kt @@ -0,0 +1,150 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.services.async.v1.context + +import com.alchemystai.sdk.core.ClientOptions +import com.alchemystai.sdk.core.RequestOptions +import com.alchemystai.sdk.core.checkRequired +import com.alchemystai.sdk.core.handlers.errorBodyHandler +import com.alchemystai.sdk.core.handlers.errorHandler +import com.alchemystai.sdk.core.handlers.jsonHandler +import com.alchemystai.sdk.core.http.HttpMethod +import com.alchemystai.sdk.core.http.HttpRequest +import com.alchemystai.sdk.core.http.HttpResponse +import com.alchemystai.sdk.core.http.HttpResponse.Handler +import com.alchemystai.sdk.core.http.HttpResponseFor +import com.alchemystai.sdk.core.http.json +import com.alchemystai.sdk.core.http.parseable +import com.alchemystai.sdk.core.prepareAsync +import com.alchemystai.sdk.models.v1.context.addasync.AddAsyncCancelParams +import com.alchemystai.sdk.models.v1.context.addasync.AddAsyncCancelResponse +import com.alchemystai.sdk.models.v1.context.addasync.AddAsyncCreateParams +import com.alchemystai.sdk.models.v1.context.addasync.AddAsyncCreateResponse +import com.alchemystai.sdk.services.async.v1.context.addasync.StatusServiceAsync +import com.alchemystai.sdk.services.async.v1.context.addasync.StatusServiceAsyncImpl +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class AddAsyncServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + AddAsyncServiceAsync { + + private val withRawResponse: AddAsyncServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + private val status: StatusServiceAsync by lazy { StatusServiceAsyncImpl(clientOptions) } + + override fun withRawResponse(): AddAsyncServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): AddAsyncServiceAsync = + AddAsyncServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun status(): StatusServiceAsync = status + + override fun create( + params: AddAsyncCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /api/v1/context/add-async + withRawResponse().create(params, requestOptions).thenApply { it.parse() } + + override fun cancel( + params: AddAsyncCancelParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // delete /api/v1/context/add-async/{id}/cancel + withRawResponse().cancel(params, requestOptions).thenApply { it.parse() } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + AddAsyncServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + private val status: StatusServiceAsync.WithRawResponse by lazy { + StatusServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + + override fun withOptions( + modifier: Consumer + ): AddAsyncServiceAsync.WithRawResponse = + AddAsyncServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + override fun status(): StatusServiceAsync.WithRawResponse = status + + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: AddAsyncCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "context", "add-async") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { createHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val cancelHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun cancel( + params: AddAsyncCancelParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "api", + "v1", + "context", + "add-async", + params._pathParam(0), + "cancel", + ) + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { cancelHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + } +} diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/MemoryServiceAsync.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/MemoryServiceAsync.kt index 0710852..fc7450d 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/MemoryServiceAsync.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/MemoryServiceAsync.kt @@ -5,9 +5,12 @@ package com.alchemystai.sdk.services.async.v1.context import com.alchemystai.sdk.core.ClientOptions import com.alchemystai.sdk.core.RequestOptions import com.alchemystai.sdk.core.http.HttpResponse +import com.alchemystai.sdk.core.http.HttpResponseFor import com.alchemystai.sdk.models.v1.context.memory.MemoryAddParams +import com.alchemystai.sdk.models.v1.context.memory.MemoryAddResponse import com.alchemystai.sdk.models.v1.context.memory.MemoryDeleteParams import com.alchemystai.sdk.models.v1.context.memory.MemoryUpdateParams +import com.alchemystai.sdk.models.v1.context.memory.MemoryUpdateResponse import java.util.concurrent.CompletableFuture import java.util.function.Consumer @@ -26,55 +29,34 @@ interface MemoryServiceAsync { fun withOptions(modifier: Consumer): MemoryServiceAsync /** This endpoint updates memory context data. */ - fun update(): CompletableFuture = update(MemoryUpdateParams.none()) + fun update(params: MemoryUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) /** @see update */ fun update( - params: MemoryUpdateParams = MemoryUpdateParams.none(), + params: MemoryUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), - ): CompletableFuture - - /** @see update */ - fun update(params: MemoryUpdateParams = MemoryUpdateParams.none()): CompletableFuture = - update(params, RequestOptions.none()) + ): CompletableFuture - /** @see update */ - fun update(requestOptions: RequestOptions): CompletableFuture = - update(MemoryUpdateParams.none(), requestOptions) - - /** Deletes memory context data based on provided parameters */ - fun delete(): CompletableFuture = delete(MemoryDeleteParams.none()) + /** Deletes memory context data based on provided parameters. */ + fun delete(params: MemoryDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) /** @see delete */ fun delete( - params: MemoryDeleteParams = MemoryDeleteParams.none(), + params: MemoryDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture - /** @see delete */ - fun delete(params: MemoryDeleteParams = MemoryDeleteParams.none()): CompletableFuture = - delete(params, RequestOptions.none()) - - /** @see delete */ - fun delete(requestOptions: RequestOptions): CompletableFuture = - delete(MemoryDeleteParams.none(), requestOptions) - - /** This endpoint adds memory context data, fetching chat history if needed. */ - fun add(): CompletableFuture = add(MemoryAddParams.none()) + /** This endpoint adds memory (chat history) as context. */ + fun add(params: MemoryAddParams): CompletableFuture = + add(params, RequestOptions.none()) /** @see add */ fun add( - params: MemoryAddParams = MemoryAddParams.none(), + params: MemoryAddParams, requestOptions: RequestOptions = RequestOptions.none(), - ): CompletableFuture - - /** @see add */ - fun add(params: MemoryAddParams = MemoryAddParams.none()): CompletableFuture = - add(params, RequestOptions.none()) - - /** @see add */ - fun add(requestOptions: RequestOptions): CompletableFuture = - add(MemoryAddParams.none(), requestOptions) + ): CompletableFuture /** * A view of [MemoryServiceAsync] that provides access to raw HTTP responses for each method. @@ -94,62 +76,41 @@ interface MemoryServiceAsync { * Returns a raw HTTP response for `post /api/v1/context/memory/update`, but is otherwise * the same as [MemoryServiceAsync.update]. */ - fun update(): CompletableFuture = update(MemoryUpdateParams.none()) - - /** @see update */ fun update( - params: MemoryUpdateParams = MemoryUpdateParams.none(), - requestOptions: RequestOptions = RequestOptions.none(), - ): CompletableFuture + params: MemoryUpdateParams + ): CompletableFuture> = + update(params, RequestOptions.none()) /** @see update */ fun update( - params: MemoryUpdateParams = MemoryUpdateParams.none() - ): CompletableFuture = update(params, RequestOptions.none()) - - /** @see update */ - fun update(requestOptions: RequestOptions): CompletableFuture = - update(MemoryUpdateParams.none(), requestOptions) + params: MemoryUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> /** * Returns a raw HTTP response for `post /api/v1/context/memory/delete`, but is otherwise * the same as [MemoryServiceAsync.delete]. */ - fun delete(): CompletableFuture = delete(MemoryDeleteParams.none()) + fun delete(params: MemoryDeleteParams): CompletableFuture = + delete(params, RequestOptions.none()) /** @see delete */ fun delete( - params: MemoryDeleteParams = MemoryDeleteParams.none(), + params: MemoryDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): CompletableFuture - /** @see delete */ - fun delete( - params: MemoryDeleteParams = MemoryDeleteParams.none() - ): CompletableFuture = delete(params, RequestOptions.none()) - - /** @see delete */ - fun delete(requestOptions: RequestOptions): CompletableFuture = - delete(MemoryDeleteParams.none(), requestOptions) - /** * Returns a raw HTTP response for `post /api/v1/context/memory/add`, but is otherwise the * same as [MemoryServiceAsync.add]. */ - fun add(): CompletableFuture = add(MemoryAddParams.none()) + fun add(params: MemoryAddParams): CompletableFuture> = + add(params, RequestOptions.none()) /** @see add */ fun add( - params: MemoryAddParams = MemoryAddParams.none(), + params: MemoryAddParams, requestOptions: RequestOptions = RequestOptions.none(), - ): CompletableFuture - - /** @see add */ - fun add(params: MemoryAddParams = MemoryAddParams.none()): CompletableFuture = - add(params, RequestOptions.none()) - - /** @see add */ - fun add(requestOptions: RequestOptions): CompletableFuture = - add(MemoryAddParams.none(), requestOptions) + ): CompletableFuture> } } diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/MemoryServiceAsyncImpl.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/MemoryServiceAsyncImpl.kt index 2a56f5c..5cea280 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/MemoryServiceAsyncImpl.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/MemoryServiceAsyncImpl.kt @@ -7,16 +7,20 @@ import com.alchemystai.sdk.core.RequestOptions import com.alchemystai.sdk.core.handlers.emptyHandler import com.alchemystai.sdk.core.handlers.errorBodyHandler import com.alchemystai.sdk.core.handlers.errorHandler +import com.alchemystai.sdk.core.handlers.jsonHandler import com.alchemystai.sdk.core.http.HttpMethod import com.alchemystai.sdk.core.http.HttpRequest import com.alchemystai.sdk.core.http.HttpResponse import com.alchemystai.sdk.core.http.HttpResponse.Handler +import com.alchemystai.sdk.core.http.HttpResponseFor import com.alchemystai.sdk.core.http.json import com.alchemystai.sdk.core.http.parseable import com.alchemystai.sdk.core.prepareAsync import com.alchemystai.sdk.models.v1.context.memory.MemoryAddParams +import com.alchemystai.sdk.models.v1.context.memory.MemoryAddResponse import com.alchemystai.sdk.models.v1.context.memory.MemoryDeleteParams import com.alchemystai.sdk.models.v1.context.memory.MemoryUpdateParams +import com.alchemystai.sdk.models.v1.context.memory.MemoryUpdateResponse import java.util.concurrent.CompletableFuture import java.util.function.Consumer @@ -35,9 +39,9 @@ class MemoryServiceAsyncImpl internal constructor(private val clientOptions: Cli override fun update( params: MemoryUpdateParams, requestOptions: RequestOptions, - ): CompletableFuture = + ): CompletableFuture = // post /api/v1/context/memory/update - withRawResponse().update(params, requestOptions).thenAccept {} + withRawResponse().update(params, requestOptions).thenApply { it.parse() } override fun delete( params: MemoryDeleteParams, @@ -49,9 +53,9 @@ class MemoryServiceAsyncImpl internal constructor(private val clientOptions: Cli override fun add( params: MemoryAddParams, requestOptions: RequestOptions, - ): CompletableFuture = + ): CompletableFuture = // post /api/v1/context/memory/add - withRawResponse().add(params, requestOptions).thenAccept {} + withRawResponse().add(params, requestOptions).thenApply { it.parse() } class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : MemoryServiceAsync.WithRawResponse { @@ -66,12 +70,13 @@ class MemoryServiceAsyncImpl internal constructor(private val clientOptions: Cli clientOptions.toBuilder().apply(modifier::accept).build() ) - private val updateHandler: Handler = emptyHandler() + private val updateHandler: Handler = + jsonHandler(clientOptions.jsonMapper) override fun update( params: MemoryUpdateParams, requestOptions: RequestOptions, - ): CompletableFuture { + ): CompletableFuture> { val request = HttpRequest.builder() .method(HttpMethod.POST) @@ -85,7 +90,13 @@ class MemoryServiceAsyncImpl internal constructor(private val clientOptions: Cli .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> errorHandler.handle(response).parseable { - response.use { updateHandler.handle(it) } + response + .use { updateHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } } } } @@ -114,12 +125,13 @@ class MemoryServiceAsyncImpl internal constructor(private val clientOptions: Cli } } - private val addHandler: Handler = emptyHandler() + private val addHandler: Handler = + jsonHandler(clientOptions.jsonMapper) override fun add( params: MemoryAddParams, requestOptions: RequestOptions, - ): CompletableFuture { + ): CompletableFuture> { val request = HttpRequest.builder() .method(HttpMethod.POST) @@ -133,7 +145,13 @@ class MemoryServiceAsyncImpl internal constructor(private val clientOptions: Cli .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } .thenApply { response -> errorHandler.handle(response).parseable { - response.use { addHandler.handle(it) } + response + .use { addHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } } } } diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/TraceServiceAsync.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/TraceServiceAsync.kt index 22684a1..3a9bc25 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/TraceServiceAsync.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/TraceServiceAsync.kt @@ -26,7 +26,7 @@ interface TraceServiceAsync { */ fun withOptions(modifier: Consumer): TraceServiceAsync - /** Retrieves a list of traces for the authenticated user */ + /** Returns paginated traces for the authenticated user within their organization. */ fun list(): CompletableFuture = list(TraceListParams.none()) /** @see list */ @@ -44,7 +44,7 @@ interface TraceServiceAsync { fun list(requestOptions: RequestOptions): CompletableFuture = list(TraceListParams.none(), requestOptions) - /** Deletes a data trace for the authenticated user with the specified trace ID */ + /** Deletes a data trace for the authenticated user with the specified trace ID. */ fun delete(traceId: String): CompletableFuture = delete(traceId, TraceDeleteParams.none()) diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/ViewServiceAsync.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/ViewServiceAsync.kt index 23efbb6..d287d8b 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/ViewServiceAsync.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/ViewServiceAsync.kt @@ -26,7 +26,7 @@ interface ViewServiceAsync { */ fun withOptions(modifier: Consumer): ViewServiceAsync - /** Gets the context information for the authenticated user */ + /** Gets the context information for the authenticated user. */ fun retrieve(): CompletableFuture = retrieve(ViewRetrieveParams.none()) /** @see retrieve */ @@ -44,7 +44,7 @@ interface ViewServiceAsync { fun retrieve(requestOptions: RequestOptions): CompletableFuture = retrieve(ViewRetrieveParams.none(), requestOptions) - /** Fetches documents view for authenticated user with optional organization context */ + /** Fetches documents view for authenticated user with optional organization context. */ fun docs(): CompletableFuture = docs(ViewDocsParams.none()) /** @see docs */ diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/addasync/StatusServiceAsync.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/addasync/StatusServiceAsync.kt new file mode 100644 index 0000000..6edc094 --- /dev/null +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/addasync/StatusServiceAsync.kt @@ -0,0 +1,165 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.services.async.v1.context.addasync + +import com.alchemystai.sdk.core.ClientOptions +import com.alchemystai.sdk.core.RequestOptions +import com.alchemystai.sdk.core.http.HttpResponseFor +import com.alchemystai.sdk.models.v1.context.addasync.status.StatusListParams +import com.alchemystai.sdk.models.v1.context.addasync.status.StatusListResponse +import com.alchemystai.sdk.models.v1.context.addasync.status.StatusRetrieveParams +import com.alchemystai.sdk.models.v1.context.addasync.status.StatusRetrieveResponse +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +interface StatusServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): StatusServiceAsync + + /** Returns the status and result of a context add job by job id. */ + fun retrieve(id: String): CompletableFuture = + retrieve(id, StatusRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + id: String, + params: StatusRetrieveParams = StatusRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().id(id).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + id: String, + params: StatusRetrieveParams = StatusRetrieveParams.none(), + ): CompletableFuture = retrieve(id, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: StatusRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see retrieve */ + fun retrieve(params: StatusRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + id: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieve(id, StatusRetrieveParams.none(), requestOptions) + + /** + * Returns all jobs (active, waiting, delayed, failed, completed) belonging to the authenticated + * user. + */ + fun list(): CompletableFuture = list(StatusListParams.none()) + + /** @see list */ + fun list( + params: StatusListParams = StatusListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see list */ + fun list( + params: StatusListParams = StatusListParams.none() + ): CompletableFuture = list(params, RequestOptions.none()) + + /** @see list */ + fun list(requestOptions: RequestOptions): CompletableFuture = + list(StatusListParams.none(), requestOptions) + + /** + * A view of [StatusServiceAsync] that provides access to raw HTTP responses for each method. + */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): StatusServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `get /api/v1/context/add-async/{id}/status`, but is + * otherwise the same as [StatusServiceAsync.retrieve]. + */ + fun retrieve(id: String): CompletableFuture> = + retrieve(id, StatusRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + id: String, + params: StatusRetrieveParams = StatusRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().id(id).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + id: String, + params: StatusRetrieveParams = StatusRetrieveParams.none(), + ): CompletableFuture> = + retrieve(id, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: StatusRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see retrieve */ + fun retrieve( + params: StatusRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + id: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(id, StatusRetrieveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /api/v1/context/add-async/status`, but is otherwise + * the same as [StatusServiceAsync.list]. + */ + fun list(): CompletableFuture> = + list(StatusListParams.none()) + + /** @see list */ + fun list( + params: StatusListParams = StatusListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see list */ + fun list( + params: StatusListParams = StatusListParams.none() + ): CompletableFuture> = + list(params, RequestOptions.none()) + + /** @see list */ + fun list( + requestOptions: RequestOptions + ): CompletableFuture> = + list(StatusListParams.none(), requestOptions) + } +} diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/addasync/StatusServiceAsyncImpl.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/addasync/StatusServiceAsyncImpl.kt new file mode 100644 index 0000000..f60908d --- /dev/null +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/async/v1/context/addasync/StatusServiceAsyncImpl.kt @@ -0,0 +1,135 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.services.async.v1.context.addasync + +import com.alchemystai.sdk.core.ClientOptions +import com.alchemystai.sdk.core.RequestOptions +import com.alchemystai.sdk.core.checkRequired +import com.alchemystai.sdk.core.handlers.errorBodyHandler +import com.alchemystai.sdk.core.handlers.errorHandler +import com.alchemystai.sdk.core.handlers.jsonHandler +import com.alchemystai.sdk.core.http.HttpMethod +import com.alchemystai.sdk.core.http.HttpRequest +import com.alchemystai.sdk.core.http.HttpResponse +import com.alchemystai.sdk.core.http.HttpResponse.Handler +import com.alchemystai.sdk.core.http.HttpResponseFor +import com.alchemystai.sdk.core.http.parseable +import com.alchemystai.sdk.core.prepareAsync +import com.alchemystai.sdk.models.v1.context.addasync.status.StatusListParams +import com.alchemystai.sdk.models.v1.context.addasync.status.StatusListResponse +import com.alchemystai.sdk.models.v1.context.addasync.status.StatusRetrieveParams +import com.alchemystai.sdk.models.v1.context.addasync.status.StatusRetrieveResponse +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class StatusServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + StatusServiceAsync { + + private val withRawResponse: StatusServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): StatusServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): StatusServiceAsync = + StatusServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun retrieve( + params: StatusRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /api/v1/context/add-async/{id}/status + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + + override fun list( + params: StatusListParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /api/v1/context/add-async/status + withRawResponse().list(params, requestOptions).thenApply { it.parse() } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + StatusServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): StatusServiceAsync.WithRawResponse = + StatusServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: StatusRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "api", + "v1", + "context", + "add-async", + params._pathParam(0), + "status", + ) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: StatusListParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "context", "add-async", "status") + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + } +} diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/ContextService.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/ContextService.kt index e383d75..13b5f46 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/ContextService.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/ContextService.kt @@ -11,6 +11,7 @@ import com.alchemystai.sdk.models.v1.context.ContextDeleteParams import com.alchemystai.sdk.models.v1.context.ContextDeleteResponse import com.alchemystai.sdk.models.v1.context.ContextSearchParams import com.alchemystai.sdk.models.v1.context.ContextSearchResponse +import com.alchemystai.sdk.services.blocking.v1.context.AddAsyncService import com.alchemystai.sdk.services.blocking.v1.context.MemoryService import com.alchemystai.sdk.services.blocking.v1.context.TraceService import com.alchemystai.sdk.services.blocking.v1.context.ViewService @@ -37,43 +38,33 @@ interface ContextService { fun memory(): MemoryService - /** Deletes context data based on provided parameters */ - fun delete(): ContextDeleteResponse = delete(ContextDeleteParams.none()) + fun addAsync(): AddAsyncService + + /** + * This endpoint deletes context data based on the provided parameters. It returns a success or + * error response depending on the result from the context processor. + */ + fun delete(params: ContextDeleteParams): ContextDeleteResponse = + delete(params, RequestOptions.none()) /** @see delete */ fun delete( - params: ContextDeleteParams = ContextDeleteParams.none(), + params: ContextDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): ContextDeleteResponse - /** @see delete */ - fun delete(params: ContextDeleteParams = ContextDeleteParams.none()): ContextDeleteResponse = - delete(params, RequestOptions.none()) - - /** @see delete */ - fun delete(requestOptions: RequestOptions): ContextDeleteResponse = - delete(ContextDeleteParams.none(), requestOptions) - /** * This endpoint accepts context data and sends it to a context processor for further handling. * It returns a success or error response depending on the result from the context processor. */ - fun add(): ContextAddResponse = add(ContextAddParams.none()) + fun add(params: ContextAddParams): ContextAddResponse = add(params, RequestOptions.none()) /** @see add */ fun add( - params: ContextAddParams = ContextAddParams.none(), + params: ContextAddParams, requestOptions: RequestOptions = RequestOptions.none(), ): ContextAddResponse - /** @see add */ - fun add(params: ContextAddParams = ContextAddParams.none()): ContextAddResponse = - add(params, RequestOptions.none()) - - /** @see add */ - fun add(requestOptions: RequestOptions): ContextAddResponse = - add(ContextAddParams.none(), requestOptions) - /** * This endpoint sends a search request to the context processor to retrieve relevant context * data based on the provided query. @@ -103,55 +94,38 @@ interface ContextService { fun memory(): MemoryService.WithRawResponse + fun addAsync(): AddAsyncService.WithRawResponse + /** * Returns a raw HTTP response for `post /api/v1/context/delete`, but is otherwise the same * as [ContextService.delete]. */ @MustBeClosed - fun delete(): HttpResponseFor = delete(ContextDeleteParams.none()) + fun delete(params: ContextDeleteParams): HttpResponseFor = + delete(params, RequestOptions.none()) /** @see delete */ @MustBeClosed fun delete( - params: ContextDeleteParams = ContextDeleteParams.none(), + params: ContextDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor - /** @see delete */ - @MustBeClosed - fun delete( - params: ContextDeleteParams = ContextDeleteParams.none() - ): HttpResponseFor = delete(params, RequestOptions.none()) - - /** @see delete */ - @MustBeClosed - fun delete(requestOptions: RequestOptions): HttpResponseFor = - delete(ContextDeleteParams.none(), requestOptions) - /** * Returns a raw HTTP response for `post /api/v1/context/add`, but is otherwise the same as * [ContextService.add]. */ - @MustBeClosed fun add(): HttpResponseFor = add(ContextAddParams.none()) + @MustBeClosed + fun add(params: ContextAddParams): HttpResponseFor = + add(params, RequestOptions.none()) /** @see add */ @MustBeClosed fun add( - params: ContextAddParams = ContextAddParams.none(), + params: ContextAddParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponseFor - /** @see add */ - @MustBeClosed - fun add( - params: ContextAddParams = ContextAddParams.none() - ): HttpResponseFor = add(params, RequestOptions.none()) - - /** @see add */ - @MustBeClosed - fun add(requestOptions: RequestOptions): HttpResponseFor = - add(ContextAddParams.none(), requestOptions) - /** * Returns a raw HTTP response for `post /api/v1/context/search`, but is otherwise the same * as [ContextService.search]. diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/ContextServiceImpl.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/ContextServiceImpl.kt index 104b198..4380632 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/ContextServiceImpl.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/ContextServiceImpl.kt @@ -21,6 +21,8 @@ import com.alchemystai.sdk.models.v1.context.ContextDeleteParams import com.alchemystai.sdk.models.v1.context.ContextDeleteResponse import com.alchemystai.sdk.models.v1.context.ContextSearchParams import com.alchemystai.sdk.models.v1.context.ContextSearchResponse +import com.alchemystai.sdk.services.blocking.v1.context.AddAsyncService +import com.alchemystai.sdk.services.blocking.v1.context.AddAsyncServiceImpl import com.alchemystai.sdk.services.blocking.v1.context.MemoryService import com.alchemystai.sdk.services.blocking.v1.context.MemoryServiceImpl import com.alchemystai.sdk.services.blocking.v1.context.TraceService @@ -42,6 +44,8 @@ class ContextServiceImpl internal constructor(private val clientOptions: ClientO private val memory: MemoryService by lazy { MemoryServiceImpl(clientOptions) } + private val addAsync: AddAsyncService by lazy { AddAsyncServiceImpl(clientOptions) } + override fun withRawResponse(): ContextService.WithRawResponse = withRawResponse override fun withOptions(modifier: Consumer): ContextService = @@ -53,6 +57,8 @@ class ContextServiceImpl internal constructor(private val clientOptions: ClientO override fun memory(): MemoryService = memory + override fun addAsync(): AddAsyncService = addAsync + override fun delete( params: ContextDeleteParams, requestOptions: RequestOptions, @@ -89,6 +95,10 @@ class ContextServiceImpl internal constructor(private val clientOptions: ClientO MemoryServiceImpl.WithRawResponseImpl(clientOptions) } + private val addAsync: AddAsyncService.WithRawResponse by lazy { + AddAsyncServiceImpl.WithRawResponseImpl(clientOptions) + } + override fun withOptions( modifier: Consumer ): ContextService.WithRawResponse = @@ -102,6 +112,8 @@ class ContextServiceImpl internal constructor(private val clientOptions: ClientO override fun memory(): MemoryService.WithRawResponse = memory + override fun addAsync(): AddAsyncService.WithRawResponse = addAsync + private val deleteHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/AddAsyncService.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/AddAsyncService.kt new file mode 100644 index 0000000..ffa94d4 --- /dev/null +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/AddAsyncService.kt @@ -0,0 +1,151 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.services.blocking.v1.context + +import com.alchemystai.sdk.core.ClientOptions +import com.alchemystai.sdk.core.RequestOptions +import com.alchemystai.sdk.core.http.HttpResponseFor +import com.alchemystai.sdk.models.v1.context.addasync.AddAsyncCancelParams +import com.alchemystai.sdk.models.v1.context.addasync.AddAsyncCancelResponse +import com.alchemystai.sdk.models.v1.context.addasync.AddAsyncCreateParams +import com.alchemystai.sdk.models.v1.context.addasync.AddAsyncCreateResponse +import com.alchemystai.sdk.services.blocking.v1.context.addasync.StatusService +import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer + +interface AddAsyncService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): AddAsyncService + + fun status(): StatusService + + /** + * This endpoint accepts context data and queues it for asynchronous processing by the context + * processor. It returns a success or error response depending on the queuing result. + */ + fun create(params: AddAsyncCreateParams): AddAsyncCreateResponse = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: AddAsyncCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): AddAsyncCreateResponse + + /** + * Attempts to cancel a context add job by job id. + * - If the job is already completed or failed, returns 404. + * - If the job is currently running ("active"), returns 409 and cannot be cancelled. + * - Only jobs in "waiting" or "delayed" state can be cancelled. + */ + fun cancel(id: String): AddAsyncCancelResponse = cancel(id, AddAsyncCancelParams.none()) + + /** @see cancel */ + fun cancel( + id: String, + params: AddAsyncCancelParams = AddAsyncCancelParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): AddAsyncCancelResponse = cancel(params.toBuilder().id(id).build(), requestOptions) + + /** @see cancel */ + fun cancel( + id: String, + params: AddAsyncCancelParams = AddAsyncCancelParams.none(), + ): AddAsyncCancelResponse = cancel(id, params, RequestOptions.none()) + + /** @see cancel */ + fun cancel( + params: AddAsyncCancelParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): AddAsyncCancelResponse + + /** @see cancel */ + fun cancel(params: AddAsyncCancelParams): AddAsyncCancelResponse = + cancel(params, RequestOptions.none()) + + /** @see cancel */ + fun cancel(id: String, requestOptions: RequestOptions): AddAsyncCancelResponse = + cancel(id, AddAsyncCancelParams.none(), requestOptions) + + /** A view of [AddAsyncService] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): AddAsyncService.WithRawResponse + + fun status(): StatusService.WithRawResponse + + /** + * Returns a raw HTTP response for `post /api/v1/context/add-async`, but is otherwise the + * same as [AddAsyncService.create]. + */ + @MustBeClosed + fun create(params: AddAsyncCreateParams): HttpResponseFor = + create(params, RequestOptions.none()) + + /** @see create */ + @MustBeClosed + fun create( + params: AddAsyncCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** + * Returns a raw HTTP response for `delete /api/v1/context/add-async/{id}/cancel`, but is + * otherwise the same as [AddAsyncService.cancel]. + */ + @MustBeClosed + fun cancel(id: String): HttpResponseFor = + cancel(id, AddAsyncCancelParams.none()) + + /** @see cancel */ + @MustBeClosed + fun cancel( + id: String, + params: AddAsyncCancelParams = AddAsyncCancelParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + cancel(params.toBuilder().id(id).build(), requestOptions) + + /** @see cancel */ + @MustBeClosed + fun cancel( + id: String, + params: AddAsyncCancelParams = AddAsyncCancelParams.none(), + ): HttpResponseFor = cancel(id, params, RequestOptions.none()) + + /** @see cancel */ + @MustBeClosed + fun cancel( + params: AddAsyncCancelParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see cancel */ + @MustBeClosed + fun cancel(params: AddAsyncCancelParams): HttpResponseFor = + cancel(params, RequestOptions.none()) + + /** @see cancel */ + @MustBeClosed + fun cancel( + id: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + cancel(id, AddAsyncCancelParams.none(), requestOptions) + } +} diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/AddAsyncServiceImpl.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/AddAsyncServiceImpl.kt new file mode 100644 index 0000000..57f22c3 --- /dev/null +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/AddAsyncServiceImpl.kt @@ -0,0 +1,143 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.services.blocking.v1.context + +import com.alchemystai.sdk.core.ClientOptions +import com.alchemystai.sdk.core.RequestOptions +import com.alchemystai.sdk.core.checkRequired +import com.alchemystai.sdk.core.handlers.errorBodyHandler +import com.alchemystai.sdk.core.handlers.errorHandler +import com.alchemystai.sdk.core.handlers.jsonHandler +import com.alchemystai.sdk.core.http.HttpMethod +import com.alchemystai.sdk.core.http.HttpRequest +import com.alchemystai.sdk.core.http.HttpResponse +import com.alchemystai.sdk.core.http.HttpResponse.Handler +import com.alchemystai.sdk.core.http.HttpResponseFor +import com.alchemystai.sdk.core.http.json +import com.alchemystai.sdk.core.http.parseable +import com.alchemystai.sdk.core.prepare +import com.alchemystai.sdk.models.v1.context.addasync.AddAsyncCancelParams +import com.alchemystai.sdk.models.v1.context.addasync.AddAsyncCancelResponse +import com.alchemystai.sdk.models.v1.context.addasync.AddAsyncCreateParams +import com.alchemystai.sdk.models.v1.context.addasync.AddAsyncCreateResponse +import com.alchemystai.sdk.services.blocking.v1.context.addasync.StatusService +import com.alchemystai.sdk.services.blocking.v1.context.addasync.StatusServiceImpl +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class AddAsyncServiceImpl internal constructor(private val clientOptions: ClientOptions) : + AddAsyncService { + + private val withRawResponse: AddAsyncService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + private val status: StatusService by lazy { StatusServiceImpl(clientOptions) } + + override fun withRawResponse(): AddAsyncService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): AddAsyncService = + AddAsyncServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun status(): StatusService = status + + override fun create( + params: AddAsyncCreateParams, + requestOptions: RequestOptions, + ): AddAsyncCreateResponse = + // post /api/v1/context/add-async + withRawResponse().create(params, requestOptions).parse() + + override fun cancel( + params: AddAsyncCancelParams, + requestOptions: RequestOptions, + ): AddAsyncCancelResponse = + // delete /api/v1/context/add-async/{id}/cancel + withRawResponse().cancel(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + AddAsyncService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + private val status: StatusService.WithRawResponse by lazy { + StatusServiceImpl.WithRawResponseImpl(clientOptions) + } + + override fun withOptions( + modifier: Consumer + ): AddAsyncService.WithRawResponse = + AddAsyncServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + override fun status(): StatusService.WithRawResponse = status + + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: AddAsyncCreateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "context", "add-async") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { createHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val cancelHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun cancel( + params: AddAsyncCancelParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "api", + "v1", + "context", + "add-async", + params._pathParam(0), + "cancel", + ) + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { cancelHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } +} diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/MemoryService.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/MemoryService.kt index df7eb0a..17d7c2c 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/MemoryService.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/MemoryService.kt @@ -5,9 +5,12 @@ package com.alchemystai.sdk.services.blocking.v1.context import com.alchemystai.sdk.core.ClientOptions import com.alchemystai.sdk.core.RequestOptions import com.alchemystai.sdk.core.http.HttpResponse +import com.alchemystai.sdk.core.http.HttpResponseFor import com.alchemystai.sdk.models.v1.context.memory.MemoryAddParams +import com.alchemystai.sdk.models.v1.context.memory.MemoryAddResponse import com.alchemystai.sdk.models.v1.context.memory.MemoryDeleteParams import com.alchemystai.sdk.models.v1.context.memory.MemoryUpdateParams +import com.alchemystai.sdk.models.v1.context.memory.MemoryUpdateResponse import com.google.errorprone.annotations.MustBeClosed import java.util.function.Consumer @@ -26,51 +29,29 @@ interface MemoryService { fun withOptions(modifier: Consumer): MemoryService /** This endpoint updates memory context data. */ - fun update() = update(MemoryUpdateParams.none()) - - /** @see update */ - fun update( - params: MemoryUpdateParams = MemoryUpdateParams.none(), - requestOptions: RequestOptions = RequestOptions.none(), - ) - - /** @see update */ - fun update(params: MemoryUpdateParams = MemoryUpdateParams.none()) = + fun update(params: MemoryUpdateParams): MemoryUpdateResponse = update(params, RequestOptions.none()) /** @see update */ - fun update(requestOptions: RequestOptions) = update(MemoryUpdateParams.none(), requestOptions) - - /** Deletes memory context data based on provided parameters */ - fun delete() = delete(MemoryDeleteParams.none()) - - /** @see delete */ - fun delete( - params: MemoryDeleteParams = MemoryDeleteParams.none(), + fun update( + params: MemoryUpdateParams, requestOptions: RequestOptions = RequestOptions.none(), - ) + ): MemoryUpdateResponse - /** @see delete */ - fun delete(params: MemoryDeleteParams = MemoryDeleteParams.none()) = - delete(params, RequestOptions.none()) + /** Deletes memory context data based on provided parameters. */ + fun delete(params: MemoryDeleteParams) = delete(params, RequestOptions.none()) /** @see delete */ - fun delete(requestOptions: RequestOptions) = delete(MemoryDeleteParams.none(), requestOptions) + fun delete(params: MemoryDeleteParams, requestOptions: RequestOptions = RequestOptions.none()) - /** This endpoint adds memory context data, fetching chat history if needed. */ - fun add() = add(MemoryAddParams.none()) + /** This endpoint adds memory (chat history) as context. */ + fun add(params: MemoryAddParams): MemoryAddResponse = add(params, RequestOptions.none()) /** @see add */ fun add( - params: MemoryAddParams = MemoryAddParams.none(), + params: MemoryAddParams, requestOptions: RequestOptions = RequestOptions.none(), - ) - - /** @see add */ - fun add(params: MemoryAddParams = MemoryAddParams.none()) = add(params, RequestOptions.none()) - - /** @see add */ - fun add(requestOptions: RequestOptions) = add(MemoryAddParams.none(), requestOptions) + ): MemoryAddResponse /** A view of [MemoryService] that provides access to raw HTTP responses for each method. */ interface WithRawResponse { @@ -86,69 +67,44 @@ interface MemoryService { * Returns a raw HTTP response for `post /api/v1/context/memory/update`, but is otherwise * the same as [MemoryService.update]. */ - @MustBeClosed fun update(): HttpResponse = update(MemoryUpdateParams.none()) - - /** @see update */ - @MustBeClosed - fun update( - params: MemoryUpdateParams = MemoryUpdateParams.none(), - requestOptions: RequestOptions = RequestOptions.none(), - ): HttpResponse - - /** @see update */ @MustBeClosed - fun update(params: MemoryUpdateParams = MemoryUpdateParams.none()): HttpResponse = + fun update(params: MemoryUpdateParams): HttpResponseFor = update(params, RequestOptions.none()) /** @see update */ @MustBeClosed - fun update(requestOptions: RequestOptions): HttpResponse = - update(MemoryUpdateParams.none(), requestOptions) + fun update( + params: MemoryUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor /** * Returns a raw HTTP response for `post /api/v1/context/memory/delete`, but is otherwise * the same as [MemoryService.delete]. */ - @MustBeClosed fun delete(): HttpResponse = delete(MemoryDeleteParams.none()) + @MustBeClosed + fun delete(params: MemoryDeleteParams): HttpResponse = delete(params, RequestOptions.none()) /** @see delete */ @MustBeClosed fun delete( - params: MemoryDeleteParams = MemoryDeleteParams.none(), + params: MemoryDeleteParams, requestOptions: RequestOptions = RequestOptions.none(), ): HttpResponse - /** @see delete */ - @MustBeClosed - fun delete(params: MemoryDeleteParams = MemoryDeleteParams.none()): HttpResponse = - delete(params, RequestOptions.none()) - - /** @see delete */ - @MustBeClosed - fun delete(requestOptions: RequestOptions): HttpResponse = - delete(MemoryDeleteParams.none(), requestOptions) - /** * Returns a raw HTTP response for `post /api/v1/context/memory/add`, but is otherwise the * same as [MemoryService.add]. */ - @MustBeClosed fun add(): HttpResponse = add(MemoryAddParams.none()) - - /** @see add */ - @MustBeClosed - fun add( - params: MemoryAddParams = MemoryAddParams.none(), - requestOptions: RequestOptions = RequestOptions.none(), - ): HttpResponse - - /** @see add */ @MustBeClosed - fun add(params: MemoryAddParams = MemoryAddParams.none()): HttpResponse = + fun add(params: MemoryAddParams): HttpResponseFor = add(params, RequestOptions.none()) /** @see add */ @MustBeClosed - fun add(requestOptions: RequestOptions): HttpResponse = - add(MemoryAddParams.none(), requestOptions) + fun add( + params: MemoryAddParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor } } diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/MemoryServiceImpl.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/MemoryServiceImpl.kt index f27dd80..a5fadbf 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/MemoryServiceImpl.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/MemoryServiceImpl.kt @@ -7,16 +7,20 @@ import com.alchemystai.sdk.core.RequestOptions import com.alchemystai.sdk.core.handlers.emptyHandler import com.alchemystai.sdk.core.handlers.errorBodyHandler import com.alchemystai.sdk.core.handlers.errorHandler +import com.alchemystai.sdk.core.handlers.jsonHandler import com.alchemystai.sdk.core.http.HttpMethod import com.alchemystai.sdk.core.http.HttpRequest import com.alchemystai.sdk.core.http.HttpResponse import com.alchemystai.sdk.core.http.HttpResponse.Handler +import com.alchemystai.sdk.core.http.HttpResponseFor import com.alchemystai.sdk.core.http.json import com.alchemystai.sdk.core.http.parseable import com.alchemystai.sdk.core.prepare import com.alchemystai.sdk.models.v1.context.memory.MemoryAddParams +import com.alchemystai.sdk.models.v1.context.memory.MemoryAddResponse import com.alchemystai.sdk.models.v1.context.memory.MemoryDeleteParams import com.alchemystai.sdk.models.v1.context.memory.MemoryUpdateParams +import com.alchemystai.sdk.models.v1.context.memory.MemoryUpdateResponse import java.util.function.Consumer class MemoryServiceImpl internal constructor(private val clientOptions: ClientOptions) : @@ -31,20 +35,21 @@ class MemoryServiceImpl internal constructor(private val clientOptions: ClientOp override fun withOptions(modifier: Consumer): MemoryService = MemoryServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) - override fun update(params: MemoryUpdateParams, requestOptions: RequestOptions) { + override fun update( + params: MemoryUpdateParams, + requestOptions: RequestOptions, + ): MemoryUpdateResponse = // post /api/v1/context/memory/update - withRawResponse().update(params, requestOptions) - } + withRawResponse().update(params, requestOptions).parse() override fun delete(params: MemoryDeleteParams, requestOptions: RequestOptions) { // post /api/v1/context/memory/delete withRawResponse().delete(params, requestOptions) } - override fun add(params: MemoryAddParams, requestOptions: RequestOptions) { + override fun add(params: MemoryAddParams, requestOptions: RequestOptions): MemoryAddResponse = // post /api/v1/context/memory/add - withRawResponse().add(params, requestOptions) - } + withRawResponse().add(params, requestOptions).parse() class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : MemoryService.WithRawResponse { @@ -59,12 +64,13 @@ class MemoryServiceImpl internal constructor(private val clientOptions: ClientOp clientOptions.toBuilder().apply(modifier::accept).build() ) - private val updateHandler: Handler = emptyHandler() + private val updateHandler: Handler = + jsonHandler(clientOptions.jsonMapper) override fun update( params: MemoryUpdateParams, requestOptions: RequestOptions, - ): HttpResponse { + ): HttpResponseFor { val request = HttpRequest.builder() .method(HttpMethod.POST) @@ -76,7 +82,13 @@ class MemoryServiceImpl internal constructor(private val clientOptions: ClientOp val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) return errorHandler.handle(response).parseable { - response.use { updateHandler.handle(it) } + response + .use { updateHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } } } @@ -101,9 +113,13 @@ class MemoryServiceImpl internal constructor(private val clientOptions: ClientOp } } - private val addHandler: Handler = emptyHandler() + private val addHandler: Handler = + jsonHandler(clientOptions.jsonMapper) - override fun add(params: MemoryAddParams, requestOptions: RequestOptions): HttpResponse { + override fun add( + params: MemoryAddParams, + requestOptions: RequestOptions, + ): HttpResponseFor { val request = HttpRequest.builder() .method(HttpMethod.POST) @@ -115,7 +131,13 @@ class MemoryServiceImpl internal constructor(private val clientOptions: ClientOp val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) val response = clientOptions.httpClient.execute(request, requestOptions) return errorHandler.handle(response).parseable { - response.use { addHandler.handle(it) } + response + .use { addHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } } } } diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/TraceService.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/TraceService.kt index fb5b5c5..e74cc2e 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/TraceService.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/TraceService.kt @@ -26,7 +26,7 @@ interface TraceService { */ fun withOptions(modifier: Consumer): TraceService - /** Retrieves a list of traces for the authenticated user */ + /** Returns paginated traces for the authenticated user within their organization. */ fun list(): TraceListResponse = list(TraceListParams.none()) /** @see list */ @@ -43,7 +43,7 @@ interface TraceService { fun list(requestOptions: RequestOptions): TraceListResponse = list(TraceListParams.none(), requestOptions) - /** Deletes a data trace for the authenticated user with the specified trace ID */ + /** Deletes a data trace for the authenticated user with the specified trace ID. */ fun delete(traceId: String): TraceDeleteResponse = delete(traceId, TraceDeleteParams.none()) /** @see delete */ diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/ViewService.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/ViewService.kt index a325d90..94d9ebe 100644 --- a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/ViewService.kt +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/ViewService.kt @@ -26,7 +26,7 @@ interface ViewService { */ fun withOptions(modifier: Consumer): ViewService - /** Gets the context information for the authenticated user */ + /** Gets the context information for the authenticated user. */ fun retrieve(): ViewRetrieveResponse = retrieve(ViewRetrieveParams.none()) /** @see retrieve */ @@ -43,7 +43,7 @@ interface ViewService { fun retrieve(requestOptions: RequestOptions): ViewRetrieveResponse = retrieve(ViewRetrieveParams.none(), requestOptions) - /** Fetches documents view for authenticated user with optional organization context */ + /** Fetches documents view for authenticated user with optional organization context. */ fun docs(): ViewDocsResponse = docs(ViewDocsParams.none()) /** @see docs */ diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/addasync/StatusService.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/addasync/StatusService.kt new file mode 100644 index 0000000..e273c03 --- /dev/null +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/addasync/StatusService.kt @@ -0,0 +1,158 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.services.blocking.v1.context.addasync + +import com.alchemystai.sdk.core.ClientOptions +import com.alchemystai.sdk.core.RequestOptions +import com.alchemystai.sdk.core.http.HttpResponseFor +import com.alchemystai.sdk.models.v1.context.addasync.status.StatusListParams +import com.alchemystai.sdk.models.v1.context.addasync.status.StatusListResponse +import com.alchemystai.sdk.models.v1.context.addasync.status.StatusRetrieveParams +import com.alchemystai.sdk.models.v1.context.addasync.status.StatusRetrieveResponse +import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer + +interface StatusService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): StatusService + + /** Returns the status and result of a context add job by job id. */ + fun retrieve(id: String): StatusRetrieveResponse = retrieve(id, StatusRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + id: String, + params: StatusRetrieveParams = StatusRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): StatusRetrieveResponse = retrieve(params.toBuilder().id(id).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + id: String, + params: StatusRetrieveParams = StatusRetrieveParams.none(), + ): StatusRetrieveResponse = retrieve(id, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: StatusRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): StatusRetrieveResponse + + /** @see retrieve */ + fun retrieve(params: StatusRetrieveParams): StatusRetrieveResponse = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(id: String, requestOptions: RequestOptions): StatusRetrieveResponse = + retrieve(id, StatusRetrieveParams.none(), requestOptions) + + /** + * Returns all jobs (active, waiting, delayed, failed, completed) belonging to the authenticated + * user. + */ + fun list(): StatusListResponse = list(StatusListParams.none()) + + /** @see list */ + fun list( + params: StatusListParams = StatusListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): StatusListResponse + + /** @see list */ + fun list(params: StatusListParams = StatusListParams.none()): StatusListResponse = + list(params, RequestOptions.none()) + + /** @see list */ + fun list(requestOptions: RequestOptions): StatusListResponse = + list(StatusListParams.none(), requestOptions) + + /** A view of [StatusService] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): StatusService.WithRawResponse + + /** + * Returns a raw HTTP response for `get /api/v1/context/add-async/{id}/status`, but is + * otherwise the same as [StatusService.retrieve]. + */ + @MustBeClosed + fun retrieve(id: String): HttpResponseFor = + retrieve(id, StatusRetrieveParams.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + id: String, + params: StatusRetrieveParams = StatusRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().id(id).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + id: String, + params: StatusRetrieveParams = StatusRetrieveParams.none(), + ): HttpResponseFor = retrieve(id, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: StatusRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: StatusRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + id: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(id, StatusRetrieveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /api/v1/context/add-async/status`, but is otherwise + * the same as [StatusService.list]. + */ + @MustBeClosed + fun list(): HttpResponseFor = list(StatusListParams.none()) + + /** @see list */ + @MustBeClosed + fun list( + params: StatusListParams = StatusListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see list */ + @MustBeClosed + fun list( + params: StatusListParams = StatusListParams.none() + ): HttpResponseFor = list(params, RequestOptions.none()) + + /** @see list */ + @MustBeClosed + fun list(requestOptions: RequestOptions): HttpResponseFor = + list(StatusListParams.none(), requestOptions) + } +} diff --git a/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/addasync/StatusServiceImpl.kt b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/addasync/StatusServiceImpl.kt new file mode 100644 index 0000000..4749e36 --- /dev/null +++ b/alchemyst-ai-java-core/src/main/kotlin/com/alchemystai/sdk/services/blocking/v1/context/addasync/StatusServiceImpl.kt @@ -0,0 +1,128 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.services.blocking.v1.context.addasync + +import com.alchemystai.sdk.core.ClientOptions +import com.alchemystai.sdk.core.RequestOptions +import com.alchemystai.sdk.core.checkRequired +import com.alchemystai.sdk.core.handlers.errorBodyHandler +import com.alchemystai.sdk.core.handlers.errorHandler +import com.alchemystai.sdk.core.handlers.jsonHandler +import com.alchemystai.sdk.core.http.HttpMethod +import com.alchemystai.sdk.core.http.HttpRequest +import com.alchemystai.sdk.core.http.HttpResponse +import com.alchemystai.sdk.core.http.HttpResponse.Handler +import com.alchemystai.sdk.core.http.HttpResponseFor +import com.alchemystai.sdk.core.http.parseable +import com.alchemystai.sdk.core.prepare +import com.alchemystai.sdk.models.v1.context.addasync.status.StatusListParams +import com.alchemystai.sdk.models.v1.context.addasync.status.StatusListResponse +import com.alchemystai.sdk.models.v1.context.addasync.status.StatusRetrieveParams +import com.alchemystai.sdk.models.v1.context.addasync.status.StatusRetrieveResponse +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class StatusServiceImpl internal constructor(private val clientOptions: ClientOptions) : + StatusService { + + private val withRawResponse: StatusService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): StatusService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): StatusService = + StatusServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun retrieve( + params: StatusRetrieveParams, + requestOptions: RequestOptions, + ): StatusRetrieveResponse = + // get /api/v1/context/add-async/{id}/status + withRawResponse().retrieve(params, requestOptions).parse() + + override fun list( + params: StatusListParams, + requestOptions: RequestOptions, + ): StatusListResponse = + // get /api/v1/context/add-async/status + withRawResponse().list(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + StatusService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): StatusService.WithRawResponse = + StatusServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: StatusRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "api", + "v1", + "context", + "add-async", + params._pathParam(0), + "status", + ) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: StatusListParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("api", "v1", "context", "add-async", "status") + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } +} diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/core/ObjectMappersTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/core/ObjectMappersTest.kt index 236b908..b9961fc 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/core/ObjectMappersTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/core/ObjectMappersTest.kt @@ -3,12 +3,14 @@ package com.alchemystai.sdk.core import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.databind.exc.MismatchedInputException import com.fasterxml.jackson.module.kotlin.readValue -import java.time.LocalDateTime +import java.time.LocalDate +import java.time.LocalTime +import java.time.OffsetDateTime +import java.time.ZoneOffset import kotlin.reflect.KClass import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.catchThrowable import org.junit.jupiter.api.Test -import org.junit.jupiter.api.assertDoesNotThrow import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.EnumSource import org.junitpioneer.jupiter.cartesian.CartesianTest @@ -46,11 +48,7 @@ internal class ObjectMappersTest { val VALID_CONVERSIONS = listOf( FLOAT to DOUBLE, - FLOAT to INTEGER, - FLOAT to LONG, DOUBLE to FLOAT, - DOUBLE to INTEGER, - DOUBLE to LONG, INTEGER to FLOAT, INTEGER to DOUBLE, INTEGER to LONG, @@ -58,14 +56,6 @@ internal class ObjectMappersTest { LONG to DOUBLE, LONG to INTEGER, CLASS to MAP, - // These aren't actually valid, but coercion configs don't work for String until - // v2.14.0: https://github.com/FasterXML/jackson-databind/issues/3240 - // We currently test on v2.13.4. - BOOLEAN to STRING, - FLOAT to STRING, - DOUBLE to STRING, - INTEGER to STRING, - LONG to STRING, ) } } @@ -84,19 +74,44 @@ internal class ObjectMappersTest { } } - enum class LenientLocalDateTimeTestCase(val string: String) { - DATE("1998-04-21"), - DATE_TIME("1998-04-21T04:00:00"), - ZONED_DATE_TIME_1("1998-04-21T04:00:00+03:00"), - ZONED_DATE_TIME_2("1998-04-21T04:00:00Z"), + enum class LenientOffsetDateTimeTestCase( + val string: String, + val expectedOffsetDateTime: OffsetDateTime, + ) { + DATE( + "1998-04-21", + expectedOffsetDateTime = + OffsetDateTime.of(LocalDate.of(1998, 4, 21), LocalTime.of(0, 0), ZoneOffset.UTC), + ), + DATE_TIME( + "1998-04-21T04:00:00", + expectedOffsetDateTime = + OffsetDateTime.of(LocalDate.of(1998, 4, 21), LocalTime.of(4, 0), ZoneOffset.UTC), + ), + ZONED_DATE_TIME_1( + "1998-04-21T04:00:00+03:00", + expectedOffsetDateTime = + OffsetDateTime.of( + LocalDate.of(1998, 4, 21), + LocalTime.of(4, 0), + ZoneOffset.ofHours(3), + ), + ), + ZONED_DATE_TIME_2( + "1998-04-21T04:00:00Z", + expectedOffsetDateTime = + OffsetDateTime.of(LocalDate.of(1998, 4, 21), LocalTime.of(4, 0), ZoneOffset.UTC), + ), } @ParameterizedTest @EnumSource - fun readLocalDateTime_lenient(testCase: LenientLocalDateTimeTestCase) { + fun readOffsetDateTime_lenient(testCase: LenientOffsetDateTimeTestCase) { val jsonMapper = jsonMapper() val json = jsonMapper.writeValueAsString(testCase.string) - assertDoesNotThrow { jsonMapper().readValue(json) } + val offsetDateTime = jsonMapper().readValue(json) + + assertThat(offsetDateTime).isEqualTo(testCase.expectedOffsetDateTime) } } diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/core/http/HttpRequestTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/core/http/HttpRequestTest.kt new file mode 100644 index 0000000..61d97c8 --- /dev/null +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/core/http/HttpRequestTest.kt @@ -0,0 +1,110 @@ +package com.alchemystai.sdk.core.http + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.EnumSource + +internal class HttpRequestTest { + + 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/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/ContextAddParamsTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/ContextAddParamsTest.kt index 9d87f36..3acfb03 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/ContextAddParamsTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/ContextAddParamsTest.kt @@ -2,7 +2,6 @@ package com.alchemystai.sdk.models.v1.context -import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -12,18 +11,23 @@ internal class ContextAddParamsTest { fun create() { ContextAddParams.builder() .contextType(ContextAddParams.ContextType.RESOURCE) - .addDocument(ContextAddParams.Document.builder().content("content").build()) + .addDocument( + ContextAddParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(ContextAddParams.Scope.INTERNAL) + .source("support-inbox") .metadata( ContextAddParams.Metadata.builder() - .fileName("fileName") - .fileSize(0.0) - .fileType("fileType") - .addGroupName("string") - .lastModified("lastModified") + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") .build() ) - .scope(ContextAddParams.Scope.INTERNAL) - .source("source") .build() } @@ -32,43 +36,64 @@ internal class ContextAddParamsTest { val params = ContextAddParams.builder() .contextType(ContextAddParams.ContextType.RESOURCE) - .addDocument(ContextAddParams.Document.builder().content("content").build()) + .addDocument( + ContextAddParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(ContextAddParams.Scope.INTERNAL) + .source("support-inbox") .metadata( ContextAddParams.Metadata.builder() - .fileName("fileName") - .fileSize(0.0) - .fileType("fileType") - .addGroupName("string") - .lastModified("lastModified") + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") .build() ) - .scope(ContextAddParams.Scope.INTERNAL) - .source("source") .build() val body = params._body() - assertThat(body.contextType()).contains(ContextAddParams.ContextType.RESOURCE) - assertThat(body.documents().getOrNull()) - .containsExactly(ContextAddParams.Document.builder().content("content").build()) + assertThat(body.contextType()).isEqualTo(ContextAddParams.ContextType.RESOURCE) + assertThat(body.documents()) + .containsExactly( + ContextAddParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + assertThat(body.scope()).isEqualTo(ContextAddParams.Scope.INTERNAL) + assertThat(body.source()).isEqualTo("support-inbox") assertThat(body.metadata()) .contains( ContextAddParams.Metadata.builder() - .fileName("fileName") - .fileSize(0.0) - .fileType("fileType") - .addGroupName("string") - .lastModified("lastModified") + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") .build() ) - assertThat(body.scope()).contains(ContextAddParams.Scope.INTERNAL) - assertThat(body.source()).contains("source") } @Test fun bodyWithoutOptionalFields() { - val params = ContextAddParams.builder().build() + val params = + ContextAddParams.builder() + .contextType(ContextAddParams.ContextType.RESOURCE) + .addDocument(ContextAddParams.Document.builder().build()) + .scope(ContextAddParams.Scope.INTERNAL) + .source("support-inbox") + .build() val body = params._body() + + assertThat(body.contextType()).isEqualTo(ContextAddParams.ContextType.RESOURCE) + assertThat(body.documents()).containsExactly(ContextAddParams.Document.builder().build()) + assertThat(body.scope()).isEqualTo(ContextAddParams.Scope.INTERNAL) + assertThat(body.source()).isEqualTo("support-inbox") } } diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/ContextAddResponseTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/ContextAddResponseTest.kt index 7d96a2c..7bc0be5 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/ContextAddResponseTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/ContextAddResponseTest.kt @@ -11,13 +11,27 @@ internal class ContextAddResponseTest { @Test fun create() { - val contextAddResponse = ContextAddResponse.builder().build() + val contextAddResponse = + ContextAddResponse.builder() + .contextId("ctx_01HXYZABC") + .success(true) + .processedDocuments(2.0) + .build() + + assertThat(contextAddResponse.contextId()).isEqualTo("ctx_01HXYZABC") + assertThat(contextAddResponse.success()).isEqualTo(true) + assertThat(contextAddResponse.processedDocuments()).contains(2.0) } @Test fun roundtrip() { val jsonMapper = jsonMapper() - val contextAddResponse = ContextAddResponse.builder().build() + val contextAddResponse = + ContextAddResponse.builder() + .contextId("ctx_01HXYZABC") + .success(true) + .processedDocuments(2.0) + .build() val roundtrippedContextAddResponse = jsonMapper.readValue( diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/ContextDeleteParamsTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/ContextDeleteParamsTest.kt index de5d378..7ca88c8 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/ContextDeleteParamsTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/ContextDeleteParamsTest.kt @@ -10,10 +10,10 @@ internal class ContextDeleteParamsTest { @Test fun create() { ContextDeleteParams.builder() + .organizationId("org_01HXYZABC") + .source("support-inbox") .byDoc(true) - .byId(true) - .organizationId("organization_id") - .source("source") + .byId(false) .userId("user_id") .build() } @@ -22,26 +22,33 @@ internal class ContextDeleteParamsTest { fun body() { val params = ContextDeleteParams.builder() + .organizationId("org_01HXYZABC") + .source("support-inbox") .byDoc(true) - .byId(true) - .organizationId("organization_id") - .source("source") + .byId(false) .userId("user_id") .build() val body = params._body() + assertThat(body.organizationId()).isEqualTo("org_01HXYZABC") + assertThat(body.source()).isEqualTo("support-inbox") assertThat(body.byDoc()).contains(true) - assertThat(body.byId()).contains(true) - assertThat(body.organizationId()).contains("organization_id") - assertThat(body.source()).contains("source") + assertThat(body.byId()).contains(false) assertThat(body.userId()).contains("user_id") } @Test fun bodyWithoutOptionalFields() { - val params = ContextDeleteParams.builder().build() + val params = + ContextDeleteParams.builder() + .organizationId("org_01HXYZABC") + .source("support-inbox") + .build() val body = params._body() + + assertThat(body.organizationId()).isEqualTo("org_01HXYZABC") + assertThat(body.source()).isEqualTo("support-inbox") } } diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/ContextSearchParamsTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/ContextSearchParamsTest.kt index fd5a2e8..dd38e44 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/ContextSearchParamsTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/ContextSearchParamsTest.kt @@ -3,6 +3,7 @@ package com.alchemystai.sdk.models.v1.context import com.alchemystai.sdk.core.JsonValue +import com.alchemystai.sdk.core.http.QueryParams import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -11,23 +12,61 @@ internal class ContextSearchParamsTest { @Test fun create() { ContextSearchParams.builder() + .metadata(ContextSearchParams.Metadata.TRUE) + .mode(ContextSearchParams.Mode.FAST) .minimumSimilarityThreshold(0.5) - .query("search query for user preferences") + .query("What did the customer ask about pricing for the Scale plan?") .similarityThreshold(0.8) - .metadata(JsonValue.from(mapOf())) + .bodyMetadata(JsonValue.from(mapOf())) .scope(ContextSearchParams.Scope.INTERNAL) .userId("user123") .build() } + @Test + fun queryParams() { + val params = + ContextSearchParams.builder() + .metadata(ContextSearchParams.Metadata.TRUE) + .mode(ContextSearchParams.Mode.FAST) + .minimumSimilarityThreshold(0.5) + .query("What did the customer ask about pricing for the Scale plan?") + .similarityThreshold(0.8) + .bodyMetadata(JsonValue.from(mapOf())) + .scope(ContextSearchParams.Scope.INTERNAL) + .userId("user123") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo(QueryParams.builder().put("metadata", "true").put("mode", "fast").build()) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = + ContextSearchParams.builder() + .minimumSimilarityThreshold(0.5) + .query("What did the customer ask about pricing for the Scale plan?") + .similarityThreshold(0.8) + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } + @Test fun body() { val params = ContextSearchParams.builder() + .metadata(ContextSearchParams.Metadata.TRUE) + .mode(ContextSearchParams.Mode.FAST) .minimumSimilarityThreshold(0.5) - .query("search query for user preferences") + .query("What did the customer ask about pricing for the Scale plan?") .similarityThreshold(0.8) - .metadata(JsonValue.from(mapOf())) + .bodyMetadata(JsonValue.from(mapOf())) .scope(ContextSearchParams.Scope.INTERNAL) .userId("user123") .build() @@ -35,9 +74,10 @@ internal class ContextSearchParamsTest { val body = params._body() assertThat(body.minimumSimilarityThreshold()).isEqualTo(0.5) - assertThat(body.query()).isEqualTo("search query for user preferences") + assertThat(body.query()) + .isEqualTo("What did the customer ask about pricing for the Scale plan?") assertThat(body.similarityThreshold()).isEqualTo(0.8) - assertThat(body._metadata()).isEqualTo(JsonValue.from(mapOf())) + assertThat(body._bodyMetadata()).isEqualTo(JsonValue.from(mapOf())) assertThat(body.scope()).contains(ContextSearchParams.Scope.INTERNAL) assertThat(body.userId()).contains("user123") } @@ -47,14 +87,15 @@ internal class ContextSearchParamsTest { val params = ContextSearchParams.builder() .minimumSimilarityThreshold(0.5) - .query("search query for user preferences") + .query("What did the customer ask about pricing for the Scale plan?") .similarityThreshold(0.8) .build() val body = params._body() assertThat(body.minimumSimilarityThreshold()).isEqualTo(0.5) - assertThat(body.query()).isEqualTo("search query for user preferences") + assertThat(body.query()) + .isEqualTo("What did the customer ask about pricing for the Scale plan?") assertThat(body.similarityThreshold()).isEqualTo(0.8) } } diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/addasync/AddAsyncCancelParamsTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/addasync/AddAsyncCancelParamsTest.kt new file mode 100644 index 0000000..5310827 --- /dev/null +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/addasync/AddAsyncCancelParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.models.v1.context.addasync + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class AddAsyncCancelParamsTest { + + @Test + fun create() { + AddAsyncCancelParams.builder().id("id").build() + } + + @Test + fun pathParams() { + val params = AddAsyncCancelParams.builder().id("id").build() + + assertThat(params._pathParam(0)).isEqualTo("id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/addasync/AddAsyncCancelResponseTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/addasync/AddAsyncCancelResponseTest.kt new file mode 100644 index 0000000..72b8be9 --- /dev/null +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/addasync/AddAsyncCancelResponseTest.kt @@ -0,0 +1,47 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.models.v1.context.addasync + +import com.alchemystai.sdk.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class AddAsyncCancelResponseTest { + + @Test + fun create() { + val addAsyncCancelResponse = + AddAsyncCancelResponse.builder() + .jobId("job_01HXYZABC") + .message("Job cancelled successfully") + .status("cancelled") + .success(true) + .build() + + assertThat(addAsyncCancelResponse.jobId()).isEqualTo("job_01HXYZABC") + assertThat(addAsyncCancelResponse.message()).isEqualTo("Job cancelled successfully") + assertThat(addAsyncCancelResponse.status()).isEqualTo("cancelled") + assertThat(addAsyncCancelResponse.success()).isEqualTo(true) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val addAsyncCancelResponse = + AddAsyncCancelResponse.builder() + .jobId("job_01HXYZABC") + .message("Job cancelled successfully") + .status("cancelled") + .success(true) + .build() + + val roundtrippedAddAsyncCancelResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(addAsyncCancelResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedAddAsyncCancelResponse).isEqualTo(addAsyncCancelResponse) + } +} diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/addasync/AddAsyncCreateParamsTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/addasync/AddAsyncCreateParamsTest.kt new file mode 100644 index 0000000..5a301ad --- /dev/null +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/addasync/AddAsyncCreateParamsTest.kt @@ -0,0 +1,100 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.models.v1.context.addasync + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class AddAsyncCreateParamsTest { + + @Test + fun create() { + AddAsyncCreateParams.builder() + .contextType(AddAsyncCreateParams.ContextType.RESOURCE) + .addDocument( + AddAsyncCreateParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(AddAsyncCreateParams.Scope.INTERNAL) + .source("support-inbox") + .metadata( + AddAsyncCreateParams.Metadata.builder() + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") + .build() + ) + .build() + } + + @Test + fun body() { + val params = + AddAsyncCreateParams.builder() + .contextType(AddAsyncCreateParams.ContextType.RESOURCE) + .addDocument( + AddAsyncCreateParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(AddAsyncCreateParams.Scope.INTERNAL) + .source("support-inbox") + .metadata( + AddAsyncCreateParams.Metadata.builder() + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") + .build() + ) + .build() + + val body = params._body() + + assertThat(body.contextType()).isEqualTo(AddAsyncCreateParams.ContextType.RESOURCE) + assertThat(body.documents()) + .containsExactly( + AddAsyncCreateParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + assertThat(body.scope()).isEqualTo(AddAsyncCreateParams.Scope.INTERNAL) + assertThat(body.source()).isEqualTo("support-inbox") + assertThat(body.metadata()) + .contains( + AddAsyncCreateParams.Metadata.builder() + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") + .build() + ) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = + AddAsyncCreateParams.builder() + .contextType(AddAsyncCreateParams.ContextType.RESOURCE) + .addDocument(AddAsyncCreateParams.Document.builder().build()) + .scope(AddAsyncCreateParams.Scope.INTERNAL) + .source("support-inbox") + .build() + + val body = params._body() + + assertThat(body.contextType()).isEqualTo(AddAsyncCreateParams.ContextType.RESOURCE) + assertThat(body.documents()) + .containsExactly(AddAsyncCreateParams.Document.builder().build()) + assertThat(body.scope()).isEqualTo(AddAsyncCreateParams.Scope.INTERNAL) + assertThat(body.source()).isEqualTo("support-inbox") + } +} diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/addasync/AddAsyncCreateResponseTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/addasync/AddAsyncCreateResponseTest.kt new file mode 100644 index 0000000..21f1f9e --- /dev/null +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/addasync/AddAsyncCreateResponseTest.kt @@ -0,0 +1,35 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.models.v1.context.addasync + +import com.alchemystai.sdk.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class AddAsyncCreateResponseTest { + + @Test + fun create() { + val addAsyncCreateResponse = + AddAsyncCreateResponse.builder().jobId("context-add-123456").queued(true).build() + + assertThat(addAsyncCreateResponse.jobId()).isEqualTo("context-add-123456") + assertThat(addAsyncCreateResponse.queued()).isEqualTo(true) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val addAsyncCreateResponse = + AddAsyncCreateResponse.builder().jobId("context-add-123456").queued(true).build() + + val roundtrippedAddAsyncCreateResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(addAsyncCreateResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedAddAsyncCreateResponse).isEqualTo(addAsyncCreateResponse) + } +} diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/addasync/status/StatusListParamsTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/addasync/status/StatusListParamsTest.kt new file mode 100644 index 0000000..561d194 --- /dev/null +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/addasync/status/StatusListParamsTest.kt @@ -0,0 +1,49 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.models.v1.context.addasync.status + +import com.alchemystai.sdk.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class StatusListParamsTest { + + @Test + fun create() { + StatusListParams.builder() + .limit("limit") + .offset("offset") + .type(StatusListParams.Type.ALL) + .build() + } + + @Test + fun queryParams() { + val params = + StatusListParams.builder() + .limit("limit") + .offset("offset") + .type(StatusListParams.Type.ALL) + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("limit", "limit") + .put("offset", "offset") + .put("type", "all") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = StatusListParams.builder().build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/addasync/status/StatusListResponseTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/addasync/status/StatusListResponseTest.kt new file mode 100644 index 0000000..3403fc4 --- /dev/null +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/addasync/status/StatusListResponseTest.kt @@ -0,0 +1,73 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.models.v1.context.addasync.status + +import com.alchemystai.sdk.core.JsonValue +import com.alchemystai.sdk.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class StatusListResponseTest { + + @Test + fun create() { + val statusListResponse = + StatusListResponse.builder() + .addJob( + StatusListResponse.Job.builder() + .attemptsMade(1.0) + .data(JsonValue.from(mapOf())) + .jobId("12345") + .status("active") + .failedReason("Some error") + .finishedOn(1712345678901.0) + .processedOn(1712345678900.0) + .build() + ) + .success(true) + .build() + + assertThat(statusListResponse.jobs()) + .containsExactly( + StatusListResponse.Job.builder() + .attemptsMade(1.0) + .data(JsonValue.from(mapOf())) + .jobId("12345") + .status("active") + .failedReason("Some error") + .finishedOn(1712345678901.0) + .processedOn(1712345678900.0) + .build() + ) + assertThat(statusListResponse.success()).isEqualTo(true) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val statusListResponse = + StatusListResponse.builder() + .addJob( + StatusListResponse.Job.builder() + .attemptsMade(1.0) + .data(JsonValue.from(mapOf())) + .jobId("12345") + .status("active") + .failedReason("Some error") + .finishedOn(1712345678901.0) + .processedOn(1712345678900.0) + .build() + ) + .success(true) + .build() + + val roundtrippedStatusListResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(statusListResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedStatusListResponse).isEqualTo(statusListResponse) + } +} diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/addasync/status/StatusRetrieveParamsTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/addasync/status/StatusRetrieveParamsTest.kt new file mode 100644 index 0000000..ad2444e --- /dev/null +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/addasync/status/StatusRetrieveParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.models.v1.context.addasync.status + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class StatusRetrieveParamsTest { + + @Test + fun create() { + StatusRetrieveParams.builder().id("id").build() + } + + @Test + fun pathParams() { + val params = StatusRetrieveParams.builder().id("id").build() + + assertThat(params._pathParam(0)).isEqualTo("id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/addasync/status/StatusRetrieveResponseTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/addasync/status/StatusRetrieveResponseTest.kt new file mode 100644 index 0000000..3034931 --- /dev/null +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/addasync/status/StatusRetrieveResponseTest.kt @@ -0,0 +1,60 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.models.v1.context.addasync.status + +import com.alchemystai.sdk.core.JsonValue +import com.alchemystai.sdk.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class StatusRetrieveResponseTest { + + @Test + fun create() { + val statusRetrieveResponse = + StatusRetrieveResponse.builder() + .jobId("job_01HXYZABC") + .status("completed") + .success(true) + .attemptsMade(1.0) + .failedReason("") + .finishedOn(1712345678901.0) + .processedOn(1712345670000.0) + .result(JsonValue.from(mapOf())) + .build() + + assertThat(statusRetrieveResponse.jobId()).isEqualTo("job_01HXYZABC") + assertThat(statusRetrieveResponse.status()).isEqualTo("completed") + assertThat(statusRetrieveResponse.success()).isEqualTo(true) + assertThat(statusRetrieveResponse.attemptsMade()).contains(1.0) + assertThat(statusRetrieveResponse.failedReason()).contains("") + assertThat(statusRetrieveResponse.finishedOn()).contains(1712345678901.0) + assertThat(statusRetrieveResponse.processedOn()).contains(1712345670000.0) + assertThat(statusRetrieveResponse._result()).isEqualTo(JsonValue.from(mapOf())) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val statusRetrieveResponse = + StatusRetrieveResponse.builder() + .jobId("job_01HXYZABC") + .status("completed") + .success(true) + .attemptsMade(1.0) + .failedReason("") + .finishedOn(1712345678901.0) + .processedOn(1712345670000.0) + .result(JsonValue.from(mapOf())) + .build() + + val roundtrippedStatusRetrieveResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(statusRetrieveResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedStatusRetrieveResponse).isEqualTo(statusRetrieveResponse) + } +} diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryAddParamsTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryAddParamsTest.kt index a35c718..80909df 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryAddParamsTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryAddParamsTest.kt @@ -2,7 +2,6 @@ package com.alchemystai.sdk.models.v1.context.memory -import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -11,8 +10,16 @@ internal class MemoryAddParamsTest { @Test fun create() { MemoryAddParams.builder() - .addContent(MemoryAddParams.Content.builder().content("content").build()) - .memoryId("memoryId") + .addContent( + MemoryAddParams.Content.builder() + .content("Customer asked about pricing for the Scale plan.") + .metadata( + MemoryAddParams.Content.Metadata.builder().messageId("messageId").build() + ) + .build() + ) + .sessionId("support-thread-TCK-1234") + .metadata(MemoryAddParams.Metadata.builder().addGroupName("string").build()) .build() } @@ -20,21 +27,56 @@ internal class MemoryAddParamsTest { fun body() { val params = MemoryAddParams.builder() - .addContent(MemoryAddParams.Content.builder().content("content").build()) - .memoryId("memoryId") + .addContent( + MemoryAddParams.Content.builder() + .content("Customer asked about pricing for the Scale plan.") + .metadata( + MemoryAddParams.Content.Metadata.builder() + .messageId("messageId") + .build() + ) + .build() + ) + .sessionId("support-thread-TCK-1234") + .metadata(MemoryAddParams.Metadata.builder().addGroupName("string").build()) .build() val body = params._body() - assertThat(body.contents().getOrNull()) - .containsExactly(MemoryAddParams.Content.builder().content("content").build()) - assertThat(body.memoryId()).contains("memoryId") + assertThat(body.contents()) + .containsExactly( + MemoryAddParams.Content.builder() + .content("Customer asked about pricing for the Scale plan.") + .metadata( + MemoryAddParams.Content.Metadata.builder().messageId("messageId").build() + ) + .build() + ) + assertThat(body.sessionId()).isEqualTo("support-thread-TCK-1234") + assertThat(body.metadata()) + .contains(MemoryAddParams.Metadata.builder().addGroupName("string").build()) } @Test fun bodyWithoutOptionalFields() { - val params = MemoryAddParams.builder().build() + val params = + MemoryAddParams.builder() + .addContent( + MemoryAddParams.Content.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .sessionId("support-thread-TCK-1234") + .build() val body = params._body() + + assertThat(body.contents()) + .containsExactly( + MemoryAddParams.Content.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + assertThat(body.sessionId()).isEqualTo("support-thread-TCK-1234") } } diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryAddResponseTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryAddResponseTest.kt new file mode 100644 index 0000000..be2ce93 --- /dev/null +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryAddResponseTest.kt @@ -0,0 +1,44 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.models.v1.context.memory + +import com.alchemystai.sdk.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class MemoryAddResponseTest { + + @Test + fun create() { + val memoryAddResponse = + MemoryAddResponse.builder() + .contextId("ctx_01HXYZABC") + .success(true) + .processedDocuments(2.0) + .build() + + assertThat(memoryAddResponse.contextId()).isEqualTo("ctx_01HXYZABC") + assertThat(memoryAddResponse.success()).isEqualTo(true) + assertThat(memoryAddResponse.processedDocuments()).contains(2.0) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val memoryAddResponse = + MemoryAddResponse.builder() + .contextId("ctx_01HXYZABC") + .success(true) + .processedDocuments(2.0) + .build() + + val roundtrippedMemoryAddResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(memoryAddResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedMemoryAddResponse).isEqualTo(memoryAddResponse) + } +} diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryDeleteParamsTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryDeleteParamsTest.kt index 7abb8d6..764825c 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryDeleteParamsTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryDeleteParamsTest.kt @@ -10,8 +10,10 @@ internal class MemoryDeleteParamsTest { @Test fun create() { MemoryDeleteParams.builder() - .memoryId("memoryId") - .organizationId("organization_id") + .memoryId("support-thread-TCK-1234") + .organizationId("org_01HXYZABC") + .byDoc(true) + .byId(false) .userId("user_id") .build() } @@ -20,22 +22,33 @@ internal class MemoryDeleteParamsTest { fun body() { val params = MemoryDeleteParams.builder() - .memoryId("memoryId") - .organizationId("organization_id") + .memoryId("support-thread-TCK-1234") + .organizationId("org_01HXYZABC") + .byDoc(true) + .byId(false) .userId("user_id") .build() val body = params._body() - assertThat(body.memoryId()).contains("memoryId") - assertThat(body.organizationId()).contains("organization_id") + assertThat(body.memoryId()).isEqualTo("support-thread-TCK-1234") + assertThat(body.organizationId()).contains("org_01HXYZABC") + assertThat(body.byDoc()).contains(true) + assertThat(body.byId()).contains(false) assertThat(body.userId()).contains("user_id") } @Test fun bodyWithoutOptionalFields() { - val params = MemoryDeleteParams.builder().build() + val params = + MemoryDeleteParams.builder() + .memoryId("support-thread-TCK-1234") + .organizationId("org_01HXYZABC") + .build() val body = params._body() + + assertThat(body.memoryId()).isEqualTo("support-thread-TCK-1234") + assertThat(body.organizationId()).contains("org_01HXYZABC") } } diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryUpdateParamsTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryUpdateParamsTest.kt index 03d37a1..fec4b23 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryUpdateParamsTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryUpdateParamsTest.kt @@ -2,7 +2,7 @@ package com.alchemystai.sdk.models.v1.context.memory -import kotlin.jvm.optionals.getOrNull +import com.alchemystai.sdk.core.JsonValue import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -11,8 +11,33 @@ internal class MemoryUpdateParamsTest { @Test fun create() { MemoryUpdateParams.builder() - .addContent(MemoryUpdateParams.Content.builder().content("content").build()) - .memoryId("memoryId") + .addContent( + MemoryUpdateParams.Content.builder() + .id("msg-1") + .content("Customer asked about pricing for the Scale plan.") + .createdAt("2025-01-10T12:34:56.000Z") + .metadata( + MemoryUpdateParams.Content.Metadata.builder() + .putAdditionalProperty("messageId", JsonValue.from("bar")) + .build() + ) + .role("user") + .build() + ) + .addContent( + MemoryUpdateParams.Content.builder() + .id("msg-2") + .content("Updated answer about the Scale plan pricing after discounts.") + .createdAt("2025-01-10T12:36:00.000Z") + .metadata( + MemoryUpdateParams.Content.Metadata.builder() + .putAdditionalProperty("messageId", JsonValue.from("bar")) + .build() + ) + .role("assistant") + .build() + ) + .sessionId("support-thread-TCK-1234") .build() } @@ -20,21 +45,81 @@ internal class MemoryUpdateParamsTest { fun body() { val params = MemoryUpdateParams.builder() - .addContent(MemoryUpdateParams.Content.builder().content("content").build()) - .memoryId("memoryId") + .addContent( + MemoryUpdateParams.Content.builder() + .id("msg-1") + .content("Customer asked about pricing for the Scale plan.") + .createdAt("2025-01-10T12:34:56.000Z") + .metadata( + MemoryUpdateParams.Content.Metadata.builder() + .putAdditionalProperty("messageId", JsonValue.from("bar")) + .build() + ) + .role("user") + .build() + ) + .addContent( + MemoryUpdateParams.Content.builder() + .id("msg-2") + .content("Updated answer about the Scale plan pricing after discounts.") + .createdAt("2025-01-10T12:36:00.000Z") + .metadata( + MemoryUpdateParams.Content.Metadata.builder() + .putAdditionalProperty("messageId", JsonValue.from("bar")) + .build() + ) + .role("assistant") + .build() + ) + .sessionId("support-thread-TCK-1234") .build() val body = params._body() - assertThat(body.contents().getOrNull()) - .containsExactly(MemoryUpdateParams.Content.builder().content("content").build()) - assertThat(body.memoryId()).contains("memoryId") + assertThat(body.contents()) + .containsExactly( + MemoryUpdateParams.Content.builder() + .id("msg-1") + .content("Customer asked about pricing for the Scale plan.") + .createdAt("2025-01-10T12:34:56.000Z") + .metadata( + MemoryUpdateParams.Content.Metadata.builder() + .putAdditionalProperty("messageId", JsonValue.from("bar")) + .build() + ) + .role("user") + .build(), + MemoryUpdateParams.Content.builder() + .id("msg-2") + .content("Updated answer about the Scale plan pricing after discounts.") + .createdAt("2025-01-10T12:36:00.000Z") + .metadata( + MemoryUpdateParams.Content.Metadata.builder() + .putAdditionalProperty("messageId", JsonValue.from("bar")) + .build() + ) + .role("assistant") + .build(), + ) + assertThat(body.sessionId()).isEqualTo("support-thread-TCK-1234") } @Test fun bodyWithoutOptionalFields() { - val params = MemoryUpdateParams.builder().build() + val params = + MemoryUpdateParams.builder() + .addContent(MemoryUpdateParams.Content.builder().build()) + .addContent(MemoryUpdateParams.Content.builder().build()) + .sessionId("support-thread-TCK-1234") + .build() val body = params._body() + + assertThat(body.contents()) + .containsExactly( + MemoryUpdateParams.Content.builder().build(), + MemoryUpdateParams.Content.builder().build(), + ) + assertThat(body.sessionId()).isEqualTo("support-thread-TCK-1234") } } diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryUpdateResponseTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryUpdateResponseTest.kt new file mode 100644 index 0000000..937de31 --- /dev/null +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/memory/MemoryUpdateResponseTest.kt @@ -0,0 +1,44 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.models.v1.context.memory + +import com.alchemystai.sdk.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class MemoryUpdateResponseTest { + + @Test + fun create() { + val memoryUpdateResponse = + MemoryUpdateResponse.builder() + .memoryId("support-thread-TCK-1234") + .success(true) + .updatedEntries(2.0) + .build() + + assertThat(memoryUpdateResponse.memoryId()).isEqualTo("support-thread-TCK-1234") + assertThat(memoryUpdateResponse.success()).isEqualTo(true) + assertThat(memoryUpdateResponse.updatedEntries()).isEqualTo(2.0) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val memoryUpdateResponse = + MemoryUpdateResponse.builder() + .memoryId("support-thread-TCK-1234") + .success(true) + .updatedEntries(2.0) + .build() + + val roundtrippedMemoryUpdateResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(memoryUpdateResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedMemoryUpdateResponse).isEqualTo(memoryUpdateResponse) + } +} diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceDeleteResponseTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceDeleteResponseTest.kt index 5d1a8d2..f4992e0 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceDeleteResponseTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceDeleteResponseTest.kt @@ -2,9 +2,9 @@ package com.alchemystai.sdk.models.v1.context.traces -import com.alchemystai.sdk.core.JsonValue import com.alchemystai.sdk.core.jsonMapper import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import java.time.OffsetDateTime import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -13,16 +13,73 @@ internal class TraceDeleteResponseTest { @Test fun create() { val traceDeleteResponse = - TraceDeleteResponse.builder().trace(JsonValue.from(mapOf())).build() + TraceDeleteResponse.builder() + .trace( + TraceDeleteResponse.Trace.builder() + ._id("trace_123") + .createdAt(OffsetDateTime.parse("2025-01-10T12:35:10.000Z")) + .data( + TraceDeleteResponse.Trace.Data.builder() + .fileName("support_thread_TCK-1234.txt") + .query( + "What did the customer ask about pricing for the Scale plan?" + ) + .source("support-inbox") + .build() + ) + .organizationId("org_123") + .type("context.search") + .updatedAt(OffsetDateTime.parse("2025-01-10T12:35:10.000Z")) + .userId("user_123") + .build() + ) + .build() - assertThat(traceDeleteResponse._trace()).isEqualTo(JsonValue.from(mapOf())) + assertThat(traceDeleteResponse.trace()) + .isEqualTo( + TraceDeleteResponse.Trace.builder() + ._id("trace_123") + .createdAt(OffsetDateTime.parse("2025-01-10T12:35:10.000Z")) + .data( + TraceDeleteResponse.Trace.Data.builder() + .fileName("support_thread_TCK-1234.txt") + .query("What did the customer ask about pricing for the Scale plan?") + .source("support-inbox") + .build() + ) + .organizationId("org_123") + .type("context.search") + .updatedAt(OffsetDateTime.parse("2025-01-10T12:35:10.000Z")) + .userId("user_123") + .build() + ) } @Test fun roundtrip() { val jsonMapper = jsonMapper() val traceDeleteResponse = - TraceDeleteResponse.builder().trace(JsonValue.from(mapOf())).build() + TraceDeleteResponse.builder() + .trace( + TraceDeleteResponse.Trace.builder() + ._id("trace_123") + .createdAt(OffsetDateTime.parse("2025-01-10T12:35:10.000Z")) + .data( + TraceDeleteResponse.Trace.Data.builder() + .fileName("support_thread_TCK-1234.txt") + .query( + "What did the customer ask about pricing for the Scale plan?" + ) + .source("support-inbox") + .build() + ) + .organizationId("org_123") + .type("context.search") + .updatedAt(OffsetDateTime.parse("2025-01-10T12:35:10.000Z")) + .userId("user_123") + .build() + ) + .build() val roundtrippedTraceDeleteResponse = jsonMapper.readValue( diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceListParamsTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceListParamsTest.kt index 3f1d856..24caae7 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceListParamsTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceListParamsTest.kt @@ -2,12 +2,33 @@ package com.alchemystai.sdk.models.v1.context.traces +import com.alchemystai.sdk.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test internal class TraceListParamsTest { @Test fun create() { - TraceListParams.builder().build() + TraceListParams.builder().limit(0L).page(0L).build() + } + + @Test + fun queryParams() { + val params = TraceListParams.builder().limit(0L).page(0L).build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo(QueryParams.builder().put("limit", "0").put("page", "0").build()) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = TraceListParams.builder().build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) } } diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceListResponseTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceListResponseTest.kt index c2bb5d4..513f3fb 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceListResponseTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/traces/TraceListResponseTest.kt @@ -6,7 +6,6 @@ import com.alchemystai.sdk.core.JsonValue import com.alchemystai.sdk.core.jsonMapper import com.fasterxml.jackson.module.kotlin.jacksonTypeRef import java.time.OffsetDateTime -import kotlin.jvm.optionals.getOrNull import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test @@ -16,11 +15,22 @@ internal class TraceListResponseTest { fun create() { val traceListResponse = TraceListResponse.builder() + .pagination( + TraceListResponse.Pagination.builder() + .hasNextPage(true) + .hasPrevPage(true) + .limit(0L) + .page(0L) + .total(0L) + .totalPages(0L) + .build() + ) .addTrace( TraceListResponse.Trace.builder() ._id("_id") .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .data(JsonValue.from(mapOf())) + .organizationId("organizationId") .type("type") .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .userId("userId") @@ -28,12 +38,24 @@ internal class TraceListResponseTest { ) .build() - assertThat(traceListResponse.traces().getOrNull()) + assertThat(traceListResponse.pagination()) + .isEqualTo( + TraceListResponse.Pagination.builder() + .hasNextPage(true) + .hasPrevPage(true) + .limit(0L) + .page(0L) + .total(0L) + .totalPages(0L) + .build() + ) + assertThat(traceListResponse.traces()) .containsExactly( TraceListResponse.Trace.builder() ._id("_id") .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .data(JsonValue.from(mapOf())) + .organizationId("organizationId") .type("type") .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .userId("userId") @@ -46,11 +68,22 @@ internal class TraceListResponseTest { val jsonMapper = jsonMapper() val traceListResponse = TraceListResponse.builder() + .pagination( + TraceListResponse.Pagination.builder() + .hasNextPage(true) + .hasPrevPage(true) + .limit(0L) + .page(0L) + .total(0L) + .totalPages(0L) + .build() + ) .addTrace( TraceListResponse.Trace.builder() ._id("_id") .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .data(JsonValue.from(mapOf())) + .organizationId("organizationId") .type("type") .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) .userId("userId") diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewDocsParamsTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewDocsParamsTest.kt index db5e1cb..ba888fe 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewDocsParamsTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewDocsParamsTest.kt @@ -2,12 +2,33 @@ package com.alchemystai.sdk.models.v1.context.view +import com.alchemystai.sdk.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test internal class ViewDocsParamsTest { @Test fun create() { - ViewDocsParams.builder().build() + ViewDocsParams.builder().magicKey("magic_key").build() + } + + @Test + fun queryParams() { + val params = ViewDocsParams.builder().magicKey("magic_key").build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo(QueryParams.builder().put("magic_key", "magic_key").build()) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = ViewDocsParams.builder().build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) } } diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewDocsResponseTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewDocsResponseTest.kt index 77a0423..bf04b91 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewDocsResponseTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewDocsResponseTest.kt @@ -11,13 +11,46 @@ internal class ViewDocsResponseTest { @Test fun create() { - val viewDocsResponse = ViewDocsResponse.builder().build() + val viewDocsResponse = + ViewDocsResponse.builder() + .addDocument( + ViewDocsResponse.Document.builder() + .fileName("fileName") + .fileSize(0.0) + .fileType("fileType") + .addGroupName("string") + .lastModified("lastModified") + .build() + ) + .build() + + assertThat(viewDocsResponse.documents()) + .containsExactly( + ViewDocsResponse.Document.builder() + .fileName("fileName") + .fileSize(0.0) + .fileType("fileType") + .addGroupName("string") + .lastModified("lastModified") + .build() + ) } @Test fun roundtrip() { val jsonMapper = jsonMapper() - val viewDocsResponse = ViewDocsResponse.builder().build() + val viewDocsResponse = + ViewDocsResponse.builder() + .addDocument( + ViewDocsResponse.Document.builder() + .fileName("fileName") + .fileSize(0.0) + .fileType("fileType") + .addGroupName("string") + .lastModified("lastModified") + .build() + ) + .build() val roundtrippedViewDocsResponse = jsonMapper.readValue( diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewRetrieveParamsTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewRetrieveParamsTest.kt index 74a0439..836e998 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewRetrieveParamsTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewRetrieveParamsTest.kt @@ -2,12 +2,39 @@ package com.alchemystai.sdk.models.v1.context.view +import com.alchemystai.sdk.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test internal class ViewRetrieveParamsTest { @Test fun create() { - ViewRetrieveParams.builder().build() + ViewRetrieveParams.builder().fileName("file_name").magicKey("magic_key").build() + } + + @Test + fun queryParams() { + val params = + ViewRetrieveParams.builder().fileName("file_name").magicKey("magic_key").build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("file_name", "file_name") + .put("magic_key", "magic_key") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = ViewRetrieveParams.builder().build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) } } diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewRetrieveResponseTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewRetrieveResponseTest.kt index a16c92b..84c1f54 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewRetrieveResponseTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/context/view/ViewRetrieveResponseTest.kt @@ -2,10 +2,8 @@ package com.alchemystai.sdk.models.v1.context.view -import com.alchemystai.sdk.core.JsonValue import com.alchemystai.sdk.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 @@ -14,17 +12,66 @@ internal class ViewRetrieveResponseTest { @Test fun create() { val viewRetrieveResponse = - ViewRetrieveResponse.builder().addContext(JsonValue.from(mapOf())).build() + ViewRetrieveResponse.builder() + .addContext( + ViewRetrieveResponse.Context.builder() + .content("Customer asked about pricing for the Scale plan.") + .metadata( + ViewRetrieveResponse.Context.Metadata.builder() + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") + .build() + ) + .build() + ) + .success(true) + .build() - assertThat(viewRetrieveResponse.context().getOrNull()) - .containsExactly(JsonValue.from(mapOf())) + assertThat(viewRetrieveResponse.contexts()) + .containsExactly( + ViewRetrieveResponse.Context.builder() + .content("Customer asked about pricing for the Scale plan.") + .metadata( + ViewRetrieveResponse.Context.Metadata.builder() + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") + .build() + ) + .build() + ) + assertThat(viewRetrieveResponse.success()).isEqualTo(true) } @Test fun roundtrip() { val jsonMapper = jsonMapper() val viewRetrieveResponse = - ViewRetrieveResponse.builder().addContext(JsonValue.from(mapOf())).build() + ViewRetrieveResponse.builder() + .addContext( + ViewRetrieveResponse.Context.builder() + .content("Customer asked about pricing for the Scale plan.") + .metadata( + ViewRetrieveResponse.Context.Metadata.builder() + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") + .build() + ) + .build() + ) + .success(true) + .build() val roundtrippedViewRetrieveResponse = jsonMapper.readValue( diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/org/context/ContextViewParamsTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/org/context/ContextViewParamsTest.kt index a03dcf9..44afbc2 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/org/context/ContextViewParamsTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/models/v1/org/context/ContextViewParamsTest.kt @@ -9,15 +9,15 @@ internal class ContextViewParamsTest { @Test fun create() { - ContextViewParams.builder().addUserId("string").build() + ContextViewParams.builder().addUserId("user_123").addUserId("user_456").build() } @Test fun body() { - val params = ContextViewParams.builder().addUserId("string").build() + val params = ContextViewParams.builder().addUserId("user_123").addUserId("user_456").build() val body = params._body() - assertThat(body.userIds()).containsExactly("string") + assertThat(body.userIds()).containsExactly("user_123", "user_456") } } diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/ErrorHandlingTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/ErrorHandlingTest.kt index 3f1caae..22a955b 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/ErrorHandlingTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/ErrorHandlingTest.kt @@ -73,18 +73,23 @@ internal class ErrorHandlingTest { contextService.add( ContextAddParams.builder() .contextType(ContextAddParams.ContextType.RESOURCE) - .addDocument(ContextAddParams.Document.builder().content("content").build()) + .addDocument( + ContextAddParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(ContextAddParams.Scope.INTERNAL) + .source("support-inbox") .metadata( ContextAddParams.Metadata.builder() - .fileName("fileName") - .fileSize(0.0) - .fileType("fileType") - .addGroupName("string") - .lastModified("lastModified") + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") .build() ) - .scope(ContextAddParams.Scope.INTERNAL) - .source("source") .build() ) } @@ -109,18 +114,23 @@ internal class ErrorHandlingTest { contextService.add( ContextAddParams.builder() .contextType(ContextAddParams.ContextType.RESOURCE) - .addDocument(ContextAddParams.Document.builder().content("content").build()) + .addDocument( + ContextAddParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(ContextAddParams.Scope.INTERNAL) + .source("support-inbox") .metadata( ContextAddParams.Metadata.builder() - .fileName("fileName") - .fileSize(0.0) - .fileType("fileType") - .addGroupName("string") - .lastModified("lastModified") + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") .build() ) - .scope(ContextAddParams.Scope.INTERNAL) - .source("source") .build() ) } @@ -145,18 +155,23 @@ internal class ErrorHandlingTest { contextService.add( ContextAddParams.builder() .contextType(ContextAddParams.ContextType.RESOURCE) - .addDocument(ContextAddParams.Document.builder().content("content").build()) + .addDocument( + ContextAddParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(ContextAddParams.Scope.INTERNAL) + .source("support-inbox") .metadata( ContextAddParams.Metadata.builder() - .fileName("fileName") - .fileSize(0.0) - .fileType("fileType") - .addGroupName("string") - .lastModified("lastModified") + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") .build() ) - .scope(ContextAddParams.Scope.INTERNAL) - .source("source") .build() ) } @@ -181,18 +196,23 @@ internal class ErrorHandlingTest { contextService.add( ContextAddParams.builder() .contextType(ContextAddParams.ContextType.RESOURCE) - .addDocument(ContextAddParams.Document.builder().content("content").build()) + .addDocument( + ContextAddParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(ContextAddParams.Scope.INTERNAL) + .source("support-inbox") .metadata( ContextAddParams.Metadata.builder() - .fileName("fileName") - .fileSize(0.0) - .fileType("fileType") - .addGroupName("string") - .lastModified("lastModified") + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") .build() ) - .scope(ContextAddParams.Scope.INTERNAL) - .source("source") .build() ) } @@ -217,18 +237,23 @@ internal class ErrorHandlingTest { contextService.add( ContextAddParams.builder() .contextType(ContextAddParams.ContextType.RESOURCE) - .addDocument(ContextAddParams.Document.builder().content("content").build()) + .addDocument( + ContextAddParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(ContextAddParams.Scope.INTERNAL) + .source("support-inbox") .metadata( ContextAddParams.Metadata.builder() - .fileName("fileName") - .fileSize(0.0) - .fileType("fileType") - .addGroupName("string") - .lastModified("lastModified") + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") .build() ) - .scope(ContextAddParams.Scope.INTERNAL) - .source("source") .build() ) } @@ -253,18 +278,23 @@ internal class ErrorHandlingTest { contextService.add( ContextAddParams.builder() .contextType(ContextAddParams.ContextType.RESOURCE) - .addDocument(ContextAddParams.Document.builder().content("content").build()) + .addDocument( + ContextAddParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(ContextAddParams.Scope.INTERNAL) + .source("support-inbox") .metadata( ContextAddParams.Metadata.builder() - .fileName("fileName") - .fileSize(0.0) - .fileType("fileType") - .addGroupName("string") - .lastModified("lastModified") + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") .build() ) - .scope(ContextAddParams.Scope.INTERNAL) - .source("source") .build() ) } @@ -289,18 +319,23 @@ internal class ErrorHandlingTest { contextService.add( ContextAddParams.builder() .contextType(ContextAddParams.ContextType.RESOURCE) - .addDocument(ContextAddParams.Document.builder().content("content").build()) + .addDocument( + ContextAddParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(ContextAddParams.Scope.INTERNAL) + .source("support-inbox") .metadata( ContextAddParams.Metadata.builder() - .fileName("fileName") - .fileSize(0.0) - .fileType("fileType") - .addGroupName("string") - .lastModified("lastModified") + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") .build() ) - .scope(ContextAddParams.Scope.INTERNAL) - .source("source") .build() ) } @@ -325,18 +360,23 @@ internal class ErrorHandlingTest { contextService.add( ContextAddParams.builder() .contextType(ContextAddParams.ContextType.RESOURCE) - .addDocument(ContextAddParams.Document.builder().content("content").build()) + .addDocument( + ContextAddParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(ContextAddParams.Scope.INTERNAL) + .source("support-inbox") .metadata( ContextAddParams.Metadata.builder() - .fileName("fileName") - .fileSize(0.0) - .fileType("fileType") - .addGroupName("string") - .lastModified("lastModified") + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") .build() ) - .scope(ContextAddParams.Scope.INTERNAL) - .source("source") .build() ) } @@ -361,18 +401,23 @@ internal class ErrorHandlingTest { contextService.add( ContextAddParams.builder() .contextType(ContextAddParams.ContextType.RESOURCE) - .addDocument(ContextAddParams.Document.builder().content("content").build()) + .addDocument( + ContextAddParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(ContextAddParams.Scope.INTERNAL) + .source("support-inbox") .metadata( ContextAddParams.Metadata.builder() - .fileName("fileName") - .fileSize(0.0) - .fileType("fileType") - .addGroupName("string") - .lastModified("lastModified") + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") .build() ) - .scope(ContextAddParams.Scope.INTERNAL) - .source("source") .build() ) } @@ -397,18 +442,23 @@ internal class ErrorHandlingTest { contextService.add( ContextAddParams.builder() .contextType(ContextAddParams.ContextType.RESOURCE) - .addDocument(ContextAddParams.Document.builder().content("content").build()) + .addDocument( + ContextAddParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(ContextAddParams.Scope.INTERNAL) + .source("support-inbox") .metadata( ContextAddParams.Metadata.builder() - .fileName("fileName") - .fileSize(0.0) - .fileType("fileType") - .addGroupName("string") - .lastModified("lastModified") + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") .build() ) - .scope(ContextAddParams.Scope.INTERNAL) - .source("source") .build() ) } @@ -433,18 +483,23 @@ internal class ErrorHandlingTest { contextService.add( ContextAddParams.builder() .contextType(ContextAddParams.ContextType.RESOURCE) - .addDocument(ContextAddParams.Document.builder().content("content").build()) + .addDocument( + ContextAddParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(ContextAddParams.Scope.INTERNAL) + .source("support-inbox") .metadata( ContextAddParams.Metadata.builder() - .fileName("fileName") - .fileSize(0.0) - .fileType("fileType") - .addGroupName("string") - .lastModified("lastModified") + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") .build() ) - .scope(ContextAddParams.Scope.INTERNAL) - .source("source") .build() ) } @@ -469,18 +524,23 @@ internal class ErrorHandlingTest { contextService.add( ContextAddParams.builder() .contextType(ContextAddParams.ContextType.RESOURCE) - .addDocument(ContextAddParams.Document.builder().content("content").build()) + .addDocument( + ContextAddParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(ContextAddParams.Scope.INTERNAL) + .source("support-inbox") .metadata( ContextAddParams.Metadata.builder() - .fileName("fileName") - .fileSize(0.0) - .fileType("fileType") - .addGroupName("string") - .lastModified("lastModified") + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") .build() ) - .scope(ContextAddParams.Scope.INTERNAL) - .source("source") .build() ) } @@ -505,18 +565,23 @@ internal class ErrorHandlingTest { contextService.add( ContextAddParams.builder() .contextType(ContextAddParams.ContextType.RESOURCE) - .addDocument(ContextAddParams.Document.builder().content("content").build()) + .addDocument( + ContextAddParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(ContextAddParams.Scope.INTERNAL) + .source("support-inbox") .metadata( ContextAddParams.Metadata.builder() - .fileName("fileName") - .fileSize(0.0) - .fileType("fileType") - .addGroupName("string") - .lastModified("lastModified") + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") .build() ) - .scope(ContextAddParams.Scope.INTERNAL) - .source("source") .build() ) } @@ -541,18 +606,23 @@ internal class ErrorHandlingTest { contextService.add( ContextAddParams.builder() .contextType(ContextAddParams.ContextType.RESOURCE) - .addDocument(ContextAddParams.Document.builder().content("content").build()) + .addDocument( + ContextAddParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(ContextAddParams.Scope.INTERNAL) + .source("support-inbox") .metadata( ContextAddParams.Metadata.builder() - .fileName("fileName") - .fileSize(0.0) - .fileType("fileType") - .addGroupName("string") - .lastModified("lastModified") + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") .build() ) - .scope(ContextAddParams.Scope.INTERNAL) - .source("source") .build() ) } @@ -577,18 +647,23 @@ internal class ErrorHandlingTest { contextService.add( ContextAddParams.builder() .contextType(ContextAddParams.ContextType.RESOURCE) - .addDocument(ContextAddParams.Document.builder().content("content").build()) + .addDocument( + ContextAddParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(ContextAddParams.Scope.INTERNAL) + .source("support-inbox") .metadata( ContextAddParams.Metadata.builder() - .fileName("fileName") - .fileSize(0.0) - .fileType("fileType") - .addGroupName("string") - .lastModified("lastModified") + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") .build() ) - .scope(ContextAddParams.Scope.INTERNAL) - .source("source") .build() ) } @@ -613,18 +688,23 @@ internal class ErrorHandlingTest { contextService.add( ContextAddParams.builder() .contextType(ContextAddParams.ContextType.RESOURCE) - .addDocument(ContextAddParams.Document.builder().content("content").build()) + .addDocument( + ContextAddParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(ContextAddParams.Scope.INTERNAL) + .source("support-inbox") .metadata( ContextAddParams.Metadata.builder() - .fileName("fileName") - .fileSize(0.0) - .fileType("fileType") - .addGroupName("string") - .lastModified("lastModified") + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") .build() ) - .scope(ContextAddParams.Scope.INTERNAL) - .source("source") .build() ) } @@ -647,18 +727,23 @@ internal class ErrorHandlingTest { contextService.add( ContextAddParams.builder() .contextType(ContextAddParams.ContextType.RESOURCE) - .addDocument(ContextAddParams.Document.builder().content("content").build()) + .addDocument( + ContextAddParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(ContextAddParams.Scope.INTERNAL) + .source("support-inbox") .metadata( ContextAddParams.Metadata.builder() - .fileName("fileName") - .fileSize(0.0) - .fileType("fileType") - .addGroupName("string") - .lastModified("lastModified") + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") .build() ) - .scope(ContextAddParams.Scope.INTERNAL) - .source("source") .build() ) } diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/ServiceParamsTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/ServiceParamsTest.kt index 498b93f..b76a1ff 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/ServiceParamsTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/ServiceParamsTest.kt @@ -45,18 +45,23 @@ internal class ServiceParamsTest { contextService.add( ContextAddParams.builder() .contextType(ContextAddParams.ContextType.RESOURCE) - .addDocument(ContextAddParams.Document.builder().content("content").build()) + .addDocument( + ContextAddParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(ContextAddParams.Scope.INTERNAL) + .source("support-inbox") .metadata( ContextAddParams.Metadata.builder() - .fileName("fileName") - .fileSize(0.0) - .fileType("fileType") - .addGroupName("string") - .lastModified("lastModified") + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") .build() ) - .scope(ContextAddParams.Scope.INTERNAL) - .source("source") .putAdditionalHeader("Secret-Header", "42") .putAdditionalQueryParam("secret_query_param", "42") .putAdditionalBodyProperty("secretProperty", JsonValue.from("42")) diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/ContextServiceAsyncTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/ContextServiceAsyncTest.kt index f747089..04fb8d7 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/ContextServiceAsyncTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/ContextServiceAsyncTest.kt @@ -28,10 +28,10 @@ internal class ContextServiceAsyncTest { val contextFuture = contextServiceAsync.delete( ContextDeleteParams.builder() + .organizationId("org_01HXYZABC") + .source("support-inbox") .byDoc(true) - .byId(true) - .organizationId("organization_id") - .source("source") + .byId(false) .userId("user_id") .build() ) @@ -54,18 +54,23 @@ internal class ContextServiceAsyncTest { contextServiceAsync.add( ContextAddParams.builder() .contextType(ContextAddParams.ContextType.RESOURCE) - .addDocument(ContextAddParams.Document.builder().content("content").build()) + .addDocument( + ContextAddParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(ContextAddParams.Scope.INTERNAL) + .source("support-inbox") .metadata( ContextAddParams.Metadata.builder() - .fileName("fileName") - .fileSize(0.0) - .fileType("fileType") - .addGroupName("string") - .lastModified("lastModified") + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") .build() ) - .scope(ContextAddParams.Scope.INTERNAL) - .source("source") .build() ) @@ -86,10 +91,12 @@ internal class ContextServiceAsyncTest { val responseFuture = contextServiceAsync.search( ContextSearchParams.builder() + .metadata(ContextSearchParams.Metadata.TRUE) + .mode(ContextSearchParams.Mode.FAST) .minimumSimilarityThreshold(0.5) - .query("search query for user preferences") + .query("What did the customer ask about pricing for the Scale plan?") .similarityThreshold(0.8) - .metadata(JsonValue.from(mapOf())) + .bodyMetadata(JsonValue.from(mapOf())) .scope(ContextSearchParams.Scope.INTERNAL) .userId("user123") .build() diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/context/AddAsyncServiceAsyncTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/context/AddAsyncServiceAsyncTest.kt new file mode 100644 index 0000000..b309e21 --- /dev/null +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/context/AddAsyncServiceAsyncTest.kt @@ -0,0 +1,68 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.services.async.v1.context + +import com.alchemystai.sdk.TestServerExtension +import com.alchemystai.sdk.client.okhttp.AlchemystAiOkHttpClientAsync +import com.alchemystai.sdk.models.v1.context.addasync.AddAsyncCreateParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class AddAsyncServiceAsyncTest { + + @Disabled("Prism tests are disabled") + @Test + fun create() { + val client = + AlchemystAiOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val addAsyncServiceAsync = client.v1().context().addAsync() + + val addAsyncFuture = + addAsyncServiceAsync.create( + AddAsyncCreateParams.builder() + .contextType(AddAsyncCreateParams.ContextType.RESOURCE) + .addDocument( + AddAsyncCreateParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(AddAsyncCreateParams.Scope.INTERNAL) + .source("support-inbox") + .metadata( + AddAsyncCreateParams.Metadata.builder() + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") + .build() + ) + .build() + ) + + val addAsync = addAsyncFuture.get() + addAsync.validate() + } + + @Disabled("Prism tests are disabled") + @Test + fun cancel() { + val client = + AlchemystAiOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val addAsyncServiceAsync = client.v1().context().addAsync() + + val responseFuture = addAsyncServiceAsync.cancel("id") + + val response = responseFuture.get() + response.validate() + } +} diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/context/MemoryServiceAsyncTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/context/MemoryServiceAsyncTest.kt index 2026cb1..bd4767b 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/context/MemoryServiceAsyncTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/context/MemoryServiceAsyncTest.kt @@ -4,6 +4,7 @@ package com.alchemystai.sdk.services.async.v1.context import com.alchemystai.sdk.TestServerExtension import com.alchemystai.sdk.client.okhttp.AlchemystAiOkHttpClientAsync +import com.alchemystai.sdk.core.JsonValue import com.alchemystai.sdk.models.v1.context.memory.MemoryAddParams import com.alchemystai.sdk.models.v1.context.memory.MemoryDeleteParams import com.alchemystai.sdk.models.v1.context.memory.MemoryUpdateParams @@ -24,15 +25,41 @@ internal class MemoryServiceAsyncTest { .build() val memoryServiceAsync = client.v1().context().memory() - val future = + val memoryFuture = memoryServiceAsync.update( MemoryUpdateParams.builder() - .addContent(MemoryUpdateParams.Content.builder().content("content").build()) - .memoryId("memoryId") + .addContent( + MemoryUpdateParams.Content.builder() + .id("msg-1") + .content("Customer asked about pricing for the Scale plan.") + .createdAt("2025-01-10T12:34:56.000Z") + .metadata( + MemoryUpdateParams.Content.Metadata.builder() + .putAdditionalProperty("messageId", JsonValue.from("bar")) + .build() + ) + .role("user") + .build() + ) + .addContent( + MemoryUpdateParams.Content.builder() + .id("msg-2") + .content("Updated answer about the Scale plan pricing after discounts.") + .createdAt("2025-01-10T12:36:00.000Z") + .metadata( + MemoryUpdateParams.Content.Metadata.builder() + .putAdditionalProperty("messageId", JsonValue.from("bar")) + .build() + ) + .role("assistant") + .build() + ) + .sessionId("support-thread-TCK-1234") .build() ) - val response = future.get() + val memory = memoryFuture.get() + memory.validate() } @Disabled("Prism tests are disabled") @@ -48,8 +75,10 @@ internal class MemoryServiceAsyncTest { val future = memoryServiceAsync.delete( MemoryDeleteParams.builder() - .memoryId("memoryId") - .organizationId("organization_id") + .memoryId("support-thread-TCK-1234") + .organizationId("org_01HXYZABC") + .byDoc(true) + .byId(false) .userId("user_id") .build() ) @@ -67,14 +96,25 @@ internal class MemoryServiceAsyncTest { .build() val memoryServiceAsync = client.v1().context().memory() - val future = + val responseFuture = memoryServiceAsync.add( MemoryAddParams.builder() - .addContent(MemoryAddParams.Content.builder().content("content").build()) - .memoryId("memoryId") + .addContent( + MemoryAddParams.Content.builder() + .content("Customer asked about pricing for the Scale plan.") + .metadata( + MemoryAddParams.Content.Metadata.builder() + .messageId("messageId") + .build() + ) + .build() + ) + .sessionId("support-thread-TCK-1234") + .metadata(MemoryAddParams.Metadata.builder().addGroupName("string").build()) .build() ) - val response = future.get() + val response = responseFuture.get() + response.validate() } } diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/context/TraceServiceAsyncTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/context/TraceServiceAsyncTest.kt index 2d2e26b..7433369 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/context/TraceServiceAsyncTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/context/TraceServiceAsyncTest.kt @@ -4,6 +4,7 @@ package com.alchemystai.sdk.services.async.v1.context import com.alchemystai.sdk.TestServerExtension import com.alchemystai.sdk.client.okhttp.AlchemystAiOkHttpClientAsync +import com.alchemystai.sdk.models.v1.context.traces.TraceListParams import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -21,7 +22,8 @@ internal class TraceServiceAsyncTest { .build() val traceServiceAsync = client.v1().context().traces() - val tracesFuture = traceServiceAsync.list() + val tracesFuture = + traceServiceAsync.list(TraceListParams.builder().limit(0L).page(0L).build()) val traces = tracesFuture.get() traces.validate() diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/context/ViewServiceAsyncTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/context/ViewServiceAsyncTest.kt index d706b29..407e4f1 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/context/ViewServiceAsyncTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/context/ViewServiceAsyncTest.kt @@ -4,6 +4,8 @@ package com.alchemystai.sdk.services.async.v1.context import com.alchemystai.sdk.TestServerExtension import com.alchemystai.sdk.client.okhttp.AlchemystAiOkHttpClientAsync +import com.alchemystai.sdk.models.v1.context.view.ViewDocsParams +import com.alchemystai.sdk.models.v1.context.view.ViewRetrieveParams import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -21,7 +23,10 @@ internal class ViewServiceAsyncTest { .build() val viewServiceAsync = client.v1().context().view() - val viewFuture = viewServiceAsync.retrieve() + val viewFuture = + viewServiceAsync.retrieve( + ViewRetrieveParams.builder().fileName("file_name").magicKey("magic_key").build() + ) val view = viewFuture.get() view.validate() @@ -37,7 +42,8 @@ internal class ViewServiceAsyncTest { .build() val viewServiceAsync = client.v1().context().view() - val responseFuture = viewServiceAsync.docs() + val responseFuture = + viewServiceAsync.docs(ViewDocsParams.builder().magicKey("magic_key").build()) val response = responseFuture.get() response.validate() diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/context/addasync/StatusServiceAsyncTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/context/addasync/StatusServiceAsyncTest.kt new file mode 100644 index 0000000..126baba --- /dev/null +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/context/addasync/StatusServiceAsyncTest.kt @@ -0,0 +1,53 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.services.async.v1.context.addasync + +import com.alchemystai.sdk.TestServerExtension +import com.alchemystai.sdk.client.okhttp.AlchemystAiOkHttpClientAsync +import com.alchemystai.sdk.models.v1.context.addasync.status.StatusListParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class StatusServiceAsyncTest { + + @Disabled("Prism tests are disabled") + @Test + fun retrieve() { + val client = + AlchemystAiOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val statusServiceAsync = client.v1().context().addAsync().status() + + val statusFuture = statusServiceAsync.retrieve("id") + + val status = statusFuture.get() + status.validate() + } + + @Disabled("Prism tests are disabled") + @Test + fun list() { + val client = + AlchemystAiOkHttpClientAsync.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val statusServiceAsync = client.v1().context().addAsync().status() + + val statusesFuture = + statusServiceAsync.list( + StatusListParams.builder() + .limit("limit") + .offset("offset") + .type(StatusListParams.Type.ALL) + .build() + ) + + val statuses = statusesFuture.get() + statuses.validate() + } +} diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/org/ContextServiceAsyncTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/org/ContextServiceAsyncTest.kt index 0c81f56..21ecd76 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/org/ContextServiceAsyncTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/async/v1/org/ContextServiceAsyncTest.kt @@ -23,7 +23,9 @@ internal class ContextServiceAsyncTest { val contextServiceAsync = client.v1().org().context() val responseFuture = - contextServiceAsync.view(ContextViewParams.builder().addUserId("string").build()) + contextServiceAsync.view( + ContextViewParams.builder().addUserId("user_123").addUserId("user_456").build() + ) val response = responseFuture.get() response.validate() diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/ContextServiceTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/ContextServiceTest.kt index 81c6fb5..83aa599 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/ContextServiceTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/ContextServiceTest.kt @@ -28,10 +28,10 @@ internal class ContextServiceTest { val context = contextService.delete( ContextDeleteParams.builder() + .organizationId("org_01HXYZABC") + .source("support-inbox") .byDoc(true) - .byId(true) - .organizationId("organization_id") - .source("source") + .byId(false) .userId("user_id") .build() ) @@ -53,18 +53,23 @@ internal class ContextServiceTest { contextService.add( ContextAddParams.builder() .contextType(ContextAddParams.ContextType.RESOURCE) - .addDocument(ContextAddParams.Document.builder().content("content").build()) + .addDocument( + ContextAddParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(ContextAddParams.Scope.INTERNAL) + .source("support-inbox") .metadata( ContextAddParams.Metadata.builder() - .fileName("fileName") - .fileSize(0.0) - .fileType("fileType") - .addGroupName("string") - .lastModified("lastModified") + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") .build() ) - .scope(ContextAddParams.Scope.INTERNAL) - .source("source") .build() ) @@ -84,10 +89,12 @@ internal class ContextServiceTest { val response = contextService.search( ContextSearchParams.builder() + .metadata(ContextSearchParams.Metadata.TRUE) + .mode(ContextSearchParams.Mode.FAST) .minimumSimilarityThreshold(0.5) - .query("search query for user preferences") + .query("What did the customer ask about pricing for the Scale plan?") .similarityThreshold(0.8) - .metadata(JsonValue.from(mapOf())) + .bodyMetadata(JsonValue.from(mapOf())) .scope(ContextSearchParams.Scope.INTERNAL) .userId("user123") .build() diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/context/AddAsyncServiceTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/context/AddAsyncServiceTest.kt new file mode 100644 index 0000000..953364e --- /dev/null +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/context/AddAsyncServiceTest.kt @@ -0,0 +1,66 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.services.blocking.v1.context + +import com.alchemystai.sdk.TestServerExtension +import com.alchemystai.sdk.client.okhttp.AlchemystAiOkHttpClient +import com.alchemystai.sdk.models.v1.context.addasync.AddAsyncCreateParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class AddAsyncServiceTest { + + @Disabled("Prism tests are disabled") + @Test + fun create() { + val client = + AlchemystAiOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val addAsyncService = client.v1().context().addAsync() + + val addAsync = + addAsyncService.create( + AddAsyncCreateParams.builder() + .contextType(AddAsyncCreateParams.ContextType.RESOURCE) + .addDocument( + AddAsyncCreateParams.Document.builder() + .content("Customer asked about pricing for the Scale plan.") + .build() + ) + .scope(AddAsyncCreateParams.Scope.INTERNAL) + .source("support-inbox") + .metadata( + AddAsyncCreateParams.Metadata.builder() + .fileName("support_thread_TCK-1234.txt") + .fileSize(2048.0) + .fileType("text/plain") + .addGroupName("support") + .addGroupName("pricing") + .lastModified("2025-01-10T12:34:56.000Z") + .build() + ) + .build() + ) + + addAsync.validate() + } + + @Disabled("Prism tests are disabled") + @Test + fun cancel() { + val client = + AlchemystAiOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val addAsyncService = client.v1().context().addAsync() + + val response = addAsyncService.cancel("id") + + response.validate() + } +} diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/context/MemoryServiceTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/context/MemoryServiceTest.kt index 8f83cd4..92693cc 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/context/MemoryServiceTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/context/MemoryServiceTest.kt @@ -4,6 +4,7 @@ package com.alchemystai.sdk.services.blocking.v1.context import com.alchemystai.sdk.TestServerExtension import com.alchemystai.sdk.client.okhttp.AlchemystAiOkHttpClient +import com.alchemystai.sdk.core.JsonValue import com.alchemystai.sdk.models.v1.context.memory.MemoryAddParams import com.alchemystai.sdk.models.v1.context.memory.MemoryDeleteParams import com.alchemystai.sdk.models.v1.context.memory.MemoryUpdateParams @@ -24,12 +25,40 @@ internal class MemoryServiceTest { .build() val memoryService = client.v1().context().memory() - memoryService.update( - MemoryUpdateParams.builder() - .addContent(MemoryUpdateParams.Content.builder().content("content").build()) - .memoryId("memoryId") - .build() - ) + val memory = + memoryService.update( + MemoryUpdateParams.builder() + .addContent( + MemoryUpdateParams.Content.builder() + .id("msg-1") + .content("Customer asked about pricing for the Scale plan.") + .createdAt("2025-01-10T12:34:56.000Z") + .metadata( + MemoryUpdateParams.Content.Metadata.builder() + .putAdditionalProperty("messageId", JsonValue.from("bar")) + .build() + ) + .role("user") + .build() + ) + .addContent( + MemoryUpdateParams.Content.builder() + .id("msg-2") + .content("Updated answer about the Scale plan pricing after discounts.") + .createdAt("2025-01-10T12:36:00.000Z") + .metadata( + MemoryUpdateParams.Content.Metadata.builder() + .putAdditionalProperty("messageId", JsonValue.from("bar")) + .build() + ) + .role("assistant") + .build() + ) + .sessionId("support-thread-TCK-1234") + .build() + ) + + memory.validate() } @Disabled("Prism tests are disabled") @@ -44,8 +73,10 @@ internal class MemoryServiceTest { memoryService.delete( MemoryDeleteParams.builder() - .memoryId("memoryId") - .organizationId("organization_id") + .memoryId("support-thread-TCK-1234") + .organizationId("org_01HXYZABC") + .byDoc(true) + .byId(false) .userId("user_id") .build() ) @@ -61,11 +92,24 @@ internal class MemoryServiceTest { .build() val memoryService = client.v1().context().memory() - memoryService.add( - MemoryAddParams.builder() - .addContent(MemoryAddParams.Content.builder().content("content").build()) - .memoryId("memoryId") - .build() - ) + val response = + memoryService.add( + MemoryAddParams.builder() + .addContent( + MemoryAddParams.Content.builder() + .content("Customer asked about pricing for the Scale plan.") + .metadata( + MemoryAddParams.Content.Metadata.builder() + .messageId("messageId") + .build() + ) + .build() + ) + .sessionId("support-thread-TCK-1234") + .metadata(MemoryAddParams.Metadata.builder().addGroupName("string").build()) + .build() + ) + + response.validate() } } diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/context/TraceServiceTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/context/TraceServiceTest.kt index 696f586..b7bde44 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/context/TraceServiceTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/context/TraceServiceTest.kt @@ -4,6 +4,7 @@ package com.alchemystai.sdk.services.blocking.v1.context import com.alchemystai.sdk.TestServerExtension import com.alchemystai.sdk.client.okhttp.AlchemystAiOkHttpClient +import com.alchemystai.sdk.models.v1.context.traces.TraceListParams import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -21,7 +22,7 @@ internal class TraceServiceTest { .build() val traceService = client.v1().context().traces() - val traces = traceService.list() + val traces = traceService.list(TraceListParams.builder().limit(0L).page(0L).build()) traces.validate() } diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/context/ViewServiceTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/context/ViewServiceTest.kt index a63c672..487d0eb 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/context/ViewServiceTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/context/ViewServiceTest.kt @@ -4,6 +4,8 @@ package com.alchemystai.sdk.services.blocking.v1.context import com.alchemystai.sdk.TestServerExtension import com.alchemystai.sdk.client.okhttp.AlchemystAiOkHttpClient +import com.alchemystai.sdk.models.v1.context.view.ViewDocsParams +import com.alchemystai.sdk.models.v1.context.view.ViewRetrieveParams import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -21,7 +23,10 @@ internal class ViewServiceTest { .build() val viewService = client.v1().context().view() - val view = viewService.retrieve() + val view = + viewService.retrieve( + ViewRetrieveParams.builder().fileName("file_name").magicKey("magic_key").build() + ) view.validate() } @@ -36,7 +41,7 @@ internal class ViewServiceTest { .build() val viewService = client.v1().context().view() - val response = viewService.docs() + val response = viewService.docs(ViewDocsParams.builder().magicKey("magic_key").build()) response.validate() } diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/context/addasync/StatusServiceTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/context/addasync/StatusServiceTest.kt new file mode 100644 index 0000000..18c741e --- /dev/null +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/context/addasync/StatusServiceTest.kt @@ -0,0 +1,51 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.alchemystai.sdk.services.blocking.v1.context.addasync + +import com.alchemystai.sdk.TestServerExtension +import com.alchemystai.sdk.client.okhttp.AlchemystAiOkHttpClient +import com.alchemystai.sdk.models.v1.context.addasync.status.StatusListParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(TestServerExtension::class) +internal class StatusServiceTest { + + @Disabled("Prism tests are disabled") + @Test + fun retrieve() { + val client = + AlchemystAiOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val statusService = client.v1().context().addAsync().status() + + val status = statusService.retrieve("id") + + status.validate() + } + + @Disabled("Prism tests are disabled") + @Test + fun list() { + val client = + AlchemystAiOkHttpClient.builder() + .baseUrl(TestServerExtension.BASE_URL) + .apiKey("My API Key") + .build() + val statusService = client.v1().context().addAsync().status() + + val statuses = + statusService.list( + StatusListParams.builder() + .limit("limit") + .offset("offset") + .type(StatusListParams.Type.ALL) + .build() + ) + + statuses.validate() + } +} diff --git a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/org/ContextServiceTest.kt b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/org/ContextServiceTest.kt index 21eb120..929663d 100644 --- a/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/org/ContextServiceTest.kt +++ b/alchemyst-ai-java-core/src/test/kotlin/com/alchemystai/sdk/services/blocking/v1/org/ContextServiceTest.kt @@ -22,7 +22,10 @@ internal class ContextServiceTest { .build() val contextService = client.v1().org().context() - val response = contextService.view(ContextViewParams.builder().addUserId("string").build()) + val response = + contextService.view( + ContextViewParams.builder().addUserId("user_123").addUserId("user_456").build() + ) response.validate() } diff --git a/alchemyst-ai-java-proguard-test/build.gradle.kts b/alchemyst-ai-java-proguard-test/build.gradle.kts index 15529bf..e397d9a 100644 --- a/alchemyst-ai-java-proguard-test/build.gradle.kts +++ b/alchemyst-ai-java-proguard-test/build.gradle.kts @@ -19,7 +19,7 @@ dependencies { testImplementation(kotlin("test")) testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3") testImplementation("org.assertj:assertj-core:3.25.3") - testImplementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.13.4") + testImplementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.14.0") } tasks.shadowJar { diff --git a/alchemyst-ai-java-proguard-test/src/test/kotlin/com/alchemystai/sdk/proguard/ProGuardCompatibilityTest.kt b/alchemyst-ai-java-proguard-test/src/test/kotlin/com/alchemystai/sdk/proguard/ProGuardCompatibilityTest.kt index 72c8d7a..0d077a1 100644 --- a/alchemyst-ai-java-proguard-test/src/test/kotlin/com/alchemystai/sdk/proguard/ProGuardCompatibilityTest.kt +++ b/alchemyst-ai-java-proguard-test/src/test/kotlin/com/alchemystai/sdk/proguard/ProGuardCompatibilityTest.kt @@ -3,11 +3,9 @@ package com.alchemystai.sdk.proguard import com.alchemystai.sdk.client.okhttp.AlchemystAiOkHttpClient -import com.alchemystai.sdk.core.JsonValue import com.alchemystai.sdk.core.jsonMapper -import com.alchemystai.sdk.models.v1.context.ContextSearchResponse +import com.alchemystai.sdk.models.v1.context.ContextAddResponse import com.fasterxml.jackson.module.kotlin.jacksonTypeRef -import java.time.OffsetDateTime import kotlin.reflect.full.memberFunctions import kotlin.reflect.jvm.javaMethod import org.assertj.core.api.Assertions.assertThat @@ -55,27 +53,21 @@ internal class ProGuardCompatibilityTest { } @Test - fun contextSearchResponseRoundtrip() { + fun contextAddResponseRoundtrip() { val jsonMapper = jsonMapper() - val contextSearchResponse = - ContextSearchResponse.builder() - .addContext( - ContextSearchResponse.Context.builder() - .content("content") - .createdAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) - .metadata(JsonValue.from(mapOf())) - .score(0.001) - .updatedAt(OffsetDateTime.parse("2019-12-27T18:11:19.117Z")) - .build() - ) + val contextAddResponse = + ContextAddResponse.builder() + .contextId("ctx_01HXYZABC") + .success(true) + .processedDocuments(2.0) .build() - val roundtrippedContextSearchResponse = + val roundtrippedContextAddResponse = jsonMapper.readValue( - jsonMapper.writeValueAsString(contextSearchResponse), - jacksonTypeRef(), + jsonMapper.writeValueAsString(contextAddResponse), + jacksonTypeRef(), ) - assertThat(roundtrippedContextSearchResponse).isEqualTo(contextSearchResponse) + assertThat(roundtrippedContextAddResponse).isEqualTo(contextAddResponse) } } diff --git a/bin/check-release-environment b/bin/check-release-environment new file mode 100644 index 0000000..3a6a7b4 --- /dev/null +++ b/bin/check-release-environment @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +errors=() + +if [ -z "${SONATYPE_USERNAME}" ]; then + errors+=("The SONATYPE_USERNAME secret has not been set. Please set it in either this repository's secrets or your organization secrets") +fi + +if [ -z "${SONATYPE_PASSWORD}" ]; then + errors+=("The SONATYPE_PASSWORD secret has not been set. Please set it in either this repository's secrets or your organization secrets") +fi + +if [ -z "${GPG_SIGNING_KEY}" ]; then + errors+=("The GPG_SIGNING_KEY secret has not been set. Please set it in either this repository's secrets or your organization secrets") +fi + +if [ -z "${GPG_SIGNING_PASSWORD}" ]; then + errors+=("The GPG_SIGNING_PASSWORD secret has not been set. Please set it in either this repository's secrets or your organization secrets") +fi + +lenErrors=${#errors[@]} + +if [[ lenErrors -gt 0 ]]; then + echo -e "Found the following errors in the release environment:\n" + + for error in "${errors[@]}"; do + echo -e "- $error\n" + done + + exit 1 +fi + +echo "The environment is ready to push releases!" diff --git a/build.gradle.kts b/build.gradle.kts index 6962ab8..eac4c16 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ repositories { allprojects { group = "com.alchemystai.sdk" - version = "0.0.1" + version = "0.1.0" // x-release-please-version } subprojects { diff --git a/buildSrc/src/main/kotlin/alchemyst-ai.kotlin.gradle.kts b/buildSrc/src/main/kotlin/alchemyst-ai.kotlin.gradle.kts index abc3dfa..260dc61 100644 --- a/buildSrc/src/main/kotlin/alchemyst-ai.kotlin.gradle.kts +++ b/buildSrc/src/main/kotlin/alchemyst-ai.kotlin.gradle.kts @@ -33,6 +33,9 @@ kotlin { tasks.withType().configureEach { systemProperty("junit.jupiter.execution.parallel.enabled", true) systemProperty("junit.jupiter.execution.parallel.mode.default", "concurrent") + + // `SKIP_MOCK_TESTS` affects which tests run so it must be added as input for proper cache invalidation. + inputs.property("skipMockTests", System.getenv("SKIP_MOCK_TESTS")).optional(true) } val ktfmt by configurations.creating diff --git a/buildSrc/src/main/kotlin/alchemyst-ai.publish.gradle.kts b/buildSrc/src/main/kotlin/alchemyst-ai.publish.gradle.kts index 1821b17..b70967c 100644 --- a/buildSrc/src/main/kotlin/alchemyst-ai.publish.gradle.kts +++ b/buildSrc/src/main/kotlin/alchemyst-ai.publish.gradle.kts @@ -11,7 +11,7 @@ configure { pom { name.set("Alchemyst AI API v1 documentation") description.set("v1 API documentation for Alchemyst AI") - url.set("https://docs.getalchemystai.com") + url.set("https://getalchemystai.com/docs") licenses { license { @@ -27,9 +27,9 @@ configure { } scm { - connection.set("scm:git:git://github.com/stainless-sdks/alchemyst-ai-sdk-java.git") - developerConnection.set("scm:git:git://github.com/stainless-sdks/alchemyst-ai-sdk-java.git") - url.set("https://github.com/stainless-sdks/alchemyst-ai-sdk-java") + connection.set("scm:git:git://github.com/Alchemyst-ai/alchemyst-sdk-java.git") + developerConnection.set("scm:git:git://github.com/Alchemyst-ai/alchemyst-sdk-java.git") + url.set("https://github.com/Alchemyst-ai/alchemyst-sdk-java") } versionMapping { @@ -40,6 +40,14 @@ configure { } } } + repositories { + if (project.hasProperty("publishLocal")) { + maven { + name = "LocalFileSystem" + url = uri("${rootProject.layout.buildDirectory.get()}/local-maven-repo") + } + } + } } signing { diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..8f98719 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,67 @@ +{ + "packages": { + ".": {} + }, + "$schema": "https://raw.githubusercontent.com/stainless-api/release-please/main/schemas/config.json", + "include-v-in-tag": true, + "include-component-in-tag": false, + "versioning": "prerelease", + "prerelease": true, + "bump-minor-pre-major": true, + "bump-patch-for-minor-pre-major": false, + "pull-request-header": "Automated Release PR", + "pull-request-title-pattern": "release: ${version}", + "changelog-sections": [ + { + "type": "feat", + "section": "Features" + }, + { + "type": "fix", + "section": "Bug Fixes" + }, + { + "type": "perf", + "section": "Performance Improvements" + }, + { + "type": "revert", + "section": "Reverts" + }, + { + "type": "chore", + "section": "Chores" + }, + { + "type": "docs", + "section": "Documentation" + }, + { + "type": "style", + "section": "Styles" + }, + { + "type": "refactor", + "section": "Refactors" + }, + { + "type": "test", + "section": "Tests", + "hidden": true + }, + { + "type": "build", + "section": "Build System" + }, + { + "type": "ci", + "section": "Continuous Integration", + "hidden": true + } + ], + "release-type": "simple", + "extra-files": [ + "README.md", + "build.gradle.kts" + ] +} \ No newline at end of file diff --git a/scripts/upload-artifacts b/scripts/upload-artifacts new file mode 100755 index 0000000..10f3c70 --- /dev/null +++ b/scripts/upload-artifacts @@ -0,0 +1,193 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# ANSI Color Codes +GREEN='\033[32m' +RED='\033[31m' +NC='\033[0m' # No Color + +MAVEN_REPO_PATH="./build/local-maven-repo" + +log_error() { + local msg="$1" + local headers="$2" + local body="$3" + echo -e "${RED}${msg}${NC}" + [[ -f "$headers" ]] && echo -e "${RED}Headers:$(cat "$headers")${NC}" + echo -e "${RED}Body: ${body}${NC}" + exit 1 +} + +upload_file() { + local file_name="$1" + local tmp_headers + tmp_headers=$(mktemp) + + if [ -f "$file_name" ]; then + echo -e "${GREEN}Processing file: $file_name${NC}" + pkg_file_name="mvn${file_name#"${MAVEN_REPO_PATH}"}" + + # Get signed URL for uploading artifact file + signed_url_response=$(curl -X POST -G "$URL" \ + -sS --retry 5 \ + -D "$tmp_headers" \ + --data-urlencode "filename=$pkg_file_name" \ + -H "Authorization: Bearer $AUTH" \ + -H "Content-Type: application/json") + + # Validate JSON and extract URL + if ! signed_url=$(echo "$signed_url_response" | jq -e -r '.url' 2>/dev/null) || [[ "$signed_url" == "null" ]]; then + log_error "Failed to get valid signed URL" "$tmp_headers" "$signed_url_response" + fi + + # Set content-type based on file extension + local extension="${file_name##*.}" + local content_type + case "$extension" in + jar) content_type="application/java-archive" ;; + md5|sha1|sha256|sha512) content_type="text/plain" ;; + module) content_type="application/json" ;; + pom|xml) content_type="application/xml" ;; + html) content_type="text/html" ;; + *) content_type="application/octet-stream" ;; + esac + + # Upload file + upload_response=$(curl -v -X PUT \ + --retry 5 \ + --retry-all-errors \ + -D "$tmp_headers" \ + -H "Content-Type: $content_type" \ + --data-binary "@${file_name}" "$signed_url" 2>&1) + + if ! echo "$upload_response" | grep -q "HTTP/[0-9.]* 200"; then + log_error "Failed to upload artifact file" "$tmp_headers" "$upload_response" + fi + + # Insert small throttle to reduce rate limiting risk + sleep 0.1 + fi +} + +walk_tree() { + local current_dir="$1" + + for entry in "$current_dir"/*; do + # Check that entry is valid + [ -e "$entry" ] || [ -h "$entry" ] || continue + + if [ -d "$entry" ]; then + walk_tree "$entry" + else + upload_file "$entry" + fi + done +} + +generate_instructions() { + cat << EOF > "$MAVEN_REPO_PATH/index.html" + + + + Maven Repo + + +

Stainless SDK Maven Repository

+

This is the Maven repository for your Stainless Java SDK build.

+ +

Project configuration

+ +

The details depend on whether you're using Maven or Gradle as your build tool.

+ +

Maven

+ +

Add the following to your project's pom.xml:

+
<repositories>
+    <repository>
+        <id>stainless-sdk-repo</id>
+        <url>https://pkg.stainless.com/s/${PROJECT}/${SHA}/mvn</url>
+    </repository>
+</repositories>
+ +

Gradle

+

Add the following to your build.gradle file:

+
repositories {
+    maven {
+        url "https://pkg.stainless.com/s/${PROJECT}/${SHA}/mvn"
+    }
+}
+ +
+

Configuring authentication (if required)

+ +

Some accounts may require authentication to access the repository. If so, use the + following instructions, replacing YOUR_STAINLESS_API_TOKEN with your actual token.

+ +

Maven with authentication

+ +

First, ensure you have the following in your Maven settings.xml for repo authentication:

+
<servers>
+    <server>
+        <id>stainless-sdk-repo</id>
+        <configuration>
+            <httpHeaders>
+                <property>
+                    <name>Authorization</name>
+                    <value>Bearer YOUR_STAINLESS_API_TOKEN</value>
+                </property>
+            </httpHeaders>
+        </configuration>
+    </server>
+</servers>
+ +

Then, add the following to your project's pom.xml:

+
<repositories>
+    <repository>
+        <id>stainless-sdk-repo</id>
+        <url>https://pkg.stainless.com/s/${PROJECT}/${SHA}/mvn</url>
+    </repository>
+</repositories>
+ +

Gradle with authentication

+

Add the following to your build.gradle file:

+
repositories {
+    maven {
+        url "https://pkg.stainless.com/s/${PROJECT}/${SHA}/mvn"
+        credentials(HttpHeaderCredentials) {
+            name = "Authorization"
+            value = "Bearer YOUR_STAINLESS_API_TOKEN"
+        }
+        authentication {
+            header(HttpHeaderAuthentication)
+        }
+    }
+}
+
+ +

Using the repository

+

Once you've configured the repository, you can include dependencies from it as usual. See your + project README + for more details.

+ + +EOF + upload_file "${MAVEN_REPO_PATH}/index.html" + + echo "Configure maven or gradle to use the repo located at 'https://pkg.stainless.com/s/${PROJECT}/${SHA}/mvn'" + echo "For more details, see the directions in https://pkg.stainless.com/s/${PROJECT}/${SHA}/mvn/index.html" +} + +cd "$(dirname "$0")/.." + +echo "::group::Creating local Maven content" +./gradlew publishMavenPublicationToLocalFileSystemRepository -PpublishLocal +echo "::endgroup::" + +echo "::group::Uploading to pkg.stainless.com" +walk_tree "$MAVEN_REPO_PATH" +echo "::endgroup::" + +echo "::group::Generating instructions" +generate_instructions +echo "::endgroup::"