diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 9051fdd2..42805473 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -1,18 +1,24 @@
name: CI
on:
push:
- branches:
- - main
+ branches-ignore:
+ - 'generated'
+ - 'codegen/**'
+ - 'integrated/**'
+ - 'stl-preview-head/**'
+ - 'stl-preview-base/**'
pull_request:
- branches:
- - main
- - next
+ branches-ignore:
+ - 'stl-preview-head/**'
+ - 'stl-preview-base/**'
jobs:
lint:
- timeout-minutes: 10
+ timeout-minutes: 15
name: lint
- runs-on: ubuntu-latest
+ runs-on: ${{ github.repository == 'stainless-sdks/braintrust-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
@@ -22,7 +28,7 @@ jobs:
distribution: temurin
java-version: |
8
- 17
+ 21
cache: gradle
- name: Set up Gradle
@@ -30,10 +36,36 @@ jobs:
- name: Run lints
run: ./scripts/lint
+
+ build:
+ timeout-minutes: 15
+ name: build
+ runs-on: ${{ github.repository == 'stainless-sdks/braintrust-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
+
+ - name: Set up Java
+ uses: actions/setup-java@v4
+ with:
+ distribution: temurin
+ java-version: |
+ 8
+ 21
+ cache: gradle
+
+ - name: Set up Gradle
+ uses: gradle/actions/setup-gradle@v4
+
+ - name: Build SDK
+ run: ./scripts/build
+
test:
- timeout-minutes: 10
+ timeout-minutes: 15
name: test
- runs-on: ubuntu-latest
+ runs-on: ${{ github.repository == 'stainless-sdks/braintrust-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
@@ -43,7 +75,7 @@ jobs:
distribution: temurin
java-version: |
8
- 17
+ 21
cache: gradle
- name: Set up Gradle
diff --git a/.github/workflows/publish-sonatype.yml b/.github/workflows/publish-sonatype.yml
index bab4aea6..bb52d80e 100755
--- a/.github/workflows/publish-sonatype.yml
+++ b/.github/workflows/publish-sonatype.yml
@@ -17,7 +17,7 @@ jobs:
- uses: actions/checkout@v4
- name: Set up Java
- uses: actions/setup-java@v3
+ uses: actions/setup-java@v4
with:
distribution: temurin
java-version: |
diff --git a/.gitignore b/.gitignore
index 4e81838d..b1346e6d 100755
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,6 @@
.gradle
.idea
.kotlin
-build
+build/
codegen.log
kls_database.db
diff --git a/.release-please-manifest.json b/.release-please-manifest.json
index 6d78745c..091cfb12 100755
--- a/.release-please-manifest.json
+++ b/.release-please-manifest.json
@@ -1,3 +1,3 @@
{
- ".": "0.9.0"
+ ".": "0.10.0"
}
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9d47d1d9..f97d464c 100755
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,89 @@
# Changelog
+## 0.10.0 (2025-08-22)
+
+Full Changelog: [v0.9.0...v0.10.0](https://github.com/braintrustdata/braintrust-java/compare/v0.9.0...v0.10.0)
+
+### ⚠ BREAKING CHANGES
+
+* **client:** extract auto pagination to shared classes
+* **client:** **Migration:** - If you were referencing the `AutoPager` class on a specific `*Page` or `*PageAsync` type, then you should instead reference the shared `AutoPager` and `AutoPagerAsync` types, under the `core` package
+ - `AutoPagerAsync` now has different usage. You can call `.subscribe(...)` on the returned object instead to get called back each page item. You can also call `onCompleteFuture()` to get a future that completes when all items have been processed. Finally, you can call `.close()` on the returned object to stop auto-paginating early
+ - If you were referencing `getNextPage` or `getNextPageParams`:
+ - Swap to `nextPage()` and `nextPageParams()`
+ - Note that these both now return non-optional types (use `hasNextPage()` before calling these, since they will throw if it's impossible to get another page)
+
+### Features
+
+* add retryable exception ([d8e7b05](https://github.com/braintrustdata/braintrust-java/commit/d8e7b05c0d314fe4ec457f92c60df6580af5c2e6))
+* **client:** add `{QueryParams,Headers}#put(String, JsonValue)` methods ([2ed0bd5](https://github.com/braintrustdata/braintrust-java/commit/2ed0bd5ddc28eddf3d9f034544683d0b1eaf41a5))
+* **client:** add a `withOptions` method ([0fd4355](https://github.com/braintrustdata/braintrust-java/commit/0fd435598218e1d60f93cdc056a007b7c42a77ed))
+* **client:** add https config options ([6730e8b](https://github.com/braintrustdata/braintrust-java/commit/6730e8b831a69ca8932e33749b3c4f91b90c17da))
+* **client:** allow configuring env via system properties ([66d1af9](https://github.com/braintrustdata/braintrust-java/commit/66d1af9d64fc2ec585dc56b0e5cc2020ca9fe0f0))
+* **client:** allow providing some params positionally ([decbdbc](https://github.com/braintrustdata/braintrust-java/commit/decbdbcb64f695324a84e992c1c5abec39d01061))
+* **client:** ensure compat with proguard ([976cf03](https://github.com/braintrustdata/braintrust-java/commit/976cf03afcba30e713b8a3412a146df71662896f))
+* **client:** extract auto pagination to shared classes ([e9248c0](https://github.com/braintrustdata/braintrust-java/commit/e9248c0543f113372cafa9518da4afa861154ec8))
+* **client:** implement per-endpoint base URL support ([729a979](https://github.com/braintrustdata/braintrust-java/commit/729a9797b5eb5f0031ff4f9ecc5d23e750bb58a3))
+
+
+### Bug Fixes
+
+* **ci:** release-doctor — report correct token name ([76e5e15](https://github.com/braintrustdata/braintrust-java/commit/76e5e15496845894737ef7cce7a4b5f45b4c9627))
+* **client:** accidental mutability of some classes ([95b2515](https://github.com/braintrustdata/braintrust-java/commit/95b25154cb5f8305654068b5f933f483e2356e07))
+* **client:** bump max requests per host to max requests (5 -> 64) ([ce8a40c](https://github.com/braintrustdata/braintrust-java/commit/ce8a40c62024ba63ed82b36c6f5c5f40cbc45486))
+* **client:** don't close client on `withOptions` usage when original is gc'd ([c17580b](https://github.com/braintrustdata/braintrust-java/commit/c17580bd1187eee832f3d01a0632e8a343eee909))
+* **client:** ensure error handling always occurs ([53fa1ca](https://github.com/braintrustdata/braintrust-java/commit/53fa1ca6ab6c5328dd4e96e0f208a550f0eabd91))
+* **client:** r8 support ([f06bc35](https://github.com/braintrustdata/braintrust-java/commit/f06bc35d0f3cba5ddaadfcb8d67ec27443ec03a9))
+* **client:** remove `@MustBeClosed` for future returning methods ([5d19342](https://github.com/braintrustdata/braintrust-java/commit/5d19342d1f83132910b16047a39629b08576a201))
+
+
+### Performance Improvements
+
+* **internal:** make formatting faster ([80067f7](https://github.com/braintrustdata/braintrust-java/commit/80067f7e4f450cdc259a457a97f9691fcab7f11d))
+
+
+### Chores
+
+* **ci:** add build job ([3e6fe1e](https://github.com/braintrustdata/braintrust-java/commit/3e6fe1ebc28c61201c870f4e7068d3e1972ba80c))
+* **ci:** bump `actions/setup-java` to v4 ([3769b89](https://github.com/braintrustdata/braintrust-java/commit/3769b89c224b437df98fdbb28f0cbd8d097022d6))
+* **ci:** enable for pull requests ([3e67a54](https://github.com/braintrustdata/braintrust-java/commit/3e67a5462e640fea77f782aff31047f3ccea099f))
+* **ci:** ensure docs generation always succeeds ([266ed1d](https://github.com/braintrustdata/braintrust-java/commit/266ed1d813a06fc1b73201923da77d6bc2850eda))
+* **ci:** only run for pushes and fork pull requests ([7437b68](https://github.com/braintrustdata/braintrust-java/commit/7437b686f0b58d761465567d88e242ffad67012b))
+* **ci:** only use depot for staging repos ([fc25618](https://github.com/braintrustdata/braintrust-java/commit/fc25618f693dd09f1de17b6c53a479fac1863b03))
+* **ci:** reduce log noise ([0b93a6a](https://github.com/braintrustdata/braintrust-java/commit/0b93a6ac62936f46da8a9ce743ef8971a3a45a79))
+* **client:** refactor closing / shutdown ([09819df](https://github.com/braintrustdata/braintrust-java/commit/09819df78d9560f2dd6024c90df88e7754be8191))
+* **docs:** grammar improvements ([f8dd702](https://github.com/braintrustdata/braintrust-java/commit/f8dd702521b2400d82bacafeba88cc85cb7e94f2))
+* **example:** fix run example comment ([ab5aa6c](https://github.com/braintrustdata/braintrust-java/commit/ab5aa6c6afdfea06c9d14ebc27cd7ec79a69081a))
+* increase max gradle JVM heap to 8GB ([00333f4](https://github.com/braintrustdata/braintrust-java/commit/00333f406e3d855e519d9c52110589bc8d02e1ae))
+* **internal:** add async lock helper ([5904a7a](https://github.com/braintrustdata/braintrust-java/commit/5904a7af5e0942a5025ee76b9c9f4264c594da56))
+* **internal:** allow running specific example from cli ([1f6ea51](https://github.com/braintrustdata/braintrust-java/commit/1f6ea51f9017c4790c3bc88633f994840a917023))
+* **internal:** bump ci test timeout ([3d46fc5](https://github.com/braintrustdata/braintrust-java/commit/3d46fc54a39e825f75e16fd4698b14feb9259b35))
+* **internal:** codegen related update ([23e9c7b](https://github.com/braintrustdata/braintrust-java/commit/23e9c7be91a92814d984eb8ee14f8b640c65fbe3))
+* **internal:** codegen related update ([ee51402](https://github.com/braintrustdata/braintrust-java/commit/ee51402c535e190bc5800086e02f7c184f1d7d9b))
+* **internal:** dynamically determine included projects ([8129561](https://github.com/braintrustdata/braintrust-java/commit/8129561686f8808b8871009844056fafd99502e9))
+* **internal:** java 17 -> 21 on ci ([fc13394](https://github.com/braintrustdata/braintrust-java/commit/fc13394a9cf52b353036f153e2cf5a0f53343750))
+* **internal:** reduce proguard ci logging ([2c716b1](https://github.com/braintrustdata/braintrust-java/commit/2c716b1510cbebf94570204533b8e1aaef11db80))
+* **internal:** refactor delegating from client to options ([70faee4](https://github.com/braintrustdata/braintrust-java/commit/70faee4a69f3a382336d30ef7d52737a2d6ab560))
+* **internal:** remove flaky `-Xbackend-threads=0` option ([96fdae2](https://github.com/braintrustdata/braintrust-java/commit/96fdae2700801166f887a8195e36029ee15d4aa3))
+* **internal:** remove unnecessary `[...]` in `[@see](https://github.com/see)` ([a0ef543](https://github.com/braintrustdata/braintrust-java/commit/a0ef543b879834083db1b17103a03962b1734edf))
+* **internal:** support passing arguments to test script ([87f7a5f](https://github.com/braintrustdata/braintrust-java/commit/87f7a5f68f1b67008daccc7dc93238af71f1ab3e))
+* **internal:** support running formatters directly ([6a03471](https://github.com/braintrustdata/braintrust-java/commit/6a034710297d455d4601a5a2845c149592bc7da3))
+* **internal:** update comment in script ([b73560b](https://github.com/braintrustdata/braintrust-java/commit/b73560bfafbf96a366e0a9d44e25ccc0a4704bfc))
+* **internal:** update java toolchain ([7c8e53c](https://github.com/braintrustdata/braintrust-java/commit/7c8e53c86b4733074c59ca9de3d8a7fb63070350))
+* remove memory upper bound from publishing step ([1efb5d6](https://github.com/braintrustdata/braintrust-java/commit/1efb5d642e574d1e589734c7460fd8e87dd4389f))
+* update @stainless-api/prism-cli to v5.15.0 ([dba7eae](https://github.com/braintrustdata/braintrust-java/commit/dba7eaed2f677029109085d15355e048efaa006d))
+
+
+### Documentation
+
+* fix missing readme comment ([4cf9617](https://github.com/braintrustdata/braintrust-java/commit/4cf9617412a0abf92433d8435728f2b8e77058a7))
+* more code comments ([7a93a83](https://github.com/braintrustdata/braintrust-java/commit/7a93a8349115484ba0f073cf60e8084ed9c8be51))
+
+
+### Refactors
+
+* **internal:** minor `ClientOptionsTest` change ([2e7263e](https://github.com/braintrustdata/braintrust-java/commit/2e7263e6927f66064c7609f99c1073381bbc2300))
+
## 0.9.0 (2025-04-23)
Full Changelog: [v0.8.0...v0.9.0](https://github.com/braintrustdata/braintrust-java/compare/v0.8.0...v0.9.0)
diff --git a/README.md b/README.md
index 18106805..c42de50c 100644
--- a/README.md
+++ b/README.md
@@ -2,8 +2,8 @@
-[](https://central.sonatype.com/artifact/com.braintrustdata.api/braintrust-java/0.9.0)
-[](https://javadoc.io/doc/com.braintrustdata.api/braintrust-java/0.9.0)
+[](https://central.sonatype.com/artifact/com.braintrustdata.api/braintrust-java/0.10.0)
+[](https://javadoc.io/doc/com.braintrustdata.api/braintrust-java/0.10.0)
@@ -15,7 +15,7 @@ It is generated with [Stainless](https://www.stainless.com/).
-The REST API documentation can be found on [www.braintrustdata.com](https://www.braintrustdata.com/docs/api/spec). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.braintrustdata.api/braintrust-java/0.9.0).
+The REST API documentation can be found on [www.braintrustdata.com](https://www.braintrustdata.com/docs/api/spec). Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.braintrustdata.api/braintrust-java/0.10.0).
@@ -26,7 +26,7 @@ The REST API documentation can be found on [www.braintrustdata.com](https://www.
### Gradle
```kotlin
-implementation("com.braintrustdata.api:braintrust-java:0.9.0")
+implementation("com.braintrustdata.api:braintrust-java:0.10.0")
```
### Maven
@@ -35,7 +35,7 @@ implementation("com.braintrustdata.api:braintrust-java:0.9.0")
com.braintrustdata.api
braintrust-java
- 0.9.0
+ 0.10.0
```
@@ -53,7 +53,8 @@ import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient;
import com.braintrustdata.api.models.Project;
import com.braintrustdata.api.models.ProjectCreateParams;
-// Configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables
+// Configures using the `braintrust.apiKey` and `braintrust.baseUrl` system properties
+// Or configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables
BraintrustClient client = BraintrustOkHttpClient.fromEnv();
ProjectCreateParams params = ProjectCreateParams.builder()
@@ -64,13 +65,14 @@ Project project = client.projects().create(params);
## Client configuration
-Configure the client using environment variables:
+Configure the client using system properties or environment variables:
```java
import com.braintrustdata.api.client.BraintrustClient;
import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient;
-// Configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables
+// Configures using the `braintrust.apiKey` and `braintrust.baseUrl` system properties
+// Or configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables
BraintrustClient client = BraintrustOkHttpClient.fromEnv();
```
@@ -92,7 +94,8 @@ import com.braintrustdata.api.client.BraintrustClient;
import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient;
BraintrustClient client = BraintrustOkHttpClient.builder()
- // Configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables
+ // Configures using the `braintrust.apiKey` and `braintrust.baseUrl` system properties
+ // Or configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables
.fromEnv()
.apiKey("My API Key")
.build();
@@ -100,15 +103,32 @@ BraintrustClient client = BraintrustOkHttpClient.builder()
See this table for the available options:
-| Setter | Environment variable | Required | Default value |
-| --------- | --------------------- | -------- | ------------------------------ |
-| `apiKey` | `BRAINTRUST_API_KEY` | false | - |
-| `baseUrl` | `BRAINTRUST_BASE_URL` | true | `"https://api.braintrust.dev"` |
+| Setter | System property | Environment variable | Required | Default value |
+| --------- | -------------------- | --------------------- | -------- | ------------------------------ |
+| `apiKey` | `braintrust.apiKey` | `BRAINTRUST_API_KEY` | false | - |
+| `baseUrl` | `braintrust.baseUrl` | `BRAINTRUST_BASE_URL` | true | `"https://api.braintrust.dev"` |
+
+System properties take precedence over environment variables.
> [!TIP]
> Don't create more than one client in the same application. Each client has a connection pool and
> thread pools, which are more efficient to share between requests.
+### Modifying configuration
+
+To temporarily use a modified client configuration, while reusing the same connection and thread pools, call `withOptions()` on any client or service:
+
+```java
+import com.braintrustdata.api.client.BraintrustClient;
+
+BraintrustClient clientWithOptions = client.withOptions(optionsBuilder -> {
+ optionsBuilder.baseUrl("https://example.com");
+ optionsBuilder.maxRetries(42);
+});
+```
+
+The `withOptions()` method does not affect the original client or service.
+
## Requests and responses
To send a request to the Braintrust API, build an instance of some `Params` class and pass it to the corresponding client method. When the response is received, it will be deserialized into an instance of a Java class.
@@ -134,7 +154,8 @@ import com.braintrustdata.api.models.Project;
import com.braintrustdata.api.models.ProjectCreateParams;
import java.util.concurrent.CompletableFuture;
-// Configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables
+// Configures using the `braintrust.apiKey` and `braintrust.baseUrl` system properties
+// Or configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables
BraintrustClient client = BraintrustOkHttpClient.fromEnv();
ProjectCreateParams params = ProjectCreateParams.builder()
@@ -152,7 +173,8 @@ import com.braintrustdata.api.models.Project;
import com.braintrustdata.api.models.ProjectCreateParams;
import java.util.concurrent.CompletableFuture;
-// Configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables
+// Configures using the `braintrust.apiKey` and `braintrust.baseUrl` system properties
+// Or configures using the `BRAINTRUST_API_KEY` and `BRAINTRUST_BASE_URL` environment variables
BraintrustClientAsync client = BraintrustOkHttpClientAsync.fromEnv();
ProjectCreateParams params = ProjectCreateParams.builder()
@@ -211,59 +233,109 @@ The SDK throws custom unchecked exception types:
- [`BraintrustIoException`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BraintrustIoException.kt): I/O networking errors.
+- [`BraintrustRetryableException`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BraintrustRetryableException.kt): Generic error indicating a failure that could be retried by the client.
+
- [`BraintrustInvalidDataException`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BraintrustInvalidDataException.kt): Failure to interpret successfully parsed data. For example, when accessing a property that's supposed to be required, but the API unexpectedly omitted it from the response.
- [`BraintrustException`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BraintrustException.kt): Base class for all exceptions. Most errors will result in one of the previously mentioned ones, but completely generic errors may be thrown using the base class.
## Pagination
-For methods that return a paginated list of results, this library provides convenient ways access the results either one page at a time, or item-by-item across all pages.
+The SDK defines methods that return a paginated lists of results. It provides convenient ways to access the results either one page at a time or item-by-item across all pages.
### Auto-pagination
-To iterate through all results across all pages, you can use `autoPager`, which automatically handles fetching more pages for you:
+To iterate through all results across all pages, use the `autoPager()` method, which automatically fetches more pages as needed.
-### Synchronous
+When using the synchronous client, the method returns an [`Iterable`](https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html)
```java
import com.braintrustdata.api.models.Project;
import com.braintrustdata.api.models.ProjectListPage;
-// As an Iterable:
-ProjectListPage page = client.projects().list(params);
+ProjectListPage page = client.projects().list();
+
+// Process as an Iterable
for (Project project : page.autoPager()) {
System.out.println(project);
-};
+}
-// As a Stream:
-client.projects().list(params).autoPager().stream()
+// Process as a Stream
+page.autoPager()
+ .stream()
.limit(50)
.forEach(project -> System.out.println(project));
```
-### Asynchronous
+When using the asynchronous client, the method returns an [`AsyncStreamResponse`](braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/AsyncStreamResponse.kt):
```java
-// Using forEach, which returns CompletableFuture:
-asyncClient.projects().list(params).autoPager()
- .forEach(project -> System.out.println(project), executor);
+import com.braintrustdata.api.core.http.AsyncStreamResponse;
+import com.braintrustdata.api.models.Project;
+import com.braintrustdata.api.models.ProjectListPageAsync;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+
+CompletableFuture pageFuture = client.async().projects().list();
+
+pageFuture.thenRun(page -> page.autoPager().subscribe(project -> {
+ System.out.println(project);
+}));
+
+// If you need to handle errors or completion of the stream
+pageFuture.thenRun(page -> page.autoPager().subscribe(new AsyncStreamResponse.Handler<>() {
+ @Override
+ public void onNext(Project project) {
+ System.out.println(project);
+ }
+
+ @Override
+ public void onComplete(Optional error) {
+ if (error.isPresent()) {
+ System.out.println("Something went wrong!");
+ throw new RuntimeException(error.get());
+ } else {
+ System.out.println("No more!");
+ }
+ }
+}));
+
+// Or use futures
+pageFuture.thenRun(page -> page.autoPager()
+ .subscribe(project -> {
+ System.out.println(project);
+ })
+ .onCompleteFuture()
+ .whenComplete((unused, error) -> {
+ if (error != null) {
+ System.out.println("Something went wrong!");
+ throw new RuntimeException(error);
+ } else {
+ System.out.println("No more!");
+ }
+ }));
```
### Manual pagination
-If none of the above helpers meet your needs, you can also manually request pages one-by-one. A page of results has a `data()` method to fetch the list of objects, as well as top-level `response` and other methods to fetch top-level data about the page. It also has methods `hasNextPage`, `getNextPage`, and `getNextPageParams` methods to help with pagination.
+To access individual page items and manually request the next page, use the `items()`,
+`hasNextPage()`, and `nextPage()` methods:
```java
import com.braintrustdata.api.models.Project;
import com.braintrustdata.api.models.ProjectListPage;
-ProjectListPage page = client.projects().list(params);
-while (page != null) {
- for (Project project : page.objects()) {
+ProjectListPage page = client.projects().list();
+while (true) {
+ for (Project project : page.items()) {
System.out.println(project);
}
- page = page.getNextPage().orElse(null);
+ if (!page.hasNextPage()) {
+ break;
+ }
+
+ page = page.nextPage();
}
```
@@ -283,6 +355,12 @@ Or to `debug` for more verbose logging:
$ export BRAINTRUST_LOG=debug
```
+## ProGuard and R8
+
+Although the SDK uses reflection, it is still usable with [ProGuard](https://github.com/Guardsquare/proguard) and [R8](https://developer.android.com/topic/performance/app-optimization/enable-app-optimization) because `braintrust-java-core` is published with a [configuration file](braintrust-java-core/src/main/resources/META-INF/proguard/braintrust-java-core.pro) containing [keep rules](https://www.guardsquare.com/manual/configuration/usage).
+
+ProGuard and R8 should automatically detect and use the published rules, but you can also manually copy the keep rules if necessary.
+
## Jackson
The SDK depends on [Jackson](https://github.com/FasterXML/jackson) for JSON serialization/deserialization. It is compatible with version 2.13.4 or higher, but depends on version 2.18.2 by default.
@@ -298,7 +376,7 @@ If the SDK threw an exception, but you're _certain_ the version is compatible, t
### Retries
-The SDK automatically retries 2 times by default, with a short exponential backoff.
+The SDK automatically retries 2 times by default, with a short exponential backoff between requests.
Only the following error types are retried:
@@ -308,7 +386,7 @@ Only the following error types are retried:
- 429 Rate Limit
- 5xx Internal
-The API may also explicitly instruct the SDK to retry or not retry a response.
+The API may also explicitly instruct the SDK to retry or not retry a request.
To set a custom number of retries, configure the client using the `maxRetries` method:
@@ -330,7 +408,6 @@ To set a custom timeout, configure the method call using the `timeout` method:
```java
import com.braintrustdata.api.models.Project;
-import com.braintrustdata.api.models.ProjectCreateParams;
Project project = client.projects().create(
params, RequestOptions.builder().timeout(Duration.ofSeconds(30)).build()
@@ -370,6 +447,27 @@ BraintrustClient client = BraintrustOkHttpClient.builder()
.build();
```
+### HTTPS
+
+> [!NOTE]
+> Most applications should not call these methods, and instead use the system defaults. The defaults include
+> special optimizations that can be lost if the implementations are modified.
+
+To configure how HTTPS connections are secured, configure the client using the `sslSocketFactory`, `trustManager`, and `hostnameVerifier` methods:
+
+```java
+import com.braintrustdata.api.client.BraintrustClient;
+import com.braintrustdata.api.client.okhttp.BraintrustOkHttpClient;
+
+BraintrustClient client = BraintrustOkHttpClient.builder()
+ .fromEnv()
+ // If `sslSocketFactory` is set, then `trustManager` must be set, and vice versa.
+ .sslSocketFactory(yourSSLSocketFactory)
+ .trustManager(yourTrustManager)
+ .hostnameVerifier(yourHostnameVerifier)
+ .build();
+```
+
### Custom HTTP client
The SDK consists of three artifacts:
@@ -578,7 +676,6 @@ Or configure the method call to validate the response using the `responseValidat
```java
import com.braintrustdata.api.models.Project;
-import com.braintrustdata.api.models.ProjectCreateParams;
Project project = client.projects().create(
params, RequestOptions.builder().responseValidation(true).build()
diff --git a/SECURITY.md b/SECURITY.md
index 0923aae0..a7f4f3b4 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -16,11 +16,11 @@ before making any information public.
## Reporting Non-SDK Related Security Issues
If you encounter security issues that are not directly related to SDKs but pertain to the services
-or products provided by Braintrust please follow the respective company's security reporting guidelines.
+or products provided by Braintrust, please follow the respective company's security reporting guidelines.
### Braintrust Terms and Policies
-Please contact info@braintrustdata.com for any questions or concerns regarding security of our services.
+Please contact info@braintrustdata.com for any questions or concerns regarding the security of our services.
---
diff --git a/bin/check-release-environment b/bin/check-release-environment
index cc9c2cd7..3a6a7b4a 100755
--- a/bin/check-release-environment
+++ b/bin/check-release-environment
@@ -3,19 +3,19 @@
errors=()
if [ -z "${SONATYPE_USERNAME}" ]; then
- errors+=("The BRAINTRUST_SONATYPE_USERNAME secret has not been set. Please set it in either this repository's secrets or your organization secrets")
+ 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 BRAINTRUST_SONATYPE_PASSWORD secret has not been set. Please set it in either this repository's secrets or your organization secrets")
+ 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 BRAINTRUST_SONATYPE_GPG_SIGNING_KEY secret has not been set. Please set it in either this repository's secrets or your organization secrets")
+ 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 BRAINTRUST_SONATYPE_GPG_SIGNING_PASSWORD secret has not been set. Please set it in either this repository's secrets or your organization secrets")
+ 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[@]}
diff --git a/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClient.kt b/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClient.kt
index aa4f40a4..fc6b2858 100755
--- a/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClient.kt
+++ b/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClient.kt
@@ -6,22 +6,38 @@ import com.braintrustdata.api.client.BraintrustClient
import com.braintrustdata.api.client.BraintrustClientImpl
import com.braintrustdata.api.core.ClientOptions
import com.braintrustdata.api.core.Timeout
+import com.braintrustdata.api.core.http.AsyncStreamResponse
import com.braintrustdata.api.core.http.Headers
+import com.braintrustdata.api.core.http.HttpClient
import com.braintrustdata.api.core.http.QueryParams
+import com.braintrustdata.api.core.jsonMapper
import com.fasterxml.jackson.databind.json.JsonMapper
import java.net.Proxy
import java.time.Clock
import java.time.Duration
import java.util.Optional
+import java.util.concurrent.Executor
+import javax.net.ssl.HostnameVerifier
+import javax.net.ssl.SSLSocketFactory
+import javax.net.ssl.X509TrustManager
import kotlin.jvm.optionals.getOrNull
+/**
+ * A class that allows building an instance of [BraintrustClient] with [OkHttpClient] as the
+ * underlying [HttpClient].
+ */
class BraintrustOkHttpClient private constructor() {
companion object {
- /** Returns a mutable builder for constructing an instance of [BraintrustOkHttpClient]. */
+ /** Returns a mutable builder for constructing an instance of [BraintrustClient]. */
@JvmStatic fun builder() = Builder()
+ /**
+ * Returns a client configured using system properties and environment variables.
+ *
+ * @see ClientOptions.Builder.fromEnv
+ */
@JvmStatic fun fromEnv(): BraintrustClient = builder().fromEnv().build()
}
@@ -29,10 +45,63 @@ class BraintrustOkHttpClient private constructor() {
class Builder internal constructor() {
private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
- private var timeout: Timeout = Timeout.default()
private var proxy: Proxy? = null
+ private var sslSocketFactory: SSLSocketFactory? = null
+ private var trustManager: X509TrustManager? = null
+ private var hostnameVerifier: HostnameVerifier? = null
+
+ fun proxy(proxy: Proxy?) = apply { this.proxy = proxy }
+
+ /** Alias for calling [Builder.proxy] with `proxy.orElse(null)`. */
+ fun proxy(proxy: Optional) = proxy(proxy.getOrNull())
+
+ /**
+ * The socket factory used to secure HTTPS connections.
+ *
+ * If this is set, then [trustManager] must also be set.
+ *
+ * If unset, then the system default is used. Most applications should not call this method,
+ * and instead use the system default. The default include special optimizations that can be
+ * lost if the implementation is modified.
+ */
+ fun sslSocketFactory(sslSocketFactory: SSLSocketFactory?) = apply {
+ this.sslSocketFactory = sslSocketFactory
+ }
+
+ /** Alias for calling [Builder.sslSocketFactory] with `sslSocketFactory.orElse(null)`. */
+ fun sslSocketFactory(sslSocketFactory: Optional) =
+ sslSocketFactory(sslSocketFactory.getOrNull())
+
+ /**
+ * The trust manager used to secure HTTPS connections.
+ *
+ * If this is set, then [sslSocketFactory] must also be set.
+ *
+ * If unset, then the system default is used. Most applications should not call this method,
+ * and instead use the system default. The default include special optimizations that can be
+ * lost if the implementation is modified.
+ */
+ fun trustManager(trustManager: X509TrustManager?) = apply {
+ this.trustManager = trustManager
+ }
+
+ /** Alias for calling [Builder.trustManager] with `trustManager.orElse(null)`. */
+ fun trustManager(trustManager: Optional) =
+ trustManager(trustManager.getOrNull())
+
+ /**
+ * The verifier used to confirm that response certificates apply to requested hostnames for
+ * HTTPS connections.
+ *
+ * If unset, then a default hostname verifier is used.
+ */
+ fun hostnameVerifier(hostnameVerifier: HostnameVerifier?) = apply {
+ this.hostnameVerifier = hostnameVerifier
+ }
- fun baseUrl(baseUrl: String) = apply { clientOptions.baseUrl(baseUrl) }
+ /** Alias for calling [Builder.hostnameVerifier] with `hostnameVerifier.orElse(null)`. */
+ fun hostnameVerifier(hostnameVerifier: Optional) =
+ hostnameVerifier(hostnameVerifier.getOrNull())
/**
* Whether to throw an exception if any of the Jackson versions detected at runtime are
@@ -45,10 +114,93 @@ class BraintrustOkHttpClient private constructor() {
clientOptions.checkJacksonVersionCompatibility(checkJacksonVersionCompatibility)
}
+ /**
+ * The Jackson JSON mapper to use for serializing and deserializing JSON.
+ *
+ * Defaults to [com.braintrustdata.api.core.jsonMapper]. The default is usually sufficient
+ * and rarely needs to be overridden.
+ */
fun jsonMapper(jsonMapper: JsonMapper) = apply { clientOptions.jsonMapper(jsonMapper) }
+ /**
+ * The executor to use for running [AsyncStreamResponse.Handler] callbacks.
+ *
+ * Defaults to a dedicated cached thread pool.
+ *
+ * This class takes ownership of the executor and shuts it down, if possible, when closed.
+ */
+ fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply {
+ clientOptions.streamHandlerExecutor(streamHandlerExecutor)
+ }
+
+ /**
+ * The clock to use for operations that require timing, like retries.
+ *
+ * This is primarily useful for using a fake clock in tests.
+ *
+ * Defaults to [Clock.systemUTC].
+ */
fun clock(clock: Clock) = apply { clientOptions.clock(clock) }
+ /**
+ * The base URL to use for every request.
+ *
+ * Defaults to the production environment: `https://api.braintrust.dev`.
+ */
+ fun baseUrl(baseUrl: String?) = apply { clientOptions.baseUrl(baseUrl) }
+
+ /** Alias for calling [Builder.baseUrl] with `baseUrl.orElse(null)`. */
+ fun baseUrl(baseUrl: Optional) = baseUrl(baseUrl.getOrNull())
+
+ /**
+ * Whether to call `validate` on every response before returning it.
+ *
+ * Defaults to false, which means the shape of the response will not be validated upfront.
+ * Instead, validation will only occur for the parts of the response that are accessed.
+ */
+ fun responseValidation(responseValidation: Boolean) = apply {
+ clientOptions.responseValidation(responseValidation)
+ }
+
+ /**
+ * Sets the maximum time allowed for various parts of an HTTP call's lifecycle, excluding
+ * retries.
+ *
+ * Defaults to [Timeout.default].
+ */
+ fun timeout(timeout: Timeout) = apply { clientOptions.timeout(timeout) }
+
+ /**
+ * Sets the maximum time allowed for a complete HTTP call, not including retries.
+ *
+ * See [Timeout.request] for more details.
+ *
+ * For fine-grained control, pass a [Timeout] object.
+ */
+ fun timeout(timeout: Duration) = apply { clientOptions.timeout(timeout) }
+
+ /**
+ * The maximum number of times to retry failed requests, with a short exponential backoff
+ * between requests.
+ *
+ * Only the following error types are retried:
+ * - Connection errors (for example, due to a network connectivity problem)
+ * - 408 Request Timeout
+ * - 409 Conflict
+ * - 429 Rate Limit
+ * - 5xx Internal
+ *
+ * The API may also explicitly instruct the SDK to retry or not retry a request.
+ *
+ * Defaults to 2.
+ */
+ fun maxRetries(maxRetries: Int) = apply { clientOptions.maxRetries(maxRetries) }
+
+ fun apiKey(apiKey: String?) = apply { clientOptions.apiKey(apiKey) }
+
+ /** Alias for calling [Builder.apiKey] with `apiKey.orElse(null)`. */
+ fun apiKey(apiKey: Optional) = apiKey(apiKey.getOrNull())
+
fun headers(headers: Headers) = apply { clientOptions.headers(headers) }
fun headers(headers: Map>) = apply {
@@ -129,33 +281,11 @@ class BraintrustOkHttpClient private constructor() {
clientOptions.removeAllQueryParams(keys)
}
- fun timeout(timeout: Timeout) = apply {
- clientOptions.timeout(timeout)
- this.timeout = timeout
- }
-
/**
- * Sets the maximum time allowed for a complete HTTP call, not including retries.
- *
- * See [Timeout.request] for more details.
+ * Updates configuration using system properties and environment variables.
*
- * For fine-grained control, pass a [Timeout] object.
+ * @see ClientOptions.Builder.fromEnv
*/
- fun timeout(timeout: Duration) = timeout(Timeout.builder().request(timeout).build())
-
- fun maxRetries(maxRetries: Int) = apply { clientOptions.maxRetries(maxRetries) }
-
- fun proxy(proxy: Proxy) = apply { this.proxy = proxy }
-
- fun responseValidation(responseValidation: Boolean) = apply {
- clientOptions.responseValidation(responseValidation)
- }
-
- fun apiKey(apiKey: String?) = apply { clientOptions.apiKey(apiKey) }
-
- /** Alias for calling [Builder.apiKey] with `apiKey.orElse(null)`. */
- fun apiKey(apiKey: Optional) = apiKey(apiKey.getOrNull())
-
fun fromEnv() = apply { clientOptions.fromEnv() }
/**
@@ -168,9 +298,11 @@ class BraintrustOkHttpClient private constructor() {
clientOptions
.httpClient(
OkHttpClient.builder()
- .baseUrl(clientOptions.baseUrl())
- .timeout(timeout)
+ .timeout(clientOptions.timeout())
.proxy(proxy)
+ .sslSocketFactory(sslSocketFactory)
+ .trustManager(trustManager)
+ .hostnameVerifier(hostnameVerifier)
.build()
)
.build()
diff --git a/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClientAsync.kt b/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClientAsync.kt
index c0d37976..01106575 100755
--- a/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClientAsync.kt
+++ b/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/BraintrustOkHttpClientAsync.kt
@@ -6,24 +6,38 @@ import com.braintrustdata.api.client.BraintrustClientAsync
import com.braintrustdata.api.client.BraintrustClientAsyncImpl
import com.braintrustdata.api.core.ClientOptions
import com.braintrustdata.api.core.Timeout
+import com.braintrustdata.api.core.http.AsyncStreamResponse
import com.braintrustdata.api.core.http.Headers
+import com.braintrustdata.api.core.http.HttpClient
import com.braintrustdata.api.core.http.QueryParams
+import com.braintrustdata.api.core.jsonMapper
import com.fasterxml.jackson.databind.json.JsonMapper
import java.net.Proxy
import java.time.Clock
import java.time.Duration
import java.util.Optional
+import java.util.concurrent.Executor
+import javax.net.ssl.HostnameVerifier
+import javax.net.ssl.SSLSocketFactory
+import javax.net.ssl.X509TrustManager
import kotlin.jvm.optionals.getOrNull
+/**
+ * A class that allows building an instance of [BraintrustClientAsync] with [OkHttpClient] as the
+ * underlying [HttpClient].
+ */
class BraintrustOkHttpClientAsync private constructor() {
companion object {
- /**
- * Returns a mutable builder for constructing an instance of [BraintrustOkHttpClientAsync].
- */
+ /** Returns a mutable builder for constructing an instance of [BraintrustClientAsync]. */
@JvmStatic fun builder() = Builder()
+ /**
+ * Returns a client configured using system properties and environment variables.
+ *
+ * @see ClientOptions.Builder.fromEnv
+ */
@JvmStatic fun fromEnv(): BraintrustClientAsync = builder().fromEnv().build()
}
@@ -31,10 +45,63 @@ class BraintrustOkHttpClientAsync private constructor() {
class Builder internal constructor() {
private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
- private var timeout: Timeout = Timeout.default()
private var proxy: Proxy? = null
+ private var sslSocketFactory: SSLSocketFactory? = null
+ private var trustManager: X509TrustManager? = null
+ private var hostnameVerifier: HostnameVerifier? = null
+
+ fun proxy(proxy: Proxy?) = apply { this.proxy = proxy }
+
+ /** Alias for calling [Builder.proxy] with `proxy.orElse(null)`. */
+ fun proxy(proxy: Optional) = proxy(proxy.getOrNull())
+
+ /**
+ * The socket factory used to secure HTTPS connections.
+ *
+ * If this is set, then [trustManager] must also be set.
+ *
+ * If unset, then the system default is used. Most applications should not call this method,
+ * and instead use the system default. The default include special optimizations that can be
+ * lost if the implementation is modified.
+ */
+ fun sslSocketFactory(sslSocketFactory: SSLSocketFactory?) = apply {
+ this.sslSocketFactory = sslSocketFactory
+ }
+
+ /** Alias for calling [Builder.sslSocketFactory] with `sslSocketFactory.orElse(null)`. */
+ fun sslSocketFactory(sslSocketFactory: Optional) =
+ sslSocketFactory(sslSocketFactory.getOrNull())
+
+ /**
+ * The trust manager used to secure HTTPS connections.
+ *
+ * If this is set, then [sslSocketFactory] must also be set.
+ *
+ * If unset, then the system default is used. Most applications should not call this method,
+ * and instead use the system default. The default include special optimizations that can be
+ * lost if the implementation is modified.
+ */
+ fun trustManager(trustManager: X509TrustManager?) = apply {
+ this.trustManager = trustManager
+ }
- fun baseUrl(baseUrl: String) = apply { clientOptions.baseUrl(baseUrl) }
+ /** Alias for calling [Builder.trustManager] with `trustManager.orElse(null)`. */
+ fun trustManager(trustManager: Optional) =
+ trustManager(trustManager.getOrNull())
+
+ /**
+ * The verifier used to confirm that response certificates apply to requested hostnames for
+ * HTTPS connections.
+ *
+ * If unset, then a default hostname verifier is used.
+ */
+ fun hostnameVerifier(hostnameVerifier: HostnameVerifier?) = apply {
+ this.hostnameVerifier = hostnameVerifier
+ }
+
+ /** Alias for calling [Builder.hostnameVerifier] with `hostnameVerifier.orElse(null)`. */
+ fun hostnameVerifier(hostnameVerifier: Optional) =
+ hostnameVerifier(hostnameVerifier.getOrNull())
/**
* Whether to throw an exception if any of the Jackson versions detected at runtime are
@@ -47,10 +114,93 @@ class BraintrustOkHttpClientAsync private constructor() {
clientOptions.checkJacksonVersionCompatibility(checkJacksonVersionCompatibility)
}
+ /**
+ * The Jackson JSON mapper to use for serializing and deserializing JSON.
+ *
+ * Defaults to [com.braintrustdata.api.core.jsonMapper]. The default is usually sufficient
+ * and rarely needs to be overridden.
+ */
fun jsonMapper(jsonMapper: JsonMapper) = apply { clientOptions.jsonMapper(jsonMapper) }
+ /**
+ * The executor to use for running [AsyncStreamResponse.Handler] callbacks.
+ *
+ * Defaults to a dedicated cached thread pool.
+ *
+ * This class takes ownership of the executor and shuts it down, if possible, when closed.
+ */
+ fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply {
+ clientOptions.streamHandlerExecutor(streamHandlerExecutor)
+ }
+
+ /**
+ * The clock to use for operations that require timing, like retries.
+ *
+ * This is primarily useful for using a fake clock in tests.
+ *
+ * Defaults to [Clock.systemUTC].
+ */
fun clock(clock: Clock) = apply { clientOptions.clock(clock) }
+ /**
+ * The base URL to use for every request.
+ *
+ * Defaults to the production environment: `https://api.braintrust.dev`.
+ */
+ fun baseUrl(baseUrl: String?) = apply { clientOptions.baseUrl(baseUrl) }
+
+ /** Alias for calling [Builder.baseUrl] with `baseUrl.orElse(null)`. */
+ fun baseUrl(baseUrl: Optional) = baseUrl(baseUrl.getOrNull())
+
+ /**
+ * Whether to call `validate` on every response before returning it.
+ *
+ * Defaults to false, which means the shape of the response will not be validated upfront.
+ * Instead, validation will only occur for the parts of the response that are accessed.
+ */
+ fun responseValidation(responseValidation: Boolean) = apply {
+ clientOptions.responseValidation(responseValidation)
+ }
+
+ /**
+ * Sets the maximum time allowed for various parts of an HTTP call's lifecycle, excluding
+ * retries.
+ *
+ * Defaults to [Timeout.default].
+ */
+ fun timeout(timeout: Timeout) = apply { clientOptions.timeout(timeout) }
+
+ /**
+ * Sets the maximum time allowed for a complete HTTP call, not including retries.
+ *
+ * See [Timeout.request] for more details.
+ *
+ * For fine-grained control, pass a [Timeout] object.
+ */
+ fun timeout(timeout: Duration) = apply { clientOptions.timeout(timeout) }
+
+ /**
+ * The maximum number of times to retry failed requests, with a short exponential backoff
+ * between requests.
+ *
+ * Only the following error types are retried:
+ * - Connection errors (for example, due to a network connectivity problem)
+ * - 408 Request Timeout
+ * - 409 Conflict
+ * - 429 Rate Limit
+ * - 5xx Internal
+ *
+ * The API may also explicitly instruct the SDK to retry or not retry a request.
+ *
+ * Defaults to 2.
+ */
+ fun maxRetries(maxRetries: Int) = apply { clientOptions.maxRetries(maxRetries) }
+
+ fun apiKey(apiKey: String?) = apply { clientOptions.apiKey(apiKey) }
+
+ /** Alias for calling [Builder.apiKey] with `apiKey.orElse(null)`. */
+ fun apiKey(apiKey: Optional) = apiKey(apiKey.getOrNull())
+
fun headers(headers: Headers) = apply { clientOptions.headers(headers) }
fun headers(headers: Map>) = apply {
@@ -131,33 +281,11 @@ class BraintrustOkHttpClientAsync private constructor() {
clientOptions.removeAllQueryParams(keys)
}
- fun timeout(timeout: Timeout) = apply {
- clientOptions.timeout(timeout)
- this.timeout = timeout
- }
-
/**
- * Sets the maximum time allowed for a complete HTTP call, not including retries.
- *
- * See [Timeout.request] for more details.
+ * Updates configuration using system properties and environment variables.
*
- * For fine-grained control, pass a [Timeout] object.
+ * @see ClientOptions.Builder.fromEnv
*/
- fun timeout(timeout: Duration) = timeout(Timeout.builder().request(timeout).build())
-
- fun maxRetries(maxRetries: Int) = apply { clientOptions.maxRetries(maxRetries) }
-
- fun proxy(proxy: Proxy) = apply { this.proxy = proxy }
-
- fun responseValidation(responseValidation: Boolean) = apply {
- clientOptions.responseValidation(responseValidation)
- }
-
- fun apiKey(apiKey: String?) = apply { clientOptions.apiKey(apiKey) }
-
- /** Alias for calling [Builder.apiKey] with `apiKey.orElse(null)`. */
- fun apiKey(apiKey: Optional) = apiKey(apiKey.getOrNull())
-
fun fromEnv() = apply { clientOptions.fromEnv() }
/**
@@ -170,9 +298,11 @@ class BraintrustOkHttpClientAsync private constructor() {
clientOptions
.httpClient(
OkHttpClient.builder()
- .baseUrl(clientOptions.baseUrl())
- .timeout(timeout)
+ .timeout(clientOptions.timeout())
.proxy(proxy)
+ .sslSocketFactory(sslSocketFactory)
+ .trustManager(trustManager)
+ .hostnameVerifier(hostnameVerifier)
.build()
)
.build()
diff --git a/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/OkHttpClient.kt b/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/OkHttpClient.kt
index 49a5df68..7a162b29 100755
--- a/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/OkHttpClient.kt
+++ b/braintrust-java-client-okhttp/src/main/kotlin/com/braintrustdata/api/client/okhttp/OkHttpClient.kt
@@ -2,7 +2,6 @@ package com.braintrustdata.api.client.okhttp
import com.braintrustdata.api.core.RequestOptions
import com.braintrustdata.api.core.Timeout
-import com.braintrustdata.api.core.checkRequired
import com.braintrustdata.api.core.http.Headers
import com.braintrustdata.api.core.http.HttpClient
import com.braintrustdata.api.core.http.HttpMethod
@@ -15,9 +14,11 @@ import java.io.InputStream
import java.net.Proxy
import java.time.Duration
import java.util.concurrent.CompletableFuture
+import javax.net.ssl.HostnameVerifier
+import javax.net.ssl.SSLSocketFactory
+import javax.net.ssl.X509TrustManager
import okhttp3.Call
import okhttp3.Callback
-import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaType
@@ -28,8 +29,7 @@ import okhttp3.Response
import okhttp3.logging.HttpLoggingInterceptor
import okio.BufferedSink
-class OkHttpClient
-private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val baseUrl: HttpUrl) :
+class OkHttpClient private constructor(private val okHttpClient: okhttp3.OkHttpClient) :
HttpClient {
override fun execute(request: HttpRequest, requestOptions: RequestOptions): HttpResponse {
@@ -140,11 +140,7 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
}
private fun HttpRequest.toUrl(): String {
- url?.let {
- return it
- }
-
- val builder = baseUrl.newBuilder()
+ val builder = baseUrl.toHttpUrl().newBuilder()
pathSegments.forEach(builder::addPathSegment)
queryParams.keys().forEach { key ->
queryParams.values(key).forEach { builder.addQueryParameter(key, it) }
@@ -194,11 +190,11 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
class Builder internal constructor() {
- private var baseUrl: HttpUrl? = null
private var timeout: Timeout = Timeout.default()
private var proxy: Proxy? = null
-
- fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl.toHttpUrl() }
+ private var sslSocketFactory: SSLSocketFactory? = null
+ private var trustManager: X509TrustManager? = null
+ private var hostnameVerifier: HostnameVerifier? = null
fun timeout(timeout: Timeout) = apply { this.timeout = timeout }
@@ -206,6 +202,18 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
fun proxy(proxy: Proxy?) = apply { this.proxy = proxy }
+ fun sslSocketFactory(sslSocketFactory: SSLSocketFactory?) = apply {
+ this.sslSocketFactory = sslSocketFactory
+ }
+
+ fun trustManager(trustManager: X509TrustManager?) = apply {
+ this.trustManager = trustManager
+ }
+
+ fun hostnameVerifier(hostnameVerifier: HostnameVerifier?) = apply {
+ this.hostnameVerifier = hostnameVerifier
+ }
+
fun build(): OkHttpClient =
OkHttpClient(
okhttp3.OkHttpClient.Builder()
@@ -214,8 +222,25 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
.writeTimeout(timeout.write())
.callTimeout(timeout.request())
.proxy(proxy)
- .build(),
- checkRequired("baseUrl", baseUrl),
+ .apply {
+ val sslSocketFactory = sslSocketFactory
+ val trustManager = trustManager
+ if (sslSocketFactory != null && trustManager != null) {
+ sslSocketFactory(sslSocketFactory, trustManager)
+ } else {
+ check((sslSocketFactory != null) == (trustManager != null)) {
+ "Both or none of `sslSocketFactory` and `trustManager` must be set, but only one was set"
+ }
+ }
+
+ hostnameVerifier?.let(::hostnameVerifier)
+ }
+ .build()
+ .apply {
+ // We usually make all our requests to the same host so it makes sense to
+ // raise the per-host limit to the overall limit.
+ dispatcher.maxRequestsPerHost = dispatcher.maxRequests
+ }
)
}
}
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClient.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClient.kt
index bc327480..7881923e 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClient.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClient.kt
@@ -2,6 +2,7 @@
package com.braintrustdata.api.client
+import com.braintrustdata.api.core.ClientOptions
import com.braintrustdata.api.services.blocking.AclService
import com.braintrustdata.api.services.blocking.AiSecretService
import com.braintrustdata.api.services.blocking.ApiKeyService
@@ -21,6 +22,7 @@ import com.braintrustdata.api.services.blocking.SpanIframeService
import com.braintrustdata.api.services.blocking.TopLevelService
import com.braintrustdata.api.services.blocking.UserService
import com.braintrustdata.api.services.blocking.ViewService
+import java.util.function.Consumer
/**
* A client for interacting with the Braintrust REST API synchronously. You can also switch to
@@ -51,6 +53,13 @@ interface BraintrustClient {
*/
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): BraintrustClient
+
fun topLevel(): TopLevelService
fun projects(): ProjectService
@@ -105,6 +114,13 @@ interface BraintrustClient {
/** A view of [BraintrustClient] 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): BraintrustClient.WithRawResponse
+
fun topLevel(): TopLevelService.WithRawResponse
fun projects(): ProjectService.WithRawResponse
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientAsync.kt
index 24ed3368..c6edb032 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientAsync.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientAsync.kt
@@ -2,6 +2,7 @@
package com.braintrustdata.api.client
+import com.braintrustdata.api.core.ClientOptions
import com.braintrustdata.api.services.async.AclServiceAsync
import com.braintrustdata.api.services.async.AiSecretServiceAsync
import com.braintrustdata.api.services.async.ApiKeyServiceAsync
@@ -21,6 +22,7 @@ import com.braintrustdata.api.services.async.SpanIframeServiceAsync
import com.braintrustdata.api.services.async.TopLevelServiceAsync
import com.braintrustdata.api.services.async.UserServiceAsync
import com.braintrustdata.api.services.async.ViewServiceAsync
+import java.util.function.Consumer
/**
* A client for interacting with the Braintrust REST API asynchronously. You can also switch to
@@ -51,6 +53,13 @@ interface BraintrustClientAsync {
*/
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): BraintrustClientAsync
+
fun topLevel(): TopLevelServiceAsync
fun projects(): ProjectServiceAsync
@@ -107,6 +116,15 @@ interface BraintrustClientAsync {
*/
interface WithRawResponse {
+ /**
+ * Returns a view of this service with the given option modifications applied.
+ *
+ * The original service is not modified.
+ */
+ fun withOptions(
+ modifier: Consumer
+ ): BraintrustClientAsync.WithRawResponse
+
fun topLevel(): TopLevelServiceAsync.WithRawResponse
fun projects(): ProjectServiceAsync.WithRawResponse
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientAsyncImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientAsyncImpl.kt
index e945466b..2d94732b 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientAsyncImpl.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientAsyncImpl.kt
@@ -42,6 +42,7 @@ import com.braintrustdata.api.services.async.UserServiceAsync
import com.braintrustdata.api.services.async.UserServiceAsyncImpl
import com.braintrustdata.api.services.async.ViewServiceAsync
import com.braintrustdata.api.services.async.ViewServiceAsyncImpl
+import java.util.function.Consumer
class BraintrustClientAsyncImpl(private val clientOptions: ClientOptions) : BraintrustClientAsync {
@@ -130,6 +131,9 @@ class BraintrustClientAsyncImpl(private val clientOptions: ClientOptions) : Brai
override fun withRawResponse(): BraintrustClientAsync.WithRawResponse = withRawResponse
+ override fun withOptions(modifier: Consumer): BraintrustClientAsync =
+ BraintrustClientAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build())
+
override fun topLevel(): TopLevelServiceAsync = topLevel
override fun projects(): ProjectServiceAsync = projects
@@ -168,7 +172,7 @@ class BraintrustClientAsyncImpl(private val clientOptions: ClientOptions) : Brai
override fun evals(): EvalServiceAsync = evals
- override fun close() = clientOptions.httpClient.close()
+ override fun close() = clientOptions.close()
class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) :
BraintrustClientAsync.WithRawResponse {
@@ -249,6 +253,13 @@ class BraintrustClientAsyncImpl(private val clientOptions: ClientOptions) : Brai
EvalServiceAsyncImpl.WithRawResponseImpl(clientOptions)
}
+ override fun withOptions(
+ modifier: Consumer
+ ): BraintrustClientAsync.WithRawResponse =
+ BraintrustClientAsyncImpl.WithRawResponseImpl(
+ clientOptions.toBuilder().apply(modifier::accept).build()
+ )
+
override fun topLevel(): TopLevelServiceAsync.WithRawResponse = topLevel
override fun projects(): ProjectServiceAsync.WithRawResponse = projects
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientImpl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientImpl.kt
index 3eecd3cb..c205ae48 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientImpl.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/client/BraintrustClientImpl.kt
@@ -42,6 +42,7 @@ import com.braintrustdata.api.services.blocking.UserService
import com.braintrustdata.api.services.blocking.UserServiceImpl
import com.braintrustdata.api.services.blocking.ViewService
import com.braintrustdata.api.services.blocking.ViewServiceImpl
+import java.util.function.Consumer
class BraintrustClientImpl(private val clientOptions: ClientOptions) : BraintrustClient {
@@ -118,6 +119,9 @@ class BraintrustClientImpl(private val clientOptions: ClientOptions) : Braintrus
override fun withRawResponse(): BraintrustClient.WithRawResponse = withRawResponse
+ override fun withOptions(modifier: Consumer): BraintrustClient =
+ BraintrustClientImpl(clientOptions.toBuilder().apply(modifier::accept).build())
+
override fun topLevel(): TopLevelService = topLevel
override fun projects(): ProjectService = projects
@@ -156,7 +160,7 @@ class BraintrustClientImpl(private val clientOptions: ClientOptions) : Braintrus
override fun evals(): EvalService = evals
- override fun close() = clientOptions.httpClient.close()
+ override fun close() = clientOptions.close()
class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) :
BraintrustClient.WithRawResponse {
@@ -237,6 +241,13 @@ class BraintrustClientImpl(private val clientOptions: ClientOptions) : Braintrus
EvalServiceImpl.WithRawResponseImpl(clientOptions)
}
+ override fun withOptions(
+ modifier: Consumer
+ ): BraintrustClient.WithRawResponse =
+ BraintrustClientImpl.WithRawResponseImpl(
+ clientOptions.toBuilder().apply(modifier::accept).build()
+ )
+
override fun topLevel(): TopLevelService.WithRawResponse = topLevel
override fun projects(): ProjectService.WithRawResponse = projects
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/AutoPager.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/AutoPager.kt
new file mode 100644
index 00000000..d208a9f8
--- /dev/null
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/AutoPager.kt
@@ -0,0 +1,21 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.braintrustdata.api.core
+
+import java.util.stream.Stream
+import java.util.stream.StreamSupport
+
+class AutoPager private constructor(private val firstPage: Page) : Iterable {
+
+ companion object {
+
+ fun from(firstPage: Page): AutoPager = AutoPager(firstPage)
+ }
+
+ override fun iterator(): Iterator =
+ generateSequence(firstPage) { if (it.hasNextPage()) it.nextPage() else null }
+ .flatMap { it.items() }
+ .iterator()
+
+ fun stream(): Stream = StreamSupport.stream(spliterator(), false)
+}
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/AutoPagerAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/AutoPagerAsync.kt
new file mode 100644
index 00000000..7ff270b1
--- /dev/null
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/AutoPagerAsync.kt
@@ -0,0 +1,88 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.braintrustdata.api.core
+
+import com.braintrustdata.api.core.http.AsyncStreamResponse
+import java.util.Optional
+import java.util.concurrent.CompletableFuture
+import java.util.concurrent.CompletionException
+import java.util.concurrent.Executor
+import java.util.concurrent.atomic.AtomicReference
+
+class AutoPagerAsync
+private constructor(private val firstPage: PageAsync, private val defaultExecutor: Executor) :
+ AsyncStreamResponse {
+
+ companion object {
+
+ fun from(firstPage: PageAsync, defaultExecutor: Executor): AutoPagerAsync =
+ AutoPagerAsync(firstPage, defaultExecutor)
+ }
+
+ private val onCompleteFuture = CompletableFuture()
+ private val state = AtomicReference(State.NEW)
+
+ override fun subscribe(handler: AsyncStreamResponse.Handler): AsyncStreamResponse =
+ subscribe(handler, defaultExecutor)
+
+ override fun subscribe(
+ handler: AsyncStreamResponse.Handler,
+ executor: Executor,
+ ): AsyncStreamResponse = apply {
+ // TODO(JDK): Use `compareAndExchange` once targeting JDK 9.
+ check(state.compareAndSet(State.NEW, State.SUBSCRIBED)) {
+ if (state.get() == State.SUBSCRIBED) "Cannot subscribe more than once"
+ else "Cannot subscribe after the response is closed"
+ }
+
+ fun PageAsync.handle(): CompletableFuture {
+ if (state.get() == State.CLOSED) {
+ return CompletableFuture.completedFuture(null)
+ }
+
+ items().forEach { handler.onNext(it) }
+ return if (hasNextPage()) nextPage().thenCompose { it.handle() }
+ else CompletableFuture.completedFuture(null)
+ }
+
+ executor.execute {
+ firstPage.handle().whenComplete { _, error ->
+ val actualError =
+ if (error is CompletionException && error.cause != null) error.cause else error
+ try {
+ handler.onComplete(Optional.ofNullable(actualError))
+ } finally {
+ try {
+ if (actualError == null) {
+ onCompleteFuture.complete(null)
+ } else {
+ onCompleteFuture.completeExceptionally(actualError)
+ }
+ } finally {
+ close()
+ }
+ }
+ }
+ }
+ }
+
+ override fun onCompleteFuture(): CompletableFuture = onCompleteFuture
+
+ override fun close() {
+ val previousState = state.getAndSet(State.CLOSED)
+ if (previousState == State.CLOSED) {
+ return
+ }
+
+ // When the stream is closed, we should always consider it closed. If it closed due
+ // to an error, then we will have already completed the future earlier, and this
+ // will be a no-op.
+ onCompleteFuture.complete(null)
+ }
+}
+
+private enum class State {
+ NEW,
+ SUBSCRIBED,
+ CLOSED,
+}
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Check.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Check.kt
index 7b05d4da..254bc88e 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Check.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Check.kt
@@ -5,6 +5,9 @@ package com.braintrustdata.api.core
import com.fasterxml.jackson.core.Version
import com.fasterxml.jackson.core.util.VersionUtil
+fun checkRequired(name: String, condition: Boolean) =
+ check(condition) { "`$name` is required, but was not set" }
+
fun checkRequired(name: String, value: T?): T =
checkNotNull(value) { "`$name` is required, but was not set" }
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ClientOptions.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ClientOptions.kt
index 9841ea6e..a3d3f13a 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ClientOptions.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/ClientOptions.kt
@@ -2,6 +2,7 @@
package com.braintrustdata.api.core
+import com.braintrustdata.api.core.http.AsyncStreamResponse
import com.braintrustdata.api.core.http.Headers
import com.braintrustdata.api.core.http.HttpClient
import com.braintrustdata.api.core.http.PhantomReachableClosingHttpClient
@@ -9,21 +10,92 @@ import com.braintrustdata.api.core.http.QueryParams
import com.braintrustdata.api.core.http.RetryingHttpClient
import com.fasterxml.jackson.databind.json.JsonMapper
import java.time.Clock
+import java.time.Duration
import java.util.Optional
+import java.util.concurrent.Executor
+import java.util.concurrent.ExecutorService
+import java.util.concurrent.Executors
+import java.util.concurrent.ThreadFactory
+import java.util.concurrent.atomic.AtomicLong
import kotlin.jvm.optionals.getOrNull
+/** A class representing the SDK client configuration. */
class ClientOptions
private constructor(
private val originalHttpClient: HttpClient,
+ /**
+ * The HTTP client to use in the SDK.
+ *
+ * Use the one published in `braintrust-java-client-okhttp` or implement your own.
+ *
+ * This class takes ownership of the client and closes it when closed.
+ */
@get:JvmName("httpClient") val httpClient: HttpClient,
+ /**
+ * Whether to throw an exception if any of the Jackson versions detected at runtime are
+ * incompatible with the SDK's minimum supported Jackson version (2.13.4).
+ *
+ * Defaults to true. Use extreme caution when disabling this option. There is no guarantee that
+ * the SDK will work correctly when using an incompatible Jackson version.
+ */
@get:JvmName("checkJacksonVersionCompatibility") val checkJacksonVersionCompatibility: Boolean,
+ /**
+ * The Jackson JSON mapper to use for serializing and deserializing JSON.
+ *
+ * Defaults to [com.braintrustdata.api.core.jsonMapper]. The default is usually sufficient and
+ * rarely needs to be overridden.
+ */
@get:JvmName("jsonMapper") val jsonMapper: JsonMapper,
+ /**
+ * The executor to use for running [AsyncStreamResponse.Handler] callbacks.
+ *
+ * Defaults to a dedicated cached thread pool.
+ *
+ * This class takes ownership of the executor and shuts it down, if possible, when closed.
+ */
+ @get:JvmName("streamHandlerExecutor") val streamHandlerExecutor: Executor,
+ /**
+ * The clock to use for operations that require timing, like retries.
+ *
+ * This is primarily useful for using a fake clock in tests.
+ *
+ * Defaults to [Clock.systemUTC].
+ */
@get:JvmName("clock") val clock: Clock,
- @get:JvmName("baseUrl") val baseUrl: String,
+ private val baseUrl: String?,
+ /** Headers to send with the request. */
@get:JvmName("headers") val headers: Headers,
+ /** Query params to send with the request. */
@get:JvmName("queryParams") val queryParams: QueryParams,
+ /**
+ * Whether to call `validate` on every response before returning it.
+ *
+ * Defaults to false, which means the shape of the response will not be validated upfront.
+ * Instead, validation will only occur for the parts of the response that are accessed.
+ */
@get:JvmName("responseValidation") val responseValidation: Boolean,
+ /**
+ * Sets the maximum time allowed for various parts of an HTTP call's lifecycle, excluding
+ * retries.
+ *
+ * Defaults to [Timeout.default].
+ */
@get:JvmName("timeout") val timeout: Timeout,
+ /**
+ * The maximum number of times to retry failed requests, with a short exponential backoff
+ * between requests.
+ *
+ * Only the following error types are retried:
+ * - Connection errors (for example, due to a network connectivity problem)
+ * - 408 Request Timeout
+ * - 409 Conflict
+ * - 429 Rate Limit
+ * - 5xx Internal
+ *
+ * The API may also explicitly instruct the SDK to retry or not retry a request.
+ *
+ * Defaults to 2.
+ */
@get:JvmName("maxRetries") val maxRetries: Int,
private val apiKey: String?,
) {
@@ -34,6 +106,13 @@ private constructor(
}
}
+ /**
+ * The base URL to use for every request.
+ *
+ * Defaults to the production environment: `https://api.braintrust.dev`.
+ */
+ fun baseUrl(): String = baseUrl ?: PRODUCTION_URL
+
fun apiKey(): Optional = Optional.ofNullable(apiKey)
fun toBuilder() = Builder().from(this)
@@ -52,6 +131,11 @@ private constructor(
*/
@JvmStatic fun builder() = Builder()
+ /**
+ * Returns options configured using system properties and environment variables.
+ *
+ * @see Builder.fromEnv
+ */
@JvmStatic fun fromEnv(): ClientOptions = builder().fromEnv().build()
}
@@ -61,8 +145,9 @@ private constructor(
private var httpClient: HttpClient? = null
private var checkJacksonVersionCompatibility: Boolean = true
private var jsonMapper: JsonMapper = jsonMapper()
+ private var streamHandlerExecutor: Executor? = null
private var clock: Clock = Clock.systemUTC()
- private var baseUrl: String = PRODUCTION_URL
+ private var baseUrl: String? = null
private var headers: Headers.Builder = Headers.builder()
private var queryParams: QueryParams.Builder = QueryParams.builder()
private var responseValidation: Boolean = false
@@ -75,6 +160,7 @@ private constructor(
httpClient = clientOptions.originalHttpClient
checkJacksonVersionCompatibility = clientOptions.checkJacksonVersionCompatibility
jsonMapper = clientOptions.jsonMapper
+ streamHandlerExecutor = clientOptions.streamHandlerExecutor
clock = clientOptions.clock
baseUrl = clientOptions.baseUrl
headers = clientOptions.headers.toBuilder()
@@ -85,24 +171,111 @@ private constructor(
apiKey = clientOptions.apiKey
}
- fun httpClient(httpClient: HttpClient) = apply { this.httpClient = httpClient }
+ /**
+ * The HTTP client to use in the SDK.
+ *
+ * Use the one published in `braintrust-java-client-okhttp` or implement your own.
+ *
+ * This class takes ownership of the client and closes it when closed.
+ */
+ fun httpClient(httpClient: HttpClient) = apply {
+ this.httpClient = PhantomReachableClosingHttpClient(httpClient)
+ }
+ /**
+ * Whether to throw an exception if any of the Jackson versions detected at runtime are
+ * incompatible with the SDK's minimum supported Jackson version (2.13.4).
+ *
+ * Defaults to true. Use extreme caution when disabling this option. There is no guarantee
+ * that the SDK will work correctly when using an incompatible Jackson version.
+ */
fun checkJacksonVersionCompatibility(checkJacksonVersionCompatibility: Boolean) = apply {
this.checkJacksonVersionCompatibility = checkJacksonVersionCompatibility
}
+ /**
+ * The Jackson JSON mapper to use for serializing and deserializing JSON.
+ *
+ * Defaults to [com.braintrustdata.api.core.jsonMapper]. The default is usually sufficient
+ * and rarely needs to be overridden.
+ */
fun jsonMapper(jsonMapper: JsonMapper) = apply { this.jsonMapper = jsonMapper }
+ /**
+ * The executor to use for running [AsyncStreamResponse.Handler] callbacks.
+ *
+ * Defaults to a dedicated cached thread pool.
+ *
+ * This class takes ownership of the executor and shuts it down, if possible, when closed.
+ */
+ fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply {
+ this.streamHandlerExecutor =
+ if (streamHandlerExecutor is ExecutorService)
+ PhantomReachableExecutorService(streamHandlerExecutor)
+ else streamHandlerExecutor
+ }
+
+ /**
+ * The clock to use for operations that require timing, like retries.
+ *
+ * This is primarily useful for using a fake clock in tests.
+ *
+ * Defaults to [Clock.systemUTC].
+ */
fun clock(clock: Clock) = apply { this.clock = clock }
- fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl }
+ /**
+ * The base URL to use for every request.
+ *
+ * Defaults to the production environment: `https://api.braintrust.dev`.
+ */
+ fun baseUrl(baseUrl: String?) = apply { this.baseUrl = baseUrl }
+
+ /** Alias for calling [Builder.baseUrl] with `baseUrl.orElse(null)`. */
+ fun baseUrl(baseUrl: Optional) = baseUrl(baseUrl.getOrNull())
+ /**
+ * Whether to call `validate` on every response before returning it.
+ *
+ * Defaults to false, which means the shape of the response will not be validated upfront.
+ * Instead, validation will only occur for the parts of the response that are accessed.
+ */
fun responseValidation(responseValidation: Boolean) = apply {
this.responseValidation = responseValidation
}
+ /**
+ * Sets the maximum time allowed for various parts of an HTTP call's lifecycle, excluding
+ * retries.
+ *
+ * Defaults to [Timeout.default].
+ */
fun timeout(timeout: Timeout) = apply { this.timeout = timeout }
+ /**
+ * Sets the maximum time allowed for a complete HTTP call, not including retries.
+ *
+ * See [Timeout.request] for more details.
+ *
+ * For fine-grained control, pass a [Timeout] object.
+ */
+ fun timeout(timeout: Duration) = timeout(Timeout.builder().request(timeout).build())
+
+ /**
+ * The maximum number of times to retry failed requests, with a short exponential backoff
+ * between requests.
+ *
+ * Only the following error types are retried:
+ * - Connection errors (for example, due to a network connectivity problem)
+ * - 408 Request Timeout
+ * - 409 Conflict
+ * - 429 Rate Limit
+ * - 5xx Internal
+ *
+ * The API may also explicitly instruct the SDK to retry or not retry a request.
+ *
+ * Defaults to 2.
+ */
fun maxRetries(maxRetries: Int) = apply { this.maxRetries = maxRetries }
fun apiKey(apiKey: String?) = apply { this.apiKey = apiKey }
@@ -190,11 +363,26 @@ private constructor(
fun removeAllQueryParams(keys: Set) = apply { queryParams.removeAll(keys) }
- fun baseUrl(): String = baseUrl
+ fun timeout(): Timeout = timeout
+ /**
+ * Updates configuration using system properties and environment variables.
+ *
+ * See this table for the available options:
+ *
+ * |Setter |System property |Environment variable |Required|Default value |
+ * |---------|--------------------|---------------------|--------|------------------------------|
+ * |`apiKey` |`braintrust.apiKey` |`BRAINTRUST_API_KEY` |false |- |
+ * |`baseUrl`|`braintrust.baseUrl`|`BRAINTRUST_BASE_URL`|true |`"https://api.braintrust.dev"`|
+ *
+ * System properties take precedence over environment variables.
+ */
fun fromEnv() = apply {
- System.getenv("BRAINTRUST_BASE_URL")?.let { baseUrl(it) }
- System.getenv("BRAINTRUST_API_KEY")?.let { apiKey(it) }
+ (System.getProperty("braintrust.baseUrl") ?: System.getenv("BRAINTRUST_BASE_URL"))
+ ?.let { baseUrl(it) }
+ (System.getProperty("braintrust.apiKey") ?: System.getenv("BRAINTRUST_API_KEY"))?.let {
+ apiKey(it)
+ }
}
/**
@@ -231,15 +419,28 @@ private constructor(
return ClientOptions(
httpClient,
- PhantomReachableClosingHttpClient(
- RetryingHttpClient.builder()
- .httpClient(httpClient)
- .clock(clock)
- .maxRetries(maxRetries)
- .build()
- ),
+ RetryingHttpClient.builder()
+ .httpClient(httpClient)
+ .clock(clock)
+ .maxRetries(maxRetries)
+ .build(),
checkJacksonVersionCompatibility,
jsonMapper,
+ streamHandlerExecutor
+ ?: Executors.newCachedThreadPool(
+ object : ThreadFactory {
+
+ private val threadFactory: ThreadFactory =
+ Executors.defaultThreadFactory()
+ private val count = AtomicLong(0)
+
+ override fun newThread(runnable: Runnable): Thread =
+ threadFactory.newThread(runnable).also {
+ it.name =
+ "braintrust-stream-handler-thread-${count.getAndIncrement()}"
+ }
+ }
+ ),
clock,
baseUrl,
headers.build(),
@@ -251,4 +452,19 @@ private constructor(
)
}
}
+
+ /**
+ * Closes these client options, relinquishing any underlying resources.
+ *
+ * This is purposefully not inherited from [AutoCloseable] because the client options are
+ * long-lived and usually should not be synchronously closed via try-with-resources.
+ *
+ * It's also usually not necessary to call this method at all. the default client automatically
+ * releases threads and connections if they remain idle, but if you are writing an application
+ * that needs to aggressively release unused resources, then you may call this method.
+ */
+ fun close() {
+ httpClient.close()
+ (streamHandlerExecutor as? ExecutorService)?.shutdown()
+ }
}
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Page.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Page.kt
new file mode 100644
index 00000000..5d5afd20
--- /dev/null
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Page.kt
@@ -0,0 +1,33 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.braintrustdata.api.core
+
+/**
+ * An interface representing a single page, with items of type [T], from a paginated endpoint
+ * response.
+ *
+ * Implementations of this interface are expected to request additional pages synchronously. For
+ * asynchronous pagination, see the [PageAsync] interface.
+ */
+interface Page {
+
+ /**
+ * Returns whether there's another page after this one.
+ *
+ * The method generally doesn't make requests so the result depends entirely on the data in this
+ * page. If a significant amount of time has passed between requesting this page and calling
+ * this method, then the result could be stale.
+ */
+ fun hasNextPage(): Boolean
+
+ /**
+ * Returns the page after this one by making another request.
+ *
+ * @throws IllegalStateException if it's impossible to get the next page. This exception is
+ * avoidable by calling [hasNextPage] first.
+ */
+ fun nextPage(): Page
+
+ /** Returns the items in this page. */
+ fun items(): List
+}
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/PageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/PageAsync.kt
new file mode 100644
index 00000000..10b3b47a
--- /dev/null
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/PageAsync.kt
@@ -0,0 +1,35 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.braintrustdata.api.core
+
+import java.util.concurrent.CompletableFuture
+
+/**
+ * An interface representing a single page, with items of type [T], from a paginated endpoint
+ * response.
+ *
+ * Implementations of this interface are expected to request additional pages asynchronously. For
+ * synchronous pagination, see the [Page] interface.
+ */
+interface PageAsync {
+
+ /**
+ * Returns whether there's another page after this one.
+ *
+ * The method generally doesn't make requests so the result depends entirely on the data in this
+ * page. If a significant amount of time has passed between requesting this page and calling
+ * this method, then the result could be stale.
+ */
+ fun hasNextPage(): Boolean
+
+ /**
+ * Returns the page after this one by making another request.
+ *
+ * @throws IllegalStateException if it's impossible to get the next page. This exception is
+ * avoidable by calling [hasNextPage] first.
+ */
+ fun nextPage(): CompletableFuture>
+
+ /** Returns the items in this page. */
+ fun items(): List
+}
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/PhantomReachableExecutorService.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/PhantomReachableExecutorService.kt
new file mode 100644
index 00000000..0538d523
--- /dev/null
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/PhantomReachableExecutorService.kt
@@ -0,0 +1,58 @@
+package com.braintrustdata.api.core
+
+import java.util.concurrent.Callable
+import java.util.concurrent.ExecutorService
+import java.util.concurrent.Future
+import java.util.concurrent.TimeUnit
+
+/**
+ * A delegating wrapper around an [ExecutorService] that shuts it down once it's only phantom
+ * reachable.
+ *
+ * This class ensures the [ExecutorService] is shut down even if the user forgets to do it.
+ */
+internal class PhantomReachableExecutorService(private val executorService: ExecutorService) :
+ ExecutorService {
+ init {
+ closeWhenPhantomReachable(this) { executorService.shutdown() }
+ }
+
+ override fun execute(command: Runnable) = executorService.execute(command)
+
+ override fun shutdown() = executorService.shutdown()
+
+ override fun shutdownNow(): MutableList = executorService.shutdownNow()
+
+ override fun isShutdown(): Boolean = executorService.isShutdown
+
+ override fun isTerminated(): Boolean = executorService.isTerminated
+
+ override fun awaitTermination(timeout: Long, unit: TimeUnit): Boolean =
+ executorService.awaitTermination(timeout, unit)
+
+ override fun submit(task: Callable): Future = executorService.submit(task)
+
+ override fun submit(task: Runnable, result: T): Future =
+ executorService.submit(task, result)
+
+ override fun submit(task: Runnable): Future<*> = executorService.submit(task)
+
+ override fun invokeAll(
+ tasks: MutableCollection>
+ ): MutableList> = executorService.invokeAll(tasks)
+
+ override fun invokeAll(
+ tasks: MutableCollection>,
+ timeout: Long,
+ unit: TimeUnit,
+ ): MutableList> = executorService.invokeAll(tasks, timeout, unit)
+
+ override fun invokeAny(tasks: MutableCollection>): T =
+ executorService.invokeAny(tasks)
+
+ override fun invokeAny(
+ tasks: MutableCollection>,
+ timeout: Long,
+ unit: TimeUnit,
+ ): T = executorService.invokeAny(tasks, timeout, unit)
+}
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Timeout.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Timeout.kt
index 06ee42fa..b2320ac8 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Timeout.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Timeout.kt
@@ -157,10 +157,14 @@ private constructor(
return true
}
- return /* spotless:off */ other is Timeout && connect == other.connect && read == other.read && write == other.write && request == other.request /* spotless:on */
+ return other is Timeout &&
+ connect == other.connect &&
+ read == other.read &&
+ write == other.write &&
+ request == other.request
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(connect, read, write, request) /* spotless:on */
+ override fun hashCode(): Int = Objects.hash(connect, read, write, request)
override fun toString() =
"Timeout{connect=$connect, read=$read, write=$write, request=$request}"
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Utils.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Utils.kt
index 6f9fb155..a1657ff3 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Utils.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/Utils.kt
@@ -5,6 +5,8 @@ package com.braintrustdata.api.core
import com.braintrustdata.api.errors.BraintrustInvalidDataException
import java.util.Collections
import java.util.SortedMap
+import java.util.concurrent.CompletableFuture
+import java.util.concurrent.locks.Lock
@JvmSynthetic
internal fun T?.getOrThrow(name: String): T =
@@ -90,3 +92,24 @@ internal fun Any?.contentToString(): String {
}
internal interface Enum
+
+/**
+ * Executes the given [action] while holding the lock, returning a [CompletableFuture] with the
+ * result.
+ *
+ * @param action The asynchronous action to execute while holding the lock
+ * @return A [CompletableFuture] that completes with the result of the action
+ */
+@JvmSynthetic
+internal fun Lock.withLockAsync(action: () -> CompletableFuture): CompletableFuture {
+ lock()
+ val future =
+ try {
+ action()
+ } catch (e: Throwable) {
+ unlock()
+ throw e
+ }
+ future.whenComplete { _, _ -> unlock() }
+ return future
+}
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/handlers/ErrorHandler.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/handlers/ErrorHandler.kt
index f3b14814..67559b98 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/handlers/ErrorHandler.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/handlers/ErrorHandler.kt
@@ -19,7 +19,7 @@ import com.braintrustdata.api.errors.UnprocessableEntityException
import com.fasterxml.jackson.databind.json.JsonMapper
@JvmSynthetic
-internal fun errorHandler(jsonMapper: JsonMapper): Handler {
+internal fun errorBodyHandler(jsonMapper: JsonMapper): Handler {
val handler = jsonHandler(jsonMapper)
return object : Handler {
@@ -33,52 +33,52 @@ internal fun errorHandler(jsonMapper: JsonMapper): Handler {
}
@JvmSynthetic
-internal fun Handler.withErrorHandler(errorHandler: Handler): Handler =
- object : Handler {
- override fun handle(response: HttpResponse): T =
+internal fun errorHandler(errorBodyHandler: Handler): Handler =
+ object : Handler {
+ override fun handle(response: HttpResponse): HttpResponse =
when (val statusCode = response.statusCode()) {
- in 200..299 -> this@withErrorHandler.handle(response)
+ in 200..299 -> response
400 ->
throw BadRequestException.builder()
.headers(response.headers())
- .body(errorHandler.handle(response))
+ .body(errorBodyHandler.handle(response))
.build()
401 ->
throw UnauthorizedException.builder()
.headers(response.headers())
- .body(errorHandler.handle(response))
+ .body(errorBodyHandler.handle(response))
.build()
403 ->
throw PermissionDeniedException.builder()
.headers(response.headers())
- .body(errorHandler.handle(response))
+ .body(errorBodyHandler.handle(response))
.build()
404 ->
throw NotFoundException.builder()
.headers(response.headers())
- .body(errorHandler.handle(response))
+ .body(errorBodyHandler.handle(response))
.build()
422 ->
throw UnprocessableEntityException.builder()
.headers(response.headers())
- .body(errorHandler.handle(response))
+ .body(errorBodyHandler.handle(response))
.build()
429 ->
throw RateLimitException.builder()
.headers(response.headers())
- .body(errorHandler.handle(response))
+ .body(errorBodyHandler.handle(response))
.build()
in 500..599 ->
throw InternalServerException.builder()
.statusCode(statusCode)
.headers(response.headers())
- .body(errorHandler.handle(response))
+ .body(errorBodyHandler.handle(response))
.build()
else ->
throw UnexpectedStatusCodeException.builder()
.statusCode(statusCode)
.headers(response.headers())
- .body(errorHandler.handle(response))
+ .body(errorBodyHandler.handle(response))
.build()
}
}
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/AsyncStreamResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/AsyncStreamResponse.kt
new file mode 100644
index 00000000..93dff9ec
--- /dev/null
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/AsyncStreamResponse.kt
@@ -0,0 +1,157 @@
+package com.braintrustdata.api.core.http
+
+import com.braintrustdata.api.core.http.AsyncStreamResponse.Handler
+import java.util.Optional
+import java.util.concurrent.CompletableFuture
+import java.util.concurrent.Executor
+import java.util.concurrent.atomic.AtomicReference
+
+/**
+ * A class providing access to an API response as an asynchronous stream of chunks of type [T],
+ * where each chunk can be individually processed as soon as it arrives instead of waiting on the
+ * full response.
+ */
+interface AsyncStreamResponse {
+
+ /**
+ * Registers [handler] to be called for events of this stream.
+ *
+ * [handler]'s methods will be called in the client's configured or default thread pool.
+ *
+ * @throws IllegalStateException if [subscribe] has already been called.
+ */
+ fun subscribe(handler: Handler): AsyncStreamResponse
+
+ /**
+ * Registers [handler] to be called for events of this stream.
+ *
+ * [handler]'s methods will be called in the given [executor].
+ *
+ * @throws IllegalStateException if [subscribe] has already been called.
+ */
+ fun subscribe(handler: Handler, executor: Executor): AsyncStreamResponse
+
+ /**
+ * Returns a future that completes when a stream is fully consumed, errors, or gets closed
+ * early.
+ */
+ fun onCompleteFuture(): CompletableFuture
+
+ /**
+ * Closes this resource, relinquishing any underlying resources.
+ *
+ * This is purposefully not inherited from [AutoCloseable] because this response should not be
+ * synchronously closed via try-with-resources.
+ */
+ fun close()
+
+ /** A class for handling streaming events. */
+ fun interface Handler {
+
+ /** Called whenever a chunk is received. */
+ fun onNext(value: T)
+
+ /**
+ * Called when a stream is fully consumed, errors, or gets closed early.
+ *
+ * [onNext] will not be called once this method is called.
+ *
+ * @param error Non-empty if the stream completed due to an error.
+ */
+ fun onComplete(error: Optional) {}
+ }
+}
+
+@JvmSynthetic
+internal fun CompletableFuture>.toAsync(streamHandlerExecutor: Executor) =
+ PhantomReachableClosingAsyncStreamResponse(
+ object : AsyncStreamResponse {
+
+ private val onCompleteFuture = CompletableFuture()
+ private val state = AtomicReference(State.NEW)
+
+ init {
+ this@toAsync.whenComplete { _, error ->
+ // If an error occurs from the original future, then we should resolve the
+ // `onCompleteFuture` even if `subscribe` has not been called.
+ error?.let(onCompleteFuture::completeExceptionally)
+ }
+ }
+
+ override fun subscribe(handler: Handler): AsyncStreamResponse =
+ subscribe(handler, streamHandlerExecutor)
+
+ override fun subscribe(
+ handler: Handler,
+ executor: Executor,
+ ): AsyncStreamResponse = apply {
+ // TODO(JDK): Use `compareAndExchange` once targeting JDK 9.
+ check(state.compareAndSet(State.NEW, State.SUBSCRIBED)) {
+ if (state.get() == State.SUBSCRIBED) "Cannot subscribe more than once"
+ else "Cannot subscribe after the response is closed"
+ }
+
+ this@toAsync.whenCompleteAsync(
+ { streamResponse, futureError ->
+ if (state.get() == State.CLOSED) {
+ // Avoid doing any work if `close` was called before the future
+ // completed.
+ return@whenCompleteAsync
+ }
+
+ if (futureError != null) {
+ // An error occurred before we started passing chunks to the handler.
+ handler.onComplete(Optional.of(futureError))
+ return@whenCompleteAsync
+ }
+
+ var streamError: Throwable? = null
+ try {
+ streamResponse.stream().forEach(handler::onNext)
+ } catch (e: Throwable) {
+ streamError = e
+ }
+
+ try {
+ handler.onComplete(Optional.ofNullable(streamError))
+ } finally {
+ try {
+ // Notify completion via the `onCompleteFuture` as well. This is in
+ // a separate `try-finally` block so that we still complete the
+ // future if `handler.onComplete` throws.
+ if (streamError == null) {
+ onCompleteFuture.complete(null)
+ } else {
+ onCompleteFuture.completeExceptionally(streamError)
+ }
+ } finally {
+ close()
+ }
+ }
+ },
+ executor,
+ )
+ }
+
+ override fun onCompleteFuture(): CompletableFuture = onCompleteFuture
+
+ override fun close() {
+ val previousState = state.getAndSet(State.CLOSED)
+ if (previousState == State.CLOSED) {
+ return
+ }
+
+ this@toAsync.whenComplete { streamResponse, error -> streamResponse?.close() }
+ // When the stream is closed, we should always consider it closed. If it closed due
+ // to an error, then we will have already completed the future earlier, and this
+ // will be a no-op.
+ onCompleteFuture.complete(null)
+ }
+ }
+ )
+
+private enum class State {
+ NEW,
+ SUBSCRIBED,
+ CLOSED,
+}
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/Headers.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/Headers.kt
index 6d37e804..774088ec 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/Headers.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/Headers.kt
@@ -1,5 +1,15 @@
+// File generated from our OpenAPI spec by Stainless.
+
package com.braintrustdata.api.core.http
+import com.braintrustdata.api.core.JsonArray
+import com.braintrustdata.api.core.JsonBoolean
+import com.braintrustdata.api.core.JsonMissing
+import com.braintrustdata.api.core.JsonNull
+import com.braintrustdata.api.core.JsonNumber
+import com.braintrustdata.api.core.JsonObject
+import com.braintrustdata.api.core.JsonString
+import com.braintrustdata.api.core.JsonValue
import com.braintrustdata.api.core.toImmutable
import java.util.TreeMap
@@ -28,6 +38,19 @@ private constructor(
TreeMap(String.CASE_INSENSITIVE_ORDER)
private var size: Int = 0
+ fun put(name: String, value: JsonValue): Builder = apply {
+ when (value) {
+ is JsonMissing,
+ is JsonNull -> {}
+ is JsonBoolean -> put(name, value.value.toString())
+ is JsonNumber -> put(name, value.value.toString())
+ is JsonString -> put(name, value.value)
+ is JsonArray -> value.values.forEach { put(name, it) }
+ is JsonObject ->
+ value.values.forEach { (nestedName, value) -> put("$name.$nestedName", value) }
+ }
+ }
+
fun put(name: String, value: String) = apply {
map.getOrPut(name) { mutableListOf() }.add(value)
size++
@@ -41,15 +64,6 @@ private constructor(
headers.names().forEach { put(it, headers.values(it)) }
}
- fun remove(name: String) = apply { size -= map.remove(name).orEmpty().size }
-
- fun removeAll(names: Set) = apply { names.forEach(::remove) }
-
- fun clear() = apply {
- map.clear()
- size = 0
- }
-
fun replace(name: String, value: String) = apply {
remove(name)
put(name, value)
@@ -68,6 +82,15 @@ private constructor(
headers.names().forEach { replace(it, headers.values(it)) }
}
+ fun remove(name: String) = apply { size -= map.remove(name).orEmpty().size }
+
+ fun removeAll(names: Set) = apply { names.forEach(::remove) }
+
+ fun clear() = apply {
+ map.clear()
+ size = 0
+ }
+
fun build() =
Headers(
map.mapValuesTo(TreeMap(String.CASE_INSENSITIVE_ORDER)) { (_, values) ->
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/HttpRequest.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/HttpRequest.kt
index 1105f7d4..f3c2522c 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/HttpRequest.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/HttpRequest.kt
@@ -6,7 +6,7 @@ import com.braintrustdata.api.core.toImmutable
class HttpRequest
private constructor(
@get:JvmName("method") val method: HttpMethod,
- @get:JvmName("url") val url: String?,
+ @get:JvmName("baseUrl") val baseUrl: String,
@get:JvmName("pathSegments") val pathSegments: List,
@get:JvmName("headers") val headers: Headers,
@get:JvmName("queryParams") val queryParams: QueryParams,
@@ -16,7 +16,7 @@ private constructor(
fun toBuilder(): Builder = Builder().from(this)
override fun toString(): String =
- "HttpRequest{method=$method, url=$url, pathSegments=$pathSegments, headers=$headers, queryParams=$queryParams, body=$body}"
+ "HttpRequest{method=$method, baseUrl=$baseUrl, pathSegments=$pathSegments, headers=$headers, queryParams=$queryParams, body=$body}"
companion object {
@JvmStatic fun builder() = Builder()
@@ -25,7 +25,7 @@ private constructor(
class Builder internal constructor() {
private var method: HttpMethod? = null
- private var url: String? = null
+ private var baseUrl: String? = null
private var pathSegments: MutableList = mutableListOf()
private var headers: Headers.Builder = Headers.builder()
private var queryParams: QueryParams.Builder = QueryParams.builder()
@@ -34,7 +34,7 @@ private constructor(
@JvmSynthetic
internal fun from(request: HttpRequest) = apply {
method = request.method
- url = request.url
+ baseUrl = request.baseUrl
pathSegments = request.pathSegments.toMutableList()
headers = request.headers.toBuilder()
queryParams = request.queryParams.toBuilder()
@@ -43,7 +43,7 @@ private constructor(
fun method(method: HttpMethod) = apply { this.method = method }
- fun url(url: String) = apply { this.url = url }
+ fun baseUrl(baseUrl: String) = apply { this.baseUrl = baseUrl }
fun addPathSegment(pathSegment: String) = apply { pathSegments.add(pathSegment) }
@@ -136,7 +136,7 @@ private constructor(
fun build(): HttpRequest =
HttpRequest(
checkRequired("method", method),
- url,
+ checkRequired("baseUrl", baseUrl),
pathSegments.toImmutable(),
headers.build(),
queryParams.build(),
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/PhantomReachableClosingAsyncStreamResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/PhantomReachableClosingAsyncStreamResponse.kt
new file mode 100644
index 00000000..6d826dd4
--- /dev/null
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/PhantomReachableClosingAsyncStreamResponse.kt
@@ -0,0 +1,56 @@
+package com.braintrustdata.api.core.http
+
+import com.braintrustdata.api.core.closeWhenPhantomReachable
+import com.braintrustdata.api.core.http.AsyncStreamResponse.Handler
+import java.util.Optional
+import java.util.concurrent.CompletableFuture
+import java.util.concurrent.Executor
+
+/**
+ * A delegating wrapper around an `AsyncStreamResponse` that closes it once it's only phantom
+ * reachable.
+ *
+ * This class ensures the `AsyncStreamResponse` is closed even if the user forgets to close it.
+ */
+internal class PhantomReachableClosingAsyncStreamResponse(
+ private val asyncStreamResponse: AsyncStreamResponse
+) : AsyncStreamResponse {
+
+ /**
+ * An object used for keeping `asyncStreamResponse` open while the object is still reachable.
+ */
+ private val reachabilityTracker = Object()
+
+ init {
+ closeWhenPhantomReachable(reachabilityTracker, asyncStreamResponse::close)
+ }
+
+ override fun subscribe(handler: Handler): AsyncStreamResponse = apply {
+ asyncStreamResponse.subscribe(TrackedHandler(handler, reachabilityTracker))
+ }
+
+ override fun subscribe(handler: Handler, executor: Executor): AsyncStreamResponse =
+ apply {
+ asyncStreamResponse.subscribe(TrackedHandler(handler, reachabilityTracker), executor)
+ }
+
+ override fun onCompleteFuture(): CompletableFuture =
+ asyncStreamResponse.onCompleteFuture()
+
+ override fun close() = asyncStreamResponse.close()
+}
+
+/**
+ * A wrapper around a `Handler` that also references a `reachabilityTracker` object.
+ *
+ * Referencing the `reachabilityTracker` object prevents it from getting reclaimed while the handler
+ * is still reachable.
+ */
+private class TrackedHandler(
+ private val handler: Handler,
+ private val reachabilityTracker: Any,
+) : Handler {
+ override fun onNext(value: T) = handler.onNext(value)
+
+ override fun onComplete(error: Optional) = handler.onComplete(error)
+}
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/PhantomReachableClosingStreamResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/PhantomReachableClosingStreamResponse.kt
new file mode 100644
index 00000000..9c79ceb6
--- /dev/null
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/PhantomReachableClosingStreamResponse.kt
@@ -0,0 +1,21 @@
+package com.braintrustdata.api.core.http
+
+import com.braintrustdata.api.core.closeWhenPhantomReachable
+import java.util.stream.Stream
+
+/**
+ * A delegating wrapper around a `StreamResponse` that closes it once it's only phantom reachable.
+ *
+ * This class ensures the `StreamResponse` is closed even if the user forgets to close it.
+ */
+internal class PhantomReachableClosingStreamResponse(
+ private val streamResponse: StreamResponse
+) : StreamResponse {
+ init {
+ closeWhenPhantomReachable(this, streamResponse)
+ }
+
+ override fun stream(): Stream = streamResponse.stream()
+
+ override fun close() = streamResponse.close()
+}
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/QueryParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/QueryParams.kt
index 03c719df..60103d82 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/QueryParams.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/QueryParams.kt
@@ -2,6 +2,14 @@
package com.braintrustdata.api.core.http
+import com.braintrustdata.api.core.JsonArray
+import com.braintrustdata.api.core.JsonBoolean
+import com.braintrustdata.api.core.JsonMissing
+import com.braintrustdata.api.core.JsonNull
+import com.braintrustdata.api.core.JsonNumber
+import com.braintrustdata.api.core.JsonObject
+import com.braintrustdata.api.core.JsonString
+import com.braintrustdata.api.core.JsonValue
import com.braintrustdata.api.core.toImmutable
class QueryParams
@@ -28,6 +36,39 @@ private constructor(
private val map: MutableMap> = mutableMapOf()
private var size: Int = 0
+ fun put(key: String, value: JsonValue): Builder = apply {
+ when (value) {
+ is JsonMissing,
+ is JsonNull -> {}
+ is JsonBoolean -> put(key, value.value.toString())
+ is JsonNumber -> put(key, value.value.toString())
+ is JsonString -> put(key, value.value)
+ is JsonArray ->
+ put(
+ key,
+ value.values
+ .asSequence()
+ .mapNotNull {
+ when (it) {
+ is JsonMissing,
+ is JsonNull -> null
+ is JsonBoolean -> it.value.toString()
+ is JsonNumber -> it.value.toString()
+ is JsonString -> it.value
+ is JsonArray,
+ is JsonObject ->
+ throw IllegalArgumentException(
+ "Cannot comma separate non-primitives in query params"
+ )
+ }
+ }
+ .joinToString(","),
+ )
+ is JsonObject ->
+ value.values.forEach { (nestedKey, value) -> put("$key[$nestedKey]", value) }
+ }
+ }
+
fun put(key: String, value: String) = apply {
map.getOrPut(key) { mutableListOf() }.add(value)
size++
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/RetryingHttpClient.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/RetryingHttpClient.kt
index 830c55cc..da690b8b 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/RetryingHttpClient.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/RetryingHttpClient.kt
@@ -3,6 +3,7 @@ package com.braintrustdata.api.core.http
import com.braintrustdata.api.core.RequestOptions
import com.braintrustdata.api.core.checkRequired
import com.braintrustdata.api.errors.BraintrustIoException
+import com.braintrustdata.api.errors.BraintrustRetryableException
import java.io.IOException
import java.time.Clock
import java.time.Duration
@@ -176,9 +177,10 @@ private constructor(
}
private fun shouldRetry(throwable: Throwable): Boolean =
- // Only retry IOException and BraintrustIoException, other exceptions are not intended to be
- // retried.
- throwable is IOException || throwable is BraintrustIoException
+ // Only retry known retryable exceptions, other exceptions are not intended to be retried.
+ throwable is IOException ||
+ throwable is BraintrustIoException ||
+ throwable is BraintrustRetryableException
private fun getRetryBackoffDuration(retries: Int, response: HttpResponse?): Duration {
// About the Retry-After header:
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/StreamResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/StreamResponse.kt
new file mode 100644
index 00000000..3903400b
--- /dev/null
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/core/http/StreamResponse.kt
@@ -0,0 +1,19 @@
+package com.braintrustdata.api.core.http
+
+import java.util.stream.Stream
+
+interface StreamResponse : AutoCloseable {
+
+ fun stream(): Stream
+
+ /** Overridden from [AutoCloseable] to not have a checked exception in its signature. */
+ override fun close()
+}
+
+@JvmSynthetic
+internal fun StreamResponse.map(transform: (T) -> R): StreamResponse =
+ object : StreamResponse {
+ override fun stream(): Stream = this@map.stream().map(transform)
+
+ override fun close() = this@map.close()
+ }
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BraintrustRetryableException.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BraintrustRetryableException.kt
new file mode 100644
index 00000000..e70380e9
--- /dev/null
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/errors/BraintrustRetryableException.kt
@@ -0,0 +1,15 @@
+package com.braintrustdata.api.errors
+
+/**
+ * Exception that indicates a transient error that can be retried.
+ *
+ * When this exception is thrown during an HTTP request, the SDK will automatically retry the
+ * request up to the maximum number of retries.
+ *
+ * @param message A descriptive error message
+ * @param cause The underlying cause of this exception, if any
+ */
+class BraintrustRetryableException
+@JvmOverloads
+constructor(message: String? = null, cause: Throwable? = null) :
+ BraintrustException(message, cause)
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AISecret.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AISecret.kt
index f5ad5a1b..aa14de3a 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AISecret.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AISecret.kt
@@ -507,12 +507,10 @@ private constructor(
return true
}
- return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Metadata && additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
@@ -524,12 +522,31 @@ private constructor(
return true
}
- return /* spotless:off */ other is AISecret && id == other.id && name == other.name && orgId == other.orgId && created == other.created && metadata == other.metadata && previewSecret == other.previewSecret && type == other.type && updatedAt == other.updatedAt && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is AISecret &&
+ id == other.id &&
+ name == other.name &&
+ orgId == other.orgId &&
+ created == other.created &&
+ metadata == other.metadata &&
+ previewSecret == other.previewSecret &&
+ type == other.type &&
+ updatedAt == other.updatedAt &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
- private val hashCode: Int by lazy { Objects.hash(id, name, orgId, created, metadata, previewSecret, type, updatedAt, additionalProperties) }
- /* spotless:on */
+ private val hashCode: Int by lazy {
+ Objects.hash(
+ id,
+ name,
+ orgId,
+ created,
+ metadata,
+ previewSecret,
+ type,
+ updatedAt,
+ additionalProperties,
+ )
+ }
override fun hashCode(): Int = hashCode
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Acl.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Acl.kt
index 34941085..8b5e5b75 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Acl.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Acl.kt
@@ -553,12 +553,35 @@ private constructor(
return true
}
- return /* spotless:off */ other is Acl && id == other.id && _objectOrgId == other._objectOrgId && objectId == other.objectId && objectType == other.objectType && created == other.created && groupId == other.groupId && permission == other.permission && restrictObjectType == other.restrictObjectType && roleId == other.roleId && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Acl &&
+ id == other.id &&
+ _objectOrgId == other._objectOrgId &&
+ objectId == other.objectId &&
+ objectType == other.objectType &&
+ created == other.created &&
+ groupId == other.groupId &&
+ permission == other.permission &&
+ restrictObjectType == other.restrictObjectType &&
+ roleId == other.roleId &&
+ userId == other.userId &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
- private val hashCode: Int by lazy { Objects.hash(id, _objectOrgId, objectId, objectType, created, groupId, permission, restrictObjectType, roleId, userId, additionalProperties) }
- /* spotless:on */
+ private val hashCode: Int by lazy {
+ Objects.hash(
+ id,
+ _objectOrgId,
+ objectId,
+ objectType,
+ created,
+ groupId,
+ permission,
+ restrictObjectType,
+ roleId,
+ userId,
+ additionalProperties,
+ )
+ }
override fun hashCode(): Int = hashCode
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateParams.kt
index 3276e25a..532fed3d 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateParams.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateParams.kt
@@ -79,8 +79,10 @@ private constructor(
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)
@@ -560,12 +562,15 @@ private constructor(
return true
}
- return /* spotless:off */ other is Body && addAcls == other.addAcls && removeAcls == other.removeAcls && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Body &&
+ addAcls == other.addAcls &&
+ removeAcls == other.removeAcls &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
- private val hashCode: Int by lazy { Objects.hash(addAcls, removeAcls, additionalProperties) }
- /* spotless:on */
+ private val hashCode: Int by lazy {
+ Objects.hash(addAcls, removeAcls, additionalProperties)
+ }
override fun hashCode(): Int = hashCode
@@ -1004,12 +1009,29 @@ private constructor(
return true
}
- return /* spotless:off */ other is AddAcl && objectId == other.objectId && objectType == other.objectType && groupId == other.groupId && permission == other.permission && restrictObjectType == other.restrictObjectType && roleId == other.roleId && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is AddAcl &&
+ objectId == other.objectId &&
+ objectType == other.objectType &&
+ groupId == other.groupId &&
+ permission == other.permission &&
+ restrictObjectType == other.restrictObjectType &&
+ roleId == other.roleId &&
+ userId == other.userId &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
- private val hashCode: Int by lazy { Objects.hash(objectId, objectType, groupId, permission, restrictObjectType, roleId, userId, additionalProperties) }
- /* spotless:on */
+ private val hashCode: Int by lazy {
+ Objects.hash(
+ objectId,
+ objectType,
+ groupId,
+ permission,
+ restrictObjectType,
+ roleId,
+ userId,
+ additionalProperties,
+ )
+ }
override fun hashCode(): Int = hashCode
@@ -1448,12 +1470,29 @@ private constructor(
return true
}
- return /* spotless:off */ other is RemoveAcl && objectId == other.objectId && objectType == other.objectType && groupId == other.groupId && permission == other.permission && restrictObjectType == other.restrictObjectType && roleId == other.roleId && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is RemoveAcl &&
+ objectId == other.objectId &&
+ objectType == other.objectType &&
+ groupId == other.groupId &&
+ permission == other.permission &&
+ restrictObjectType == other.restrictObjectType &&
+ roleId == other.roleId &&
+ userId == other.userId &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
- private val hashCode: Int by lazy { Objects.hash(objectId, objectType, groupId, permission, restrictObjectType, roleId, userId, additionalProperties) }
- /* spotless:on */
+ private val hashCode: Int by lazy {
+ Objects.hash(
+ objectId,
+ objectType,
+ groupId,
+ permission,
+ restrictObjectType,
+ roleId,
+ userId,
+ additionalProperties,
+ )
+ }
override fun hashCode(): Int = hashCode
@@ -1466,10 +1505,13 @@ private constructor(
return true
}
- return /* spotless:off */ other is AclBatchUpdateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
+ return other is AclBatchUpdateParams &&
+ body == other.body &&
+ additionalHeaders == other.additionalHeaders &&
+ additionalQueryParams == other.additionalQueryParams
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */
+ override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams)
override fun toString() =
"AclBatchUpdateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}"
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateResponse.kt
index 901575b1..2d0e1f13 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateResponse.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclBatchUpdateResponse.kt
@@ -266,12 +266,13 @@ private constructor(
return true
}
- return /* spotless:off */ other is AclBatchUpdateResponse && addedAcls == other.addedAcls && removedAcls == other.removedAcls && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is AclBatchUpdateResponse &&
+ addedAcls == other.addedAcls &&
+ removedAcls == other.removedAcls &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(addedAcls, removedAcls, additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclCreateParams.kt
index 88196664..677e26c0 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclCreateParams.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclCreateParams.kt
@@ -140,8 +140,10 @@ private constructor(
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)
@@ -872,13 +874,30 @@ private constructor(
return true
}
- return /* spotless:off */ other is Body && objectId == other.objectId && objectType == other.objectType && groupId == other.groupId && permission == other.permission && restrictObjectType == other.restrictObjectType && roleId == other.roleId && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Body &&
+ objectId == other.objectId &&
+ objectType == other.objectType &&
+ groupId == other.groupId &&
+ permission == other.permission &&
+ restrictObjectType == other.restrictObjectType &&
+ roleId == other.roleId &&
+ userId == other.userId &&
+ additionalProperties == other.additionalProperties
+ }
+
+ private val hashCode: Int by lazy {
+ Objects.hash(
+ objectId,
+ objectType,
+ groupId,
+ permission,
+ restrictObjectType,
+ roleId,
+ userId,
+ additionalProperties,
+ )
}
- /* spotless:off */
- private val hashCode: Int by lazy { Objects.hash(objectId, objectType, groupId, permission, restrictObjectType, roleId, userId, additionalProperties) }
- /* spotless:on */
-
override fun hashCode(): Int = hashCode
override fun toString() =
@@ -890,10 +909,13 @@ private constructor(
return true
}
- return /* spotless:off */ other is AclCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
+ return other is AclCreateParams &&
+ body == other.body &&
+ additionalHeaders == other.additionalHeaders &&
+ additionalQueryParams == other.additionalQueryParams
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */
+ override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams)
override fun toString() =
"AclCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}"
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclDeleteParams.kt
index 9b05873d..1e13b46a 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclDeleteParams.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclDeleteParams.kt
@@ -4,43 +4,41 @@ package com.braintrustdata.api.models
import com.braintrustdata.api.core.JsonValue
import com.braintrustdata.api.core.Params
-import com.braintrustdata.api.core.checkRequired
import com.braintrustdata.api.core.http.Headers
import com.braintrustdata.api.core.http.QueryParams
import com.braintrustdata.api.core.toImmutable
import java.util.Objects
import java.util.Optional
+import kotlin.jvm.optionals.getOrNull
/** Delete an acl object by its id */
class AclDeleteParams
private constructor(
- private val aclId: String,
+ private val aclId: String?,
private val additionalHeaders: Headers,
private val additionalQueryParams: QueryParams,
private val additionalBodyProperties: Map,
) : Params {
/** Acl id */
- fun aclId(): String = aclId
+ fun aclId(): Optional = Optional.ofNullable(aclId)
+ /** Additional body properties to send with the request. */
fun _additionalBodyProperties(): Map = additionalBodyProperties
+ /** Additional headers to send with the request. */
fun _additionalHeaders(): Headers = additionalHeaders
+ /** Additional query param to send with the request. */
fun _additionalQueryParams(): QueryParams = additionalQueryParams
fun toBuilder() = Builder().from(this)
companion object {
- /**
- * Returns a mutable builder for constructing an instance of [AclDeleteParams].
- *
- * The following fields are required:
- * ```java
- * .aclId()
- * ```
- */
+ @JvmStatic fun none(): AclDeleteParams = builder().build()
+
+ /** Returns a mutable builder for constructing an instance of [AclDeleteParams]. */
@JvmStatic fun builder() = Builder()
}
@@ -61,7 +59,10 @@ private constructor(
}
/** Acl id */
- fun aclId(aclId: String) = apply { this.aclId = aclId }
+ fun aclId(aclId: String?) = apply { this.aclId = aclId }
+
+ /** Alias for calling [Builder.aclId] with `aclId.orElse(null)`. */
+ fun aclId(aclId: Optional) = aclId(aclId.getOrNull())
fun additionalHeaders(additionalHeaders: Headers) = apply {
this.additionalHeaders.clear()
@@ -187,17 +188,10 @@ private constructor(
* Returns an immutable instance of [AclDeleteParams].
*
* Further updates to this [Builder] will not mutate the returned instance.
- *
- * The following fields are required:
- * ```java
- * .aclId()
- * ```
- *
- * @throws IllegalStateException if any required field is unset.
*/
fun build(): AclDeleteParams =
AclDeleteParams(
- checkRequired("aclId", aclId),
+ aclId,
additionalHeaders.build(),
additionalQueryParams.build(),
additionalBodyProperties.toImmutable(),
@@ -209,7 +203,7 @@ private constructor(
fun _pathParam(index: Int): String =
when (index) {
- 0 -> aclId
+ 0 -> aclId ?: ""
else -> ""
}
@@ -222,10 +216,15 @@ private constructor(
return true
}
- return /* spotless:off */ other is AclDeleteParams && aclId == other.aclId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */
+ return other is AclDeleteParams &&
+ aclId == other.aclId &&
+ additionalHeaders == other.additionalHeaders &&
+ additionalQueryParams == other.additionalQueryParams &&
+ additionalBodyProperties == other.additionalBodyProperties
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(aclId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */
+ override fun hashCode(): Int =
+ Objects.hash(aclId, additionalHeaders, additionalQueryParams, additionalBodyProperties)
override fun toString() =
"AclDeleteParams{aclId=$aclId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}"
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParams.kt
index 05969c71..b8de1f0e 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParams.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclFindAndDeleteParams.kt
@@ -137,8 +137,10 @@ private constructor(
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)
@@ -873,13 +875,30 @@ private constructor(
return true
}
- return /* spotless:off */ other is Body && objectId == other.objectId && objectType == other.objectType && groupId == other.groupId && permission == other.permission && restrictObjectType == other.restrictObjectType && roleId == other.roleId && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Body &&
+ objectId == other.objectId &&
+ objectType == other.objectType &&
+ groupId == other.groupId &&
+ permission == other.permission &&
+ restrictObjectType == other.restrictObjectType &&
+ roleId == other.roleId &&
+ userId == other.userId &&
+ additionalProperties == other.additionalProperties
+ }
+
+ private val hashCode: Int by lazy {
+ Objects.hash(
+ objectId,
+ objectType,
+ groupId,
+ permission,
+ restrictObjectType,
+ roleId,
+ userId,
+ additionalProperties,
+ )
}
- /* spotless:off */
- private val hashCode: Int by lazy { Objects.hash(objectId, objectType, groupId, permission, restrictObjectType, roleId, userId, additionalProperties) }
- /* spotless:on */
-
override fun hashCode(): Int = hashCode
override fun toString() =
@@ -891,10 +910,13 @@ private constructor(
return true
}
- return /* spotless:off */ other is AclFindAndDeleteParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
+ return other is AclFindAndDeleteParams &&
+ body == other.body &&
+ additionalHeaders == other.additionalHeaders &&
+ additionalQueryParams == other.additionalQueryParams
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */
+ override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams)
override fun toString() =
"AclFindAndDeleteParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}"
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt
index fd5ac29d..8938e4ed 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPage.kt
@@ -2,48 +2,42 @@
package com.braintrustdata.api.models
+import com.braintrustdata.api.core.AutoPager
+import com.braintrustdata.api.core.Page
import com.braintrustdata.api.core.checkRequired
import com.braintrustdata.api.services.blocking.AclService
import java.util.Objects
-import java.util.Optional
-import java.util.stream.Stream
-import java.util.stream.StreamSupport
import kotlin.jvm.optionals.getOrNull
-/** @see [AclService.list] */
+/** @see AclService.list */
class AclListPage
private constructor(
private val service: AclService,
private val params: AclListParams,
private val response: AclListPageResponse,
-) {
+) : Page {
/**
* Delegates to [AclListPageResponse], but gracefully handles missing data.
*
- * @see [AclListPageResponse.objects]
+ * @see AclListPageResponse.objects
*/
fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList()
- fun hasNextPage(): Boolean = objects().isNotEmpty()
+ override fun items(): List = objects()
- fun getNextPageParams(): Optional {
- if (!hasNextPage()) {
- return Optional.empty()
- }
+ override fun hasNextPage(): Boolean = items().isNotEmpty()
- return Optional.of(
- if (params.endingBefore().isPresent) {
- params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build()
- } else {
- params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build()
- }
- )
- }
+ fun nextPageParams(): AclListParams =
+ if (params.endingBefore().isPresent) {
+ params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build()
+ } else {
+ params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build()
+ }
- fun getNextPage(): Optional = getNextPageParams().map { service.list(it) }
+ override fun nextPage(): AclListPage = service.list(nextPageParams())
- fun autoPager(): AutoPager = AutoPager(this)
+ fun autoPager(): AutoPager = AutoPager.from(this)
/** The parameters that were used to request this page. */
fun params(): AclListParams = params
@@ -112,34 +106,18 @@ private constructor(
)
}
- class AutoPager(private val firstPage: AclListPage) : Iterable {
-
- override fun iterator(): Iterator = iterator {
- var page = firstPage
- var index = 0
- while (true) {
- while (index < page.objects().size) {
- yield(page.objects()[index++])
- }
- page = page.getNextPage().getOrNull() ?: break
- index = 0
- }
- }
-
- fun stream(): Stream {
- return StreamSupport.stream(spliterator(), false)
- }
- }
-
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}
- return /* spotless:off */ other is AclListPage && service == other.service && params == other.params && response == other.response /* spotless:on */
+ return other is AclListPage &&
+ service == other.service &&
+ params == other.params &&
+ response == other.response
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */
+ override fun hashCode(): Int = Objects.hash(service, params, response)
override fun toString() = "AclListPage{service=$service, params=$params, response=$response}"
}
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt
index 20160da8..def7bff5 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageAsync.kt
@@ -2,52 +2,45 @@
package com.braintrustdata.api.models
+import com.braintrustdata.api.core.AutoPagerAsync
+import com.braintrustdata.api.core.PageAsync
import com.braintrustdata.api.core.checkRequired
import com.braintrustdata.api.services.async.AclServiceAsync
import java.util.Objects
-import java.util.Optional
import java.util.concurrent.CompletableFuture
import java.util.concurrent.Executor
-import java.util.function.Predicate
import kotlin.jvm.optionals.getOrNull
-/** @see [AclServiceAsync.list] */
+/** @see AclServiceAsync.list */
class AclListPageAsync
private constructor(
private val service: AclServiceAsync,
+ private val streamHandlerExecutor: Executor,
private val params: AclListParams,
private val response: AclListPageResponse,
-) {
+) : PageAsync {
/**
* Delegates to [AclListPageResponse], but gracefully handles missing data.
*
- * @see [AclListPageResponse.objects]
+ * @see AclListPageResponse.objects
*/
fun objects(): List = response._objects().getOptional("objects").getOrNull() ?: emptyList()
- fun hasNextPage(): Boolean = objects().isNotEmpty()
+ override fun items(): List = objects()
- fun getNextPageParams(): Optional {
- if (!hasNextPage()) {
- return Optional.empty()
- }
+ override fun hasNextPage(): Boolean = items().isNotEmpty()
- return Optional.of(
- if (params.endingBefore().isPresent) {
- params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build()
- } else {
- params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build()
- }
- )
- }
+ fun nextPageParams(): AclListParams =
+ if (params.endingBefore().isPresent) {
+ params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build()
+ } else {
+ params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build()
+ }
- fun getNextPage(): CompletableFuture> =
- getNextPageParams()
- .map { service.list(it).thenApply { Optional.of(it) } }
- .orElseGet { CompletableFuture.completedFuture(Optional.empty()) }
+ override fun nextPage(): CompletableFuture = service.list(nextPageParams())
- fun autoPager(): AutoPager = AutoPager(this)
+ fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor)
/** The parameters that were used to request this page. */
fun params(): AclListParams = params
@@ -65,6 +58,7 @@ private constructor(
* The following fields are required:
* ```java
* .service()
+ * .streamHandlerExecutor()
* .params()
* .response()
* ```
@@ -76,18 +70,24 @@ private constructor(
class Builder internal constructor() {
private var service: AclServiceAsync? = null
+ private var streamHandlerExecutor: Executor? = null
private var params: AclListParams? = null
private var response: AclListPageResponse? = null
@JvmSynthetic
internal fun from(aclListPageAsync: AclListPageAsync) = apply {
service = aclListPageAsync.service
+ streamHandlerExecutor = aclListPageAsync.streamHandlerExecutor
params = aclListPageAsync.params
response = aclListPageAsync.response
}
fun service(service: AclServiceAsync) = apply { this.service = service }
+ fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply {
+ this.streamHandlerExecutor = streamHandlerExecutor
+ }
+
/** The parameters that were used to request this page. */
fun params(params: AclListParams) = apply { this.params = params }
@@ -102,6 +102,7 @@ private constructor(
* The following fields are required:
* ```java
* .service()
+ * .streamHandlerExecutor()
* .params()
* .response()
* ```
@@ -111,47 +112,26 @@ private constructor(
fun build(): AclListPageAsync =
AclListPageAsync(
checkRequired("service", service),
+ checkRequired("streamHandlerExecutor", streamHandlerExecutor),
checkRequired("params", params),
checkRequired("response", response),
)
}
- class AutoPager(private val firstPage: AclListPageAsync) {
-
- fun forEach(action: Predicate, executor: Executor): CompletableFuture {
- fun CompletableFuture>.forEach(
- action: (Acl) -> Boolean,
- executor: Executor,
- ): CompletableFuture =
- thenComposeAsync(
- { page ->
- page
- .filter { it.objects().all(action) }
- .map { it.getNextPage().forEach(action, executor) }
- .orElseGet { CompletableFuture.completedFuture(null) }
- },
- executor,
- )
- return CompletableFuture.completedFuture(Optional.of(firstPage))
- .forEach(action::test, executor)
- }
-
- fun toList(executor: Executor): CompletableFuture> {
- val values = mutableListOf()
- return forEach(values::add, executor).thenApply { values }
- }
- }
-
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}
- return /* spotless:off */ other is AclListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */
+ return other is AclListPageAsync &&
+ service == other.service &&
+ streamHandlerExecutor == other.streamHandlerExecutor &&
+ params == other.params &&
+ response == other.response
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */
+ override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response)
override fun toString() =
- "AclListPageAsync{service=$service, params=$params, response=$response}"
+ "AclListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}"
}
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageResponse.kt
index 63b51fd2..46de9379 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageResponse.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListPageResponse.kt
@@ -178,12 +178,12 @@ private constructor(
return true
}
- return /* spotless:off */ other is AclListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is AclListPageResponse &&
+ objects == other.objects &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListParams.kt
index 238ae30f..d0fefc9b 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListParams.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclListParams.kt
@@ -7,6 +7,7 @@ import com.braintrustdata.api.core.checkRequired
import com.braintrustdata.api.core.getOrThrow
import com.braintrustdata.api.core.http.Headers
import com.braintrustdata.api.core.http.QueryParams
+import com.braintrustdata.api.core.toImmutable
import java.util.Objects
import java.util.Optional
import kotlin.jvm.optionals.getOrNull
@@ -60,8 +61,10 @@ private constructor(
*/
fun startingAfter(): Optional = Optional.ofNullable(startingAfter)
+ /** 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)
@@ -346,10 +349,10 @@ private constructor(
return true
}
- return /* spotless:off */ other is Ids && string == other.string && strings == other.strings /* spotless:on */
+ return other is Ids && string == other.string && strings == other.strings
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */
+ override fun hashCode(): Int = Objects.hash(string, strings)
override fun toString(): String =
when {
@@ -362,7 +365,7 @@ private constructor(
@JvmStatic fun ofString(string: String) = Ids(string = string)
- @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings)
+ @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings.toImmutable())
}
/** An interface that defines how to map each variant of [Ids] to a value of type [T]. */
@@ -379,10 +382,28 @@ private constructor(
return true
}
- return /* spotless:off */ other is AclListParams && objectId == other.objectId && objectType == other.objectType && endingBefore == other.endingBefore && ids == other.ids && limit == other.limit && startingAfter == other.startingAfter && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
+ return other is AclListParams &&
+ objectId == other.objectId &&
+ objectType == other.objectType &&
+ endingBefore == other.endingBefore &&
+ ids == other.ids &&
+ limit == other.limit &&
+ startingAfter == other.startingAfter &&
+ additionalHeaders == other.additionalHeaders &&
+ additionalQueryParams == other.additionalQueryParams
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(objectId, objectType, endingBefore, ids, limit, startingAfter, additionalHeaders, additionalQueryParams) /* spotless:on */
+ override fun hashCode(): Int =
+ Objects.hash(
+ objectId,
+ objectType,
+ endingBefore,
+ ids,
+ limit,
+ startingAfter,
+ additionalHeaders,
+ additionalQueryParams,
+ )
override fun toString() =
"AclListParams{objectId=$objectId, objectType=$objectType, endingBefore=$endingBefore, ids=$ids, limit=$limit, startingAfter=$startingAfter, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}"
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclObjectType.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclObjectType.kt
index 727accde..d70f1270 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclObjectType.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclObjectType.kt
@@ -179,7 +179,7 @@ class AclObjectType @JsonCreator private constructor(private val value: JsonFiel
return true
}
- return /* spotless:off */ other is AclObjectType && value == other.value /* spotless:on */
+ return other is AclObjectType && value == other.value
}
override fun hashCode() = value.hashCode()
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclRetrieveParams.kt
index ab43fccb..553c84c3 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclRetrieveParams.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AclRetrieveParams.kt
@@ -3,38 +3,36 @@
package com.braintrustdata.api.models
import com.braintrustdata.api.core.Params
-import com.braintrustdata.api.core.checkRequired
import com.braintrustdata.api.core.http.Headers
import com.braintrustdata.api.core.http.QueryParams
import java.util.Objects
+import java.util.Optional
+import kotlin.jvm.optionals.getOrNull
/** Get an acl object by its id */
class AclRetrieveParams
private constructor(
- private val aclId: String,
+ private val aclId: String?,
private val additionalHeaders: Headers,
private val additionalQueryParams: QueryParams,
) : Params {
/** Acl id */
- fun aclId(): String = aclId
+ fun aclId(): Optional = Optional.ofNullable(aclId)
+ /** 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 [AclRetrieveParams].
- *
- * The following fields are required:
- * ```java
- * .aclId()
- * ```
- */
+ @JvmStatic fun none(): AclRetrieveParams = builder().build()
+
+ /** Returns a mutable builder for constructing an instance of [AclRetrieveParams]. */
@JvmStatic fun builder() = Builder()
}
@@ -53,7 +51,10 @@ private constructor(
}
/** Acl id */
- fun aclId(aclId: String) = apply { this.aclId = aclId }
+ fun aclId(aclId: String?) = apply { this.aclId = aclId }
+
+ /** Alias for calling [Builder.aclId] with `aclId.orElse(null)`. */
+ fun aclId(aclId: Optional) = aclId(aclId.getOrNull())
fun additionalHeaders(additionalHeaders: Headers) = apply {
this.additionalHeaders.clear()
@@ -157,25 +158,14 @@ private constructor(
* Returns an immutable instance of [AclRetrieveParams].
*
* Further updates to this [Builder] will not mutate the returned instance.
- *
- * The following fields are required:
- * ```java
- * .aclId()
- * ```
- *
- * @throws IllegalStateException if any required field is unset.
*/
fun build(): AclRetrieveParams =
- AclRetrieveParams(
- checkRequired("aclId", aclId),
- additionalHeaders.build(),
- additionalQueryParams.build(),
- )
+ AclRetrieveParams(aclId, additionalHeaders.build(), additionalQueryParams.build())
}
fun _pathParam(index: Int): String =
when (index) {
- 0 -> aclId
+ 0 -> aclId ?: ""
else -> ""
}
@@ -188,10 +178,13 @@ private constructor(
return true
}
- return /* spotless:off */ other is AclRetrieveParams && aclId == other.aclId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
+ return other is AclRetrieveParams &&
+ aclId == other.aclId &&
+ additionalHeaders == other.additionalHeaders &&
+ additionalQueryParams == other.additionalQueryParams
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(aclId, additionalHeaders, additionalQueryParams) /* spotless:on */
+ override fun hashCode(): Int = Objects.hash(aclId, additionalHeaders, additionalQueryParams)
override fun toString() =
"AclRetrieveParams{aclId=$aclId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}"
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt
index 6a4e98f4..d4d87173 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretCreateParams.kt
@@ -108,8 +108,10 @@ private constructor(
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)
@@ -672,12 +674,18 @@ private constructor(
return true
}
- return /* spotless:off */ other is Body && name == other.name && metadata == other.metadata && orgName == other.orgName && secret == other.secret && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Body &&
+ name == other.name &&
+ metadata == other.metadata &&
+ orgName == other.orgName &&
+ secret == other.secret &&
+ type == other.type &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
- private val hashCode: Int by lazy { Objects.hash(name, metadata, orgName, secret, type, additionalProperties) }
- /* spotless:on */
+ private val hashCode: Int by lazy {
+ Objects.hash(name, metadata, orgName, secret, type, additionalProperties)
+ }
override fun hashCode(): Int = hashCode
@@ -774,12 +782,10 @@ private constructor(
return true
}
- return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Metadata && additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
@@ -791,10 +797,13 @@ private constructor(
return true
}
- return /* spotless:off */ other is AiSecretCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
+ return other is AiSecretCreateParams &&
+ body == other.body &&
+ additionalHeaders == other.additionalHeaders &&
+ additionalQueryParams == other.additionalQueryParams
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */
+ override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams)
override fun toString() =
"AiSecretCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}"
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretDeleteParams.kt
index c0e7a074..61a67496 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretDeleteParams.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretDeleteParams.kt
@@ -4,43 +4,41 @@ package com.braintrustdata.api.models
import com.braintrustdata.api.core.JsonValue
import com.braintrustdata.api.core.Params
-import com.braintrustdata.api.core.checkRequired
import com.braintrustdata.api.core.http.Headers
import com.braintrustdata.api.core.http.QueryParams
import com.braintrustdata.api.core.toImmutable
import java.util.Objects
import java.util.Optional
+import kotlin.jvm.optionals.getOrNull
/** Delete an ai_secret object by its id */
class AiSecretDeleteParams
private constructor(
- private val aiSecretId: String,
+ private val aiSecretId: String?,
private val additionalHeaders: Headers,
private val additionalQueryParams: QueryParams,
private val additionalBodyProperties: Map,
) : Params {
/** AiSecret id */
- fun aiSecretId(): String = aiSecretId
+ fun aiSecretId(): Optional = Optional.ofNullable(aiSecretId)
+ /** Additional body properties to send with the request. */
fun _additionalBodyProperties(): Map = additionalBodyProperties
+ /** Additional headers to send with the request. */
fun _additionalHeaders(): Headers = additionalHeaders
+ /** Additional query param to send with the request. */
fun _additionalQueryParams(): QueryParams = additionalQueryParams
fun toBuilder() = Builder().from(this)
companion object {
- /**
- * Returns a mutable builder for constructing an instance of [AiSecretDeleteParams].
- *
- * The following fields are required:
- * ```java
- * .aiSecretId()
- * ```
- */
+ @JvmStatic fun none(): AiSecretDeleteParams = builder().build()
+
+ /** Returns a mutable builder for constructing an instance of [AiSecretDeleteParams]. */
@JvmStatic fun builder() = Builder()
}
@@ -61,7 +59,10 @@ private constructor(
}
/** AiSecret id */
- fun aiSecretId(aiSecretId: String) = apply { this.aiSecretId = aiSecretId }
+ fun aiSecretId(aiSecretId: String?) = apply { this.aiSecretId = aiSecretId }
+
+ /** Alias for calling [Builder.aiSecretId] with `aiSecretId.orElse(null)`. */
+ fun aiSecretId(aiSecretId: Optional) = aiSecretId(aiSecretId.getOrNull())
fun additionalHeaders(additionalHeaders: Headers) = apply {
this.additionalHeaders.clear()
@@ -187,17 +188,10 @@ private constructor(
* Returns an immutable instance of [AiSecretDeleteParams].
*
* Further updates to this [Builder] will not mutate the returned instance.
- *
- * The following fields are required:
- * ```java
- * .aiSecretId()
- * ```
- *
- * @throws IllegalStateException if any required field is unset.
*/
fun build(): AiSecretDeleteParams =
AiSecretDeleteParams(
- checkRequired("aiSecretId", aiSecretId),
+ aiSecretId,
additionalHeaders.build(),
additionalQueryParams.build(),
additionalBodyProperties.toImmutable(),
@@ -209,7 +203,7 @@ private constructor(
fun _pathParam(index: Int): String =
when (index) {
- 0 -> aiSecretId
+ 0 -> aiSecretId ?: ""
else -> ""
}
@@ -222,10 +216,15 @@ private constructor(
return true
}
- return /* spotless:off */ other is AiSecretDeleteParams && aiSecretId == other.aiSecretId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */
+ return other is AiSecretDeleteParams &&
+ aiSecretId == other.aiSecretId &&
+ additionalHeaders == other.additionalHeaders &&
+ additionalQueryParams == other.additionalQueryParams &&
+ additionalBodyProperties == other.additionalBodyProperties
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(aiSecretId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */
+ override fun hashCode(): Int =
+ Objects.hash(aiSecretId, additionalHeaders, additionalQueryParams, additionalBodyProperties)
override fun toString() =
"AiSecretDeleteParams{aiSecretId=$aiSecretId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}"
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParams.kt
index 83d28e3b..a2e21a00 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParams.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretFindAndDeleteParams.kt
@@ -62,8 +62,10 @@ private constructor(
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)
@@ -462,12 +464,13 @@ private constructor(
return true
}
- return /* spotless:off */ other is Body && name == other.name && orgName == other.orgName && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Body &&
+ name == other.name &&
+ orgName == other.orgName &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(name, orgName, additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
@@ -480,10 +483,13 @@ private constructor(
return true
}
- return /* spotless:off */ other is AiSecretFindAndDeleteParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
+ return other is AiSecretFindAndDeleteParams &&
+ body == other.body &&
+ additionalHeaders == other.additionalHeaders &&
+ additionalQueryParams == other.additionalQueryParams
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */
+ override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams)
override fun toString() =
"AiSecretFindAndDeleteParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}"
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt
index 021f2341..b3de4d4f 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPage.kt
@@ -2,49 +2,43 @@
package com.braintrustdata.api.models
+import com.braintrustdata.api.core.AutoPager
+import com.braintrustdata.api.core.Page
import com.braintrustdata.api.core.checkRequired
import com.braintrustdata.api.services.blocking.AiSecretService
import java.util.Objects
-import java.util.Optional
-import java.util.stream.Stream
-import java.util.stream.StreamSupport
import kotlin.jvm.optionals.getOrNull
-/** @see [AiSecretService.list] */
+/** @see AiSecretService.list */
class AiSecretListPage
private constructor(
private val service: AiSecretService,
private val params: AiSecretListParams,
private val response: AiSecretListPageResponse,
-) {
+) : Page {
/**
* Delegates to [AiSecretListPageResponse], but gracefully handles missing data.
*
- * @see [AiSecretListPageResponse.objects]
+ * @see AiSecretListPageResponse.objects
*/
fun objects(): List =
response._objects().getOptional("objects").getOrNull() ?: emptyList()
- fun hasNextPage(): Boolean = objects().isNotEmpty()
+ override fun items(): List = objects()
- fun getNextPageParams(): Optional {
- if (!hasNextPage()) {
- return Optional.empty()
- }
+ override fun hasNextPage(): Boolean = items().isNotEmpty()
- return Optional.of(
- if (params.endingBefore().isPresent) {
- params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build()
- } else {
- params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build()
- }
- )
- }
+ fun nextPageParams(): AiSecretListParams =
+ if (params.endingBefore().isPresent) {
+ params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build()
+ } else {
+ params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build()
+ }
- fun getNextPage(): Optional = getNextPageParams().map { service.list(it) }
+ override fun nextPage(): AiSecretListPage = service.list(nextPageParams())
- fun autoPager(): AutoPager = AutoPager(this)
+ fun autoPager(): AutoPager = AutoPager.from(this)
/** The parameters that were used to request this page. */
fun params(): AiSecretListParams = params
@@ -113,34 +107,18 @@ private constructor(
)
}
- class AutoPager(private val firstPage: AiSecretListPage) : Iterable {
-
- override fun iterator(): Iterator = iterator {
- var page = firstPage
- var index = 0
- while (true) {
- while (index < page.objects().size) {
- yield(page.objects()[index++])
- }
- page = page.getNextPage().getOrNull() ?: break
- index = 0
- }
- }
-
- fun stream(): Stream {
- return StreamSupport.stream(spliterator(), false)
- }
- }
-
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}
- return /* spotless:off */ other is AiSecretListPage && service == other.service && params == other.params && response == other.response /* spotless:on */
+ return other is AiSecretListPage &&
+ service == other.service &&
+ params == other.params &&
+ response == other.response
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */
+ override fun hashCode(): Int = Objects.hash(service, params, response)
override fun toString() =
"AiSecretListPage{service=$service, params=$params, response=$response}"
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt
index 597dd9cd..535d9386 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageAsync.kt
@@ -2,53 +2,47 @@
package com.braintrustdata.api.models
+import com.braintrustdata.api.core.AutoPagerAsync
+import com.braintrustdata.api.core.PageAsync
import com.braintrustdata.api.core.checkRequired
import com.braintrustdata.api.services.async.AiSecretServiceAsync
import java.util.Objects
-import java.util.Optional
import java.util.concurrent.CompletableFuture
import java.util.concurrent.Executor
-import java.util.function.Predicate
import kotlin.jvm.optionals.getOrNull
-/** @see [AiSecretServiceAsync.list] */
+/** @see AiSecretServiceAsync.list */
class AiSecretListPageAsync
private constructor(
private val service: AiSecretServiceAsync,
+ private val streamHandlerExecutor: Executor,
private val params: AiSecretListParams,
private val response: AiSecretListPageResponse,
-) {
+) : PageAsync {
/**
* Delegates to [AiSecretListPageResponse], but gracefully handles missing data.
*
- * @see [AiSecretListPageResponse.objects]
+ * @see AiSecretListPageResponse.objects
*/
fun objects(): List =
response._objects().getOptional("objects").getOrNull() ?: emptyList()
- fun hasNextPage(): Boolean = objects().isNotEmpty()
+ override fun items(): List = objects()
- fun getNextPageParams(): Optional {
- if (!hasNextPage()) {
- return Optional.empty()
- }
+ override fun hasNextPage(): Boolean = items().isNotEmpty()
- return Optional.of(
- if (params.endingBefore().isPresent) {
- params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build()
- } else {
- params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build()
- }
- )
- }
+ fun nextPageParams(): AiSecretListParams =
+ if (params.endingBefore().isPresent) {
+ params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build()
+ } else {
+ params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build()
+ }
- fun getNextPage(): CompletableFuture> =
- getNextPageParams()
- .map { service.list(it).thenApply { Optional.of(it) } }
- .orElseGet { CompletableFuture.completedFuture(Optional.empty()) }
+ override fun nextPage(): CompletableFuture =
+ service.list(nextPageParams())
- fun autoPager(): AutoPager = AutoPager(this)
+ fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor)
/** The parameters that were used to request this page. */
fun params(): AiSecretListParams = params
@@ -66,6 +60,7 @@ private constructor(
* The following fields are required:
* ```java
* .service()
+ * .streamHandlerExecutor()
* .params()
* .response()
* ```
@@ -77,18 +72,24 @@ private constructor(
class Builder internal constructor() {
private var service: AiSecretServiceAsync? = null
+ private var streamHandlerExecutor: Executor? = null
private var params: AiSecretListParams? = null
private var response: AiSecretListPageResponse? = null
@JvmSynthetic
internal fun from(aiSecretListPageAsync: AiSecretListPageAsync) = apply {
service = aiSecretListPageAsync.service
+ streamHandlerExecutor = aiSecretListPageAsync.streamHandlerExecutor
params = aiSecretListPageAsync.params
response = aiSecretListPageAsync.response
}
fun service(service: AiSecretServiceAsync) = apply { this.service = service }
+ fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply {
+ this.streamHandlerExecutor = streamHandlerExecutor
+ }
+
/** The parameters that were used to request this page. */
fun params(params: AiSecretListParams) = apply { this.params = params }
@@ -103,6 +104,7 @@ private constructor(
* The following fields are required:
* ```java
* .service()
+ * .streamHandlerExecutor()
* .params()
* .response()
* ```
@@ -112,47 +114,26 @@ private constructor(
fun build(): AiSecretListPageAsync =
AiSecretListPageAsync(
checkRequired("service", service),
+ checkRequired("streamHandlerExecutor", streamHandlerExecutor),
checkRequired("params", params),
checkRequired("response", response),
)
}
- class AutoPager(private val firstPage: AiSecretListPageAsync) {
-
- fun forEach(action: Predicate, executor: Executor): CompletableFuture {
- fun CompletableFuture>.forEach(
- action: (AISecret) -> Boolean,
- executor: Executor,
- ): CompletableFuture =
- thenComposeAsync(
- { page ->
- page
- .filter { it.objects().all(action) }
- .map { it.getNextPage().forEach(action, executor) }
- .orElseGet { CompletableFuture.completedFuture(null) }
- },
- executor,
- )
- return CompletableFuture.completedFuture(Optional.of(firstPage))
- .forEach(action::test, executor)
- }
-
- fun toList(executor: Executor): CompletableFuture> {
- val values = mutableListOf()
- return forEach(values::add, executor).thenApply { values }
- }
- }
-
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}
- return /* spotless:off */ other is AiSecretListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */
+ return other is AiSecretListPageAsync &&
+ service == other.service &&
+ streamHandlerExecutor == other.streamHandlerExecutor &&
+ params == other.params &&
+ response == other.response
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */
+ override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response)
override fun toString() =
- "AiSecretListPageAsync{service=$service, params=$params, response=$response}"
+ "AiSecretListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}"
}
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageResponse.kt
index 57a8dde7..3a3aea43 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageResponse.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListPageResponse.kt
@@ -180,12 +180,12 @@ private constructor(
return true
}
- return /* spotless:off */ other is AiSecretListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is AiSecretListPageResponse &&
+ objects == other.objects &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListParams.kt
index dd7ef4bd..d57cd54f 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListParams.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretListParams.kt
@@ -6,6 +6,7 @@ import com.braintrustdata.api.core.Params
import com.braintrustdata.api.core.getOrThrow
import com.braintrustdata.api.core.http.Headers
import com.braintrustdata.api.core.http.QueryParams
+import com.braintrustdata.api.core.toImmutable
import java.util.Objects
import java.util.Optional
import kotlin.jvm.optionals.getOrNull
@@ -62,8 +63,10 @@ private constructor(
*/
fun startingAfter(): Optional = Optional.ofNullable(startingAfter)
+ /** 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)
@@ -363,10 +366,10 @@ private constructor(
return true
}
- return /* spotless:off */ other is AiSecretType && string == other.string && strings == other.strings /* spotless:on */
+ return other is AiSecretType && string == other.string && strings == other.strings
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */
+ override fun hashCode(): Int = Objects.hash(string, strings)
override fun toString(): String =
when {
@@ -379,7 +382,8 @@ private constructor(
@JvmStatic fun ofString(string: String) = AiSecretType(string = string)
- @JvmStatic fun ofStrings(strings: List) = AiSecretType(strings = strings)
+ @JvmStatic
+ fun ofStrings(strings: List) = AiSecretType(strings = strings.toImmutable())
}
/**
@@ -428,10 +432,10 @@ private constructor(
return true
}
- return /* spotless:off */ other is Ids && string == other.string && strings == other.strings /* spotless:on */
+ return other is Ids && string == other.string && strings == other.strings
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */
+ override fun hashCode(): Int = Objects.hash(string, strings)
override fun toString(): String =
when {
@@ -444,7 +448,7 @@ private constructor(
@JvmStatic fun ofString(string: String) = Ids(string = string)
- @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings)
+ @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings.toImmutable())
}
/** An interface that defines how to map each variant of [Ids] to a value of type [T]. */
@@ -461,10 +465,30 @@ private constructor(
return true
}
- return /* spotless:off */ other is AiSecretListParams && aiSecretName == other.aiSecretName && aiSecretType == other.aiSecretType && endingBefore == other.endingBefore && ids == other.ids && limit == other.limit && orgName == other.orgName && startingAfter == other.startingAfter && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
+ return other is AiSecretListParams &&
+ aiSecretName == other.aiSecretName &&
+ aiSecretType == other.aiSecretType &&
+ endingBefore == other.endingBefore &&
+ ids == other.ids &&
+ limit == other.limit &&
+ orgName == other.orgName &&
+ startingAfter == other.startingAfter &&
+ additionalHeaders == other.additionalHeaders &&
+ additionalQueryParams == other.additionalQueryParams
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(aiSecretName, aiSecretType, endingBefore, ids, limit, orgName, startingAfter, additionalHeaders, additionalQueryParams) /* spotless:on */
+ override fun hashCode(): Int =
+ Objects.hash(
+ aiSecretName,
+ aiSecretType,
+ endingBefore,
+ ids,
+ limit,
+ orgName,
+ startingAfter,
+ additionalHeaders,
+ additionalQueryParams,
+ )
override fun toString() =
"AiSecretListParams{aiSecretName=$aiSecretName, aiSecretType=$aiSecretType, endingBefore=$endingBefore, ids=$ids, limit=$limit, orgName=$orgName, startingAfter=$startingAfter, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}"
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt
index af588655..b75d84d6 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretReplaceParams.kt
@@ -108,8 +108,10 @@ private constructor(
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)
@@ -672,12 +674,18 @@ private constructor(
return true
}
- return /* spotless:off */ other is Body && name == other.name && metadata == other.metadata && orgName == other.orgName && secret == other.secret && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Body &&
+ name == other.name &&
+ metadata == other.metadata &&
+ orgName == other.orgName &&
+ secret == other.secret &&
+ type == other.type &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
- private val hashCode: Int by lazy { Objects.hash(name, metadata, orgName, secret, type, additionalProperties) }
- /* spotless:on */
+ private val hashCode: Int by lazy {
+ Objects.hash(name, metadata, orgName, secret, type, additionalProperties)
+ }
override fun hashCode(): Int = hashCode
@@ -774,12 +782,10 @@ private constructor(
return true
}
- return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Metadata && additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
@@ -791,10 +797,13 @@ private constructor(
return true
}
- return /* spotless:off */ other is AiSecretReplaceParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
+ return other is AiSecretReplaceParams &&
+ body == other.body &&
+ additionalHeaders == other.additionalHeaders &&
+ additionalQueryParams == other.additionalQueryParams
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */
+ override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams)
override fun toString() =
"AiSecretReplaceParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}"
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretRetrieveParams.kt
index 551f4d43..c52011db 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretRetrieveParams.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretRetrieveParams.kt
@@ -3,38 +3,36 @@
package com.braintrustdata.api.models
import com.braintrustdata.api.core.Params
-import com.braintrustdata.api.core.checkRequired
import com.braintrustdata.api.core.http.Headers
import com.braintrustdata.api.core.http.QueryParams
import java.util.Objects
+import java.util.Optional
+import kotlin.jvm.optionals.getOrNull
/** Get an ai_secret object by its id */
class AiSecretRetrieveParams
private constructor(
- private val aiSecretId: String,
+ private val aiSecretId: String?,
private val additionalHeaders: Headers,
private val additionalQueryParams: QueryParams,
) : Params {
/** AiSecret id */
- fun aiSecretId(): String = aiSecretId
+ fun aiSecretId(): Optional = Optional.ofNullable(aiSecretId)
+ /** 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 [AiSecretRetrieveParams].
- *
- * The following fields are required:
- * ```java
- * .aiSecretId()
- * ```
- */
+ @JvmStatic fun none(): AiSecretRetrieveParams = builder().build()
+
+ /** Returns a mutable builder for constructing an instance of [AiSecretRetrieveParams]. */
@JvmStatic fun builder() = Builder()
}
@@ -53,7 +51,10 @@ private constructor(
}
/** AiSecret id */
- fun aiSecretId(aiSecretId: String) = apply { this.aiSecretId = aiSecretId }
+ fun aiSecretId(aiSecretId: String?) = apply { this.aiSecretId = aiSecretId }
+
+ /** Alias for calling [Builder.aiSecretId] with `aiSecretId.orElse(null)`. */
+ fun aiSecretId(aiSecretId: Optional) = aiSecretId(aiSecretId.getOrNull())
fun additionalHeaders(additionalHeaders: Headers) = apply {
this.additionalHeaders.clear()
@@ -157,17 +158,10 @@ private constructor(
* Returns an immutable instance of [AiSecretRetrieveParams].
*
* Further updates to this [Builder] will not mutate the returned instance.
- *
- * The following fields are required:
- * ```java
- * .aiSecretId()
- * ```
- *
- * @throws IllegalStateException if any required field is unset.
*/
fun build(): AiSecretRetrieveParams =
AiSecretRetrieveParams(
- checkRequired("aiSecretId", aiSecretId),
+ aiSecretId,
additionalHeaders.build(),
additionalQueryParams.build(),
)
@@ -175,7 +169,7 @@ private constructor(
fun _pathParam(index: Int): String =
when (index) {
- 0 -> aiSecretId
+ 0 -> aiSecretId ?: ""
else -> ""
}
@@ -188,10 +182,14 @@ private constructor(
return true
}
- return /* spotless:off */ other is AiSecretRetrieveParams && aiSecretId == other.aiSecretId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
+ return other is AiSecretRetrieveParams &&
+ aiSecretId == other.aiSecretId &&
+ additionalHeaders == other.additionalHeaders &&
+ additionalQueryParams == other.additionalQueryParams
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(aiSecretId, additionalHeaders, additionalQueryParams) /* spotless:on */
+ override fun hashCode(): Int =
+ Objects.hash(aiSecretId, additionalHeaders, additionalQueryParams)
override fun toString() =
"AiSecretRetrieveParams{aiSecretId=$aiSecretId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}"
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt
index 4db720cf..b0905fb7 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/AiSecretUpdateParams.kt
@@ -7,7 +7,6 @@ import com.braintrustdata.api.core.JsonField
import com.braintrustdata.api.core.JsonMissing
import com.braintrustdata.api.core.JsonValue
import com.braintrustdata.api.core.Params
-import com.braintrustdata.api.core.checkRequired
import com.braintrustdata.api.core.http.Headers
import com.braintrustdata.api.core.http.QueryParams
import com.braintrustdata.api.core.toImmutable
@@ -28,14 +27,14 @@ import kotlin.jvm.optionals.getOrNull
*/
class AiSecretUpdateParams
private constructor(
- private val aiSecretId: String,
+ private val aiSecretId: String?,
private val body: Body,
private val additionalHeaders: Headers,
private val additionalQueryParams: QueryParams,
) : Params {
/** AiSecret id */
- fun aiSecretId(): String = aiSecretId
+ fun aiSecretId(): Optional = Optional.ofNullable(aiSecretId)
/**
* @throws BraintrustInvalidDataException if the JSON field has an unexpected type (e.g. if the
@@ -93,22 +92,19 @@ private constructor(
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 [AiSecretUpdateParams].
- *
- * The following fields are required:
- * ```java
- * .aiSecretId()
- * ```
- */
+ @JvmStatic fun none(): AiSecretUpdateParams = builder().build()
+
+ /** Returns a mutable builder for constructing an instance of [AiSecretUpdateParams]. */
@JvmStatic fun builder() = Builder()
}
@@ -129,7 +125,10 @@ private constructor(
}
/** AiSecret id */
- fun aiSecretId(aiSecretId: String) = apply { this.aiSecretId = aiSecretId }
+ fun aiSecretId(aiSecretId: String?) = apply { this.aiSecretId = aiSecretId }
+
+ /** Alias for calling [Builder.aiSecretId] with `aiSecretId.orElse(null)`. */
+ fun aiSecretId(aiSecretId: Optional) = aiSecretId(aiSecretId.getOrNull())
/**
* Sets the entire request body.
@@ -318,17 +317,10 @@ private constructor(
* Returns an immutable instance of [AiSecretUpdateParams].
*
* Further updates to this [Builder] will not mutate the returned instance.
- *
- * The following fields are required:
- * ```java
- * .aiSecretId()
- * ```
- *
- * @throws IllegalStateException if any required field is unset.
*/
fun build(): AiSecretUpdateParams =
AiSecretUpdateParams(
- checkRequired("aiSecretId", aiSecretId),
+ aiSecretId,
body.build(),
additionalHeaders.build(),
additionalQueryParams.build(),
@@ -339,7 +331,7 @@ private constructor(
fun _pathParam(index: Int): String =
when (index) {
- 0 -> aiSecretId
+ 0 -> aiSecretId ?: ""
else -> ""
}
@@ -581,12 +573,17 @@ private constructor(
return true
}
- return /* spotless:off */ other is Body && metadata == other.metadata && name == other.name && secret == other.secret && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Body &&
+ metadata == other.metadata &&
+ name == other.name &&
+ secret == other.secret &&
+ type == other.type &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
- private val hashCode: Int by lazy { Objects.hash(metadata, name, secret, type, additionalProperties) }
- /* spotless:on */
+ private val hashCode: Int by lazy {
+ Objects.hash(metadata, name, secret, type, additionalProperties)
+ }
override fun hashCode(): Int = hashCode
@@ -683,12 +680,10 @@ private constructor(
return true
}
- return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Metadata && additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
@@ -700,10 +695,15 @@ private constructor(
return true
}
- return /* spotless:off */ other is AiSecretUpdateParams && aiSecretId == other.aiSecretId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
+ return other is AiSecretUpdateParams &&
+ aiSecretId == other.aiSecretId &&
+ body == other.body &&
+ additionalHeaders == other.additionalHeaders &&
+ additionalQueryParams == other.additionalQueryParams
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(aiSecretId, body, additionalHeaders, additionalQueryParams) /* spotless:on */
+ override fun hashCode(): Int =
+ Objects.hash(aiSecretId, body, additionalHeaders, additionalQueryParams)
override fun toString() =
"AiSecretUpdateParams{aiSecretId=$aiSecretId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}"
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKey.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKey.kt
index 17e11b99..9830637e 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKey.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKey.kt
@@ -346,12 +346,19 @@ private constructor(
return true
}
- return /* spotless:off */ other is ApiKey && id == other.id && name == other.name && previewName == other.previewName && created == other.created && orgId == other.orgId && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is ApiKey &&
+ id == other.id &&
+ name == other.name &&
+ previewName == other.previewName &&
+ created == other.created &&
+ orgId == other.orgId &&
+ userId == other.userId &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
- private val hashCode: Int by lazy { Objects.hash(id, name, previewName, created, orgId, userId, additionalProperties) }
- /* spotless:on */
+ private val hashCode: Int by lazy {
+ Objects.hash(id, name, previewName, created, orgId, userId, additionalProperties)
+ }
override fun hashCode(): Int = hashCode
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyCreateParams.kt
index 236d29be..21e8dec6 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyCreateParams.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyCreateParams.kt
@@ -65,8 +65,10 @@ private constructor(
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)
@@ -465,12 +467,13 @@ private constructor(
return true
}
- return /* spotless:off */ other is Body && name == other.name && orgName == other.orgName && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Body &&
+ name == other.name &&
+ orgName == other.orgName &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(name, orgName, additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
@@ -483,10 +486,13 @@ private constructor(
return true
}
- return /* spotless:off */ other is ApiKeyCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
+ return other is ApiKeyCreateParams &&
+ body == other.body &&
+ additionalHeaders == other.additionalHeaders &&
+ additionalQueryParams == other.additionalQueryParams
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */
+ override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams)
override fun toString() =
"ApiKeyCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}"
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParams.kt
index 908060c2..f3add49a 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParams.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyDeleteParams.kt
@@ -4,43 +4,41 @@ package com.braintrustdata.api.models
import com.braintrustdata.api.core.JsonValue
import com.braintrustdata.api.core.Params
-import com.braintrustdata.api.core.checkRequired
import com.braintrustdata.api.core.http.Headers
import com.braintrustdata.api.core.http.QueryParams
import com.braintrustdata.api.core.toImmutable
import java.util.Objects
import java.util.Optional
+import kotlin.jvm.optionals.getOrNull
/** Delete an api_key object by its id */
class ApiKeyDeleteParams
private constructor(
- private val apiKeyId: String,
+ private val apiKeyId: String?,
private val additionalHeaders: Headers,
private val additionalQueryParams: QueryParams,
private val additionalBodyProperties: Map,
) : Params {
/** ApiKey id */
- fun apiKeyId(): String = apiKeyId
+ fun apiKeyId(): Optional = Optional.ofNullable(apiKeyId)
+ /** Additional body properties to send with the request. */
fun _additionalBodyProperties(): Map = additionalBodyProperties
+ /** Additional headers to send with the request. */
fun _additionalHeaders(): Headers = additionalHeaders
+ /** Additional query param to send with the request. */
fun _additionalQueryParams(): QueryParams = additionalQueryParams
fun toBuilder() = Builder().from(this)
companion object {
- /**
- * Returns a mutable builder for constructing an instance of [ApiKeyDeleteParams].
- *
- * The following fields are required:
- * ```java
- * .apiKeyId()
- * ```
- */
+ @JvmStatic fun none(): ApiKeyDeleteParams = builder().build()
+
+ /** Returns a mutable builder for constructing an instance of [ApiKeyDeleteParams]. */
@JvmStatic fun builder() = Builder()
}
@@ -61,7 +59,10 @@ private constructor(
}
/** ApiKey id */
- fun apiKeyId(apiKeyId: String) = apply { this.apiKeyId = apiKeyId }
+ fun apiKeyId(apiKeyId: String?) = apply { this.apiKeyId = apiKeyId }
+
+ /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */
+ fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull())
fun additionalHeaders(additionalHeaders: Headers) = apply {
this.additionalHeaders.clear()
@@ -187,17 +188,10 @@ private constructor(
* Returns an immutable instance of [ApiKeyDeleteParams].
*
* Further updates to this [Builder] will not mutate the returned instance.
- *
- * The following fields are required:
- * ```java
- * .apiKeyId()
- * ```
- *
- * @throws IllegalStateException if any required field is unset.
*/
fun build(): ApiKeyDeleteParams =
ApiKeyDeleteParams(
- checkRequired("apiKeyId", apiKeyId),
+ apiKeyId,
additionalHeaders.build(),
additionalQueryParams.build(),
additionalBodyProperties.toImmutable(),
@@ -209,7 +203,7 @@ private constructor(
fun _pathParam(index: Int): String =
when (index) {
- 0 -> apiKeyId
+ 0 -> apiKeyId ?: ""
else -> ""
}
@@ -222,10 +216,15 @@ private constructor(
return true
}
- return /* spotless:off */ other is ApiKeyDeleteParams && apiKeyId == other.apiKeyId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */
+ return other is ApiKeyDeleteParams &&
+ apiKeyId == other.apiKeyId &&
+ additionalHeaders == other.additionalHeaders &&
+ additionalQueryParams == other.additionalQueryParams &&
+ additionalBodyProperties == other.additionalBodyProperties
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(apiKeyId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */
+ override fun hashCode(): Int =
+ Objects.hash(apiKeyId, additionalHeaders, additionalQueryParams, additionalBodyProperties)
override fun toString() =
"ApiKeyDeleteParams{apiKeyId=$apiKeyId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}"
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt
index 0aeea56f..230a76da 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPage.kt
@@ -2,49 +2,43 @@
package com.braintrustdata.api.models
+import com.braintrustdata.api.core.AutoPager
+import com.braintrustdata.api.core.Page
import com.braintrustdata.api.core.checkRequired
import com.braintrustdata.api.services.blocking.ApiKeyService
import java.util.Objects
-import java.util.Optional
-import java.util.stream.Stream
-import java.util.stream.StreamSupport
import kotlin.jvm.optionals.getOrNull
-/** @see [ApiKeyService.list] */
+/** @see ApiKeyService.list */
class ApiKeyListPage
private constructor(
private val service: ApiKeyService,
private val params: ApiKeyListParams,
private val response: ApiKeyListPageResponse,
-) {
+) : Page {
/**
* Delegates to [ApiKeyListPageResponse], but gracefully handles missing data.
*
- * @see [ApiKeyListPageResponse.objects]
+ * @see ApiKeyListPageResponse.objects
*/
fun objects(): List =
response._objects().getOptional("objects").getOrNull() ?: emptyList()
- fun hasNextPage(): Boolean = objects().isNotEmpty()
+ override fun items(): List = objects()
- fun getNextPageParams(): Optional {
- if (!hasNextPage()) {
- return Optional.empty()
- }
+ override fun hasNextPage(): Boolean = items().isNotEmpty()
- return Optional.of(
- if (params.endingBefore().isPresent) {
- params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build()
- } else {
- params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build()
- }
- )
- }
+ fun nextPageParams(): ApiKeyListParams =
+ if (params.endingBefore().isPresent) {
+ params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build()
+ } else {
+ params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build()
+ }
- fun getNextPage(): Optional = getNextPageParams().map { service.list(it) }
+ override fun nextPage(): ApiKeyListPage = service.list(nextPageParams())
- fun autoPager(): AutoPager = AutoPager(this)
+ fun autoPager(): AutoPager = AutoPager.from(this)
/** The parameters that were used to request this page. */
fun params(): ApiKeyListParams = params
@@ -113,34 +107,18 @@ private constructor(
)
}
- class AutoPager(private val firstPage: ApiKeyListPage) : Iterable {
-
- override fun iterator(): Iterator = iterator {
- var page = firstPage
- var index = 0
- while (true) {
- while (index < page.objects().size) {
- yield(page.objects()[index++])
- }
- page = page.getNextPage().getOrNull() ?: break
- index = 0
- }
- }
-
- fun stream(): Stream {
- return StreamSupport.stream(spliterator(), false)
- }
- }
-
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}
- return /* spotless:off */ other is ApiKeyListPage && service == other.service && params == other.params && response == other.response /* spotless:on */
+ return other is ApiKeyListPage &&
+ service == other.service &&
+ params == other.params &&
+ response == other.response
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */
+ override fun hashCode(): Int = Objects.hash(service, params, response)
override fun toString() = "ApiKeyListPage{service=$service, params=$params, response=$response}"
}
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt
index 5bc2cbe9..4cb580a2 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageAsync.kt
@@ -2,53 +2,46 @@
package com.braintrustdata.api.models
+import com.braintrustdata.api.core.AutoPagerAsync
+import com.braintrustdata.api.core.PageAsync
import com.braintrustdata.api.core.checkRequired
import com.braintrustdata.api.services.async.ApiKeyServiceAsync
import java.util.Objects
-import java.util.Optional
import java.util.concurrent.CompletableFuture
import java.util.concurrent.Executor
-import java.util.function.Predicate
import kotlin.jvm.optionals.getOrNull
-/** @see [ApiKeyServiceAsync.list] */
+/** @see ApiKeyServiceAsync.list */
class ApiKeyListPageAsync
private constructor(
private val service: ApiKeyServiceAsync,
+ private val streamHandlerExecutor: Executor,
private val params: ApiKeyListParams,
private val response: ApiKeyListPageResponse,
-) {
+) : PageAsync {
/**
* Delegates to [ApiKeyListPageResponse], but gracefully handles missing data.
*
- * @see [ApiKeyListPageResponse.objects]
+ * @see ApiKeyListPageResponse.objects
*/
fun objects(): List =
response._objects().getOptional("objects").getOrNull() ?: emptyList()
- fun hasNextPage(): Boolean = objects().isNotEmpty()
+ override fun items(): List = objects()
- fun getNextPageParams(): Optional {
- if (!hasNextPage()) {
- return Optional.empty()
- }
+ override fun hasNextPage(): Boolean = items().isNotEmpty()
- return Optional.of(
- if (params.endingBefore().isPresent) {
- params.toBuilder().endingBefore(objects().first()._id().getOptional("id")).build()
- } else {
- params.toBuilder().startingAfter(objects().last()._id().getOptional("id")).build()
- }
- )
- }
+ fun nextPageParams(): ApiKeyListParams =
+ if (params.endingBefore().isPresent) {
+ params.toBuilder().endingBefore(items().first()._id().getOptional("id")).build()
+ } else {
+ params.toBuilder().startingAfter(items().last()._id().getOptional("id")).build()
+ }
- fun getNextPage(): CompletableFuture> =
- getNextPageParams()
- .map { service.list(it).thenApply { Optional.of(it) } }
- .orElseGet { CompletableFuture.completedFuture(Optional.empty()) }
+ override fun nextPage(): CompletableFuture = service.list(nextPageParams())
- fun autoPager(): AutoPager = AutoPager(this)
+ fun autoPager(): AutoPagerAsync = AutoPagerAsync.from(this, streamHandlerExecutor)
/** The parameters that were used to request this page. */
fun params(): ApiKeyListParams = params
@@ -66,6 +59,7 @@ private constructor(
* The following fields are required:
* ```java
* .service()
+ * .streamHandlerExecutor()
* .params()
* .response()
* ```
@@ -77,18 +71,24 @@ private constructor(
class Builder internal constructor() {
private var service: ApiKeyServiceAsync? = null
+ private var streamHandlerExecutor: Executor? = null
private var params: ApiKeyListParams? = null
private var response: ApiKeyListPageResponse? = null
@JvmSynthetic
internal fun from(apiKeyListPageAsync: ApiKeyListPageAsync) = apply {
service = apiKeyListPageAsync.service
+ streamHandlerExecutor = apiKeyListPageAsync.streamHandlerExecutor
params = apiKeyListPageAsync.params
response = apiKeyListPageAsync.response
}
fun service(service: ApiKeyServiceAsync) = apply { this.service = service }
+ fun streamHandlerExecutor(streamHandlerExecutor: Executor) = apply {
+ this.streamHandlerExecutor = streamHandlerExecutor
+ }
+
/** The parameters that were used to request this page. */
fun params(params: ApiKeyListParams) = apply { this.params = params }
@@ -103,6 +103,7 @@ private constructor(
* The following fields are required:
* ```java
* .service()
+ * .streamHandlerExecutor()
* .params()
* .response()
* ```
@@ -112,47 +113,26 @@ private constructor(
fun build(): ApiKeyListPageAsync =
ApiKeyListPageAsync(
checkRequired("service", service),
+ checkRequired("streamHandlerExecutor", streamHandlerExecutor),
checkRequired("params", params),
checkRequired("response", response),
)
}
- class AutoPager(private val firstPage: ApiKeyListPageAsync) {
-
- fun forEach(action: Predicate, executor: Executor): CompletableFuture {
- fun CompletableFuture>.forEach(
- action: (ApiKey) -> Boolean,
- executor: Executor,
- ): CompletableFuture =
- thenComposeAsync(
- { page ->
- page
- .filter { it.objects().all(action) }
- .map { it.getNextPage().forEach(action, executor) }
- .orElseGet { CompletableFuture.completedFuture(null) }
- },
- executor,
- )
- return CompletableFuture.completedFuture(Optional.of(firstPage))
- .forEach(action::test, executor)
- }
-
- fun toList(executor: Executor): CompletableFuture> {
- val values = mutableListOf()
- return forEach(values::add, executor).thenApply { values }
- }
- }
-
override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}
- return /* spotless:off */ other is ApiKeyListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */
+ return other is ApiKeyListPageAsync &&
+ service == other.service &&
+ streamHandlerExecutor == other.streamHandlerExecutor &&
+ params == other.params &&
+ response == other.response
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */
+ override fun hashCode(): Int = Objects.hash(service, streamHandlerExecutor, params, response)
override fun toString() =
- "ApiKeyListPageAsync{service=$service, params=$params, response=$response}"
+ "ApiKeyListPageAsync{service=$service, streamHandlerExecutor=$streamHandlerExecutor, params=$params, response=$response}"
}
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageResponse.kt
index 9c42308a..a2032816 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageResponse.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListPageResponse.kt
@@ -178,12 +178,12 @@ private constructor(
return true
}
- return /* spotless:off */ other is ApiKeyListPageResponse && objects == other.objects && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is ApiKeyListPageResponse &&
+ objects == other.objects &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(objects, additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListParams.kt
index a1fcb296..8615dda7 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListParams.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyListParams.kt
@@ -6,6 +6,7 @@ import com.braintrustdata.api.core.Params
import com.braintrustdata.api.core.getOrThrow
import com.braintrustdata.api.core.http.Headers
import com.braintrustdata.api.core.http.QueryParams
+import com.braintrustdata.api.core.toImmutable
import java.util.Objects
import java.util.Optional
import kotlin.jvm.optionals.getOrNull
@@ -59,8 +60,10 @@ private constructor(
*/
fun startingAfter(): Optional = Optional.ofNullable(startingAfter)
+ /** 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)
@@ -337,10 +340,10 @@ private constructor(
return true
}
- return /* spotless:off */ other is Ids && string == other.string && strings == other.strings /* spotless:on */
+ return other is Ids && string == other.string && strings == other.strings
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(string, strings) /* spotless:on */
+ override fun hashCode(): Int = Objects.hash(string, strings)
override fun toString(): String =
when {
@@ -353,7 +356,7 @@ private constructor(
@JvmStatic fun ofString(string: String) = Ids(string = string)
- @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings)
+ @JvmStatic fun ofStrings(strings: List) = Ids(strings = strings.toImmutable())
}
/** An interface that defines how to map each variant of [Ids] to a value of type [T]. */
@@ -370,10 +373,28 @@ private constructor(
return true
}
- return /* spotless:off */ other is ApiKeyListParams && apiKeyName == other.apiKeyName && endingBefore == other.endingBefore && ids == other.ids && limit == other.limit && orgName == other.orgName && startingAfter == other.startingAfter && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
+ return other is ApiKeyListParams &&
+ apiKeyName == other.apiKeyName &&
+ endingBefore == other.endingBefore &&
+ ids == other.ids &&
+ limit == other.limit &&
+ orgName == other.orgName &&
+ startingAfter == other.startingAfter &&
+ additionalHeaders == other.additionalHeaders &&
+ additionalQueryParams == other.additionalQueryParams
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(apiKeyName, endingBefore, ids, limit, orgName, startingAfter, additionalHeaders, additionalQueryParams) /* spotless:on */
+ override fun hashCode(): Int =
+ Objects.hash(
+ apiKeyName,
+ endingBefore,
+ ids,
+ limit,
+ orgName,
+ startingAfter,
+ additionalHeaders,
+ additionalQueryParams,
+ )
override fun toString() =
"ApiKeyListParams{apiKeyName=$apiKeyName, endingBefore=$endingBefore, ids=$ids, limit=$limit, orgName=$orgName, startingAfter=$startingAfter, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}"
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyRetrieveParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyRetrieveParams.kt
index de3cb891..4a7aa490 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyRetrieveParams.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ApiKeyRetrieveParams.kt
@@ -3,38 +3,36 @@
package com.braintrustdata.api.models
import com.braintrustdata.api.core.Params
-import com.braintrustdata.api.core.checkRequired
import com.braintrustdata.api.core.http.Headers
import com.braintrustdata.api.core.http.QueryParams
import java.util.Objects
+import java.util.Optional
+import kotlin.jvm.optionals.getOrNull
/** Get an api_key object by its id */
class ApiKeyRetrieveParams
private constructor(
- private val apiKeyId: String,
+ private val apiKeyId: String?,
private val additionalHeaders: Headers,
private val additionalQueryParams: QueryParams,
) : Params {
/** ApiKey id */
- fun apiKeyId(): String = apiKeyId
+ fun apiKeyId(): Optional = Optional.ofNullable(apiKeyId)
+ /** 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 [ApiKeyRetrieveParams].
- *
- * The following fields are required:
- * ```java
- * .apiKeyId()
- * ```
- */
+ @JvmStatic fun none(): ApiKeyRetrieveParams = builder().build()
+
+ /** Returns a mutable builder for constructing an instance of [ApiKeyRetrieveParams]. */
@JvmStatic fun builder() = Builder()
}
@@ -53,7 +51,10 @@ private constructor(
}
/** ApiKey id */
- fun apiKeyId(apiKeyId: String) = apply { this.apiKeyId = apiKeyId }
+ fun apiKeyId(apiKeyId: String?) = apply { this.apiKeyId = apiKeyId }
+
+ /** Alias for calling [Builder.apiKeyId] with `apiKeyId.orElse(null)`. */
+ fun apiKeyId(apiKeyId: Optional) = apiKeyId(apiKeyId.getOrNull())
fun additionalHeaders(additionalHeaders: Headers) = apply {
this.additionalHeaders.clear()
@@ -157,25 +158,14 @@ private constructor(
* Returns an immutable instance of [ApiKeyRetrieveParams].
*
* Further updates to this [Builder] will not mutate the returned instance.
- *
- * The following fields are required:
- * ```java
- * .apiKeyId()
- * ```
- *
- * @throws IllegalStateException if any required field is unset.
*/
fun build(): ApiKeyRetrieveParams =
- ApiKeyRetrieveParams(
- checkRequired("apiKeyId", apiKeyId),
- additionalHeaders.build(),
- additionalQueryParams.build(),
- )
+ ApiKeyRetrieveParams(apiKeyId, additionalHeaders.build(), additionalQueryParams.build())
}
fun _pathParam(index: Int): String =
when (index) {
- 0 -> apiKeyId
+ 0 -> apiKeyId ?: ""
else -> ""
}
@@ -188,10 +178,13 @@ private constructor(
return true
}
- return /* spotless:off */ other is ApiKeyRetrieveParams && apiKeyId == other.apiKeyId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
+ return other is ApiKeyRetrieveParams &&
+ apiKeyId == other.apiKeyId &&
+ additionalHeaders == other.additionalHeaders &&
+ additionalQueryParams == other.additionalQueryParams
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(apiKeyId, additionalHeaders, additionalQueryParams) /* spotless:on */
+ override fun hashCode(): Int = Objects.hash(apiKeyId, additionalHeaders, additionalQueryParams)
override fun toString() =
"ApiKeyRetrieveParams{apiKeyId=$apiKeyId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}"
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImage.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImage.kt
index d7fb8bd9..0d3f3f0a 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImage.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartImage.kt
@@ -483,7 +483,7 @@ private constructor(
return true
}
- return /* spotless:off */ other is Detail && value == other.value /* spotless:on */
+ return other is Detail && value == other.value
}
override fun hashCode() = value.hashCode()
@@ -496,12 +496,13 @@ private constructor(
return true
}
- return /* spotless:off */ other is ImageUrl && url == other.url && detail == other.detail && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is ImageUrl &&
+ url == other.url &&
+ detail == other.detail &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(url, detail, additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
@@ -622,7 +623,7 @@ private constructor(
return true
}
- return /* spotless:off */ other is Type && value == other.value /* spotless:on */
+ return other is Type && value == other.value
}
override fun hashCode() = value.hashCode()
@@ -635,12 +636,13 @@ private constructor(
return true
}
- return /* spotless:off */ other is ChatCompletionContentPartImage && imageUrl == other.imageUrl && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is ChatCompletionContentPartImage &&
+ imageUrl == other.imageUrl &&
+ type == other.type &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(imageUrl, type, additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartText.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartText.kt
index 7452ab93..8159e029 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartText.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionContentPartText.kt
@@ -298,7 +298,7 @@ private constructor(
return true
}
- return /* spotless:off */ other is Type && value == other.value /* spotless:on */
+ return other is Type && value == other.value
}
override fun hashCode() = value.hashCode()
@@ -311,12 +311,13 @@ private constructor(
return true
}
- return /* spotless:off */ other is ChatCompletionContentPartText && type == other.type && text == other.text && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is ChatCompletionContentPartText &&
+ type == other.type &&
+ text == other.text &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(type, text, additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionMessageToolCall.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionMessageToolCall.kt
index fdd8a4d7..ed90e5c5 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionMessageToolCall.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/ChatCompletionMessageToolCall.kt
@@ -398,12 +398,13 @@ private constructor(
return true
}
- return /* spotless:off */ other is Function && arguments == other.arguments && name == other.name && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Function &&
+ arguments == other.arguments &&
+ name == other.name &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(arguments, name, additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
@@ -524,7 +525,7 @@ private constructor(
return true
}
- return /* spotless:off */ other is Type && value == other.value /* spotless:on */
+ return other is Type && value == other.value
}
override fun hashCode() = value.hashCode()
@@ -537,12 +538,14 @@ private constructor(
return true
}
- return /* spotless:off */ other is ChatCompletionMessageToolCall && id == other.id && function == other.function && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is ChatCompletionMessageToolCall &&
+ id == other.id &&
+ function == other.function &&
+ type == other.type &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(id, function, type, additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CodeBundle.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CodeBundle.kt
index d547c7a0..6564379d 100644
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CodeBundle.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CodeBundle.kt
@@ -363,10 +363,10 @@ private constructor(
return true
}
- return /* spotless:off */ other is Location && experiment == other.experiment && function == other.function /* spotless:on */
+ return other is Location && experiment == other.experiment && function == other.function
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(experiment, function) /* spotless:on */
+ override fun hashCode(): Int = Objects.hash(experiment, function)
override fun toString(): String =
when {
@@ -760,10 +760,10 @@ private constructor(
return true
}
- return /* spotless:off */ other is Position && type == other.type && scorer == other.scorer /* spotless:on */
+ return other is Position && type == other.type && scorer == other.scorer
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(type, scorer) /* spotless:on */
+ override fun hashCode(): Int = Objects.hash(type, scorer)
override fun toString(): String =
when {
@@ -1120,7 +1120,7 @@ private constructor(
return true
}
- return /* spotless:off */ other is InnerType && value == other.value /* spotless:on */
+ return other is InnerType && value == other.value
}
override fun hashCode() = value.hashCode()
@@ -1133,12 +1133,12 @@ private constructor(
return true
}
- return /* spotless:off */ other is Type && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Type &&
+ type == other.type &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(type, additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
@@ -1451,7 +1451,7 @@ private constructor(
return true
}
- return /* spotless:off */ other is Type && value == other.value /* spotless:on */
+ return other is Type && value == other.value
}
override fun hashCode() = value.hashCode()
@@ -1464,12 +1464,15 @@ private constructor(
return true
}
- return /* spotless:off */ other is Scorer && index == other.index && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Scorer &&
+ index == other.index &&
+ type == other.type &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
- private val hashCode: Int by lazy { Objects.hash(index, type, additionalProperties) }
- /* spotless:on */
+ private val hashCode: Int by lazy {
+ Objects.hash(index, type, additionalProperties)
+ }
override fun hashCode(): Int = hashCode
@@ -1594,7 +1597,7 @@ private constructor(
return true
}
- return /* spotless:off */ other is Type && value == other.value /* spotless:on */
+ return other is Type && value == other.value
}
override fun hashCode() = value.hashCode()
@@ -1607,12 +1610,16 @@ private constructor(
return true
}
- return /* spotless:off */ other is Experiment && evalName == other.evalName && position == other.position && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Experiment &&
+ evalName == other.evalName &&
+ position == other.position &&
+ type == other.type &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
- private val hashCode: Int by lazy { Objects.hash(evalName, position, type, additionalProperties) }
- /* spotless:on */
+ private val hashCode: Int by lazy {
+ Objects.hash(evalName, position, type, additionalProperties)
+ }
override fun hashCode(): Int = hashCode
@@ -1913,7 +1920,7 @@ private constructor(
return true
}
- return /* spotless:off */ other is Type && value == other.value /* spotless:on */
+ return other is Type && value == other.value
}
override fun hashCode() = value.hashCode()
@@ -1926,12 +1933,13 @@ private constructor(
return true
}
- return /* spotless:off */ other is Function && index == other.index && type == other.type && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Function &&
+ index == other.index &&
+ type == other.type &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(index, type, additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
@@ -2234,7 +2242,7 @@ private constructor(
return true
}
- return /* spotless:off */ other is Runtime && value == other.value /* spotless:on */
+ return other is Runtime && value == other.value
}
override fun hashCode() = value.hashCode()
@@ -2247,12 +2255,13 @@ private constructor(
return true
}
- return /* spotless:off */ other is RuntimeContext && runtime == other.runtime && version == other.version && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is RuntimeContext &&
+ runtime == other.runtime &&
+ version == other.version &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(runtime, version, additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
@@ -2265,12 +2274,17 @@ private constructor(
return true
}
- return /* spotless:off */ other is CodeBundle && bundleId == other.bundleId && location == other.location && runtimeContext == other.runtimeContext && preview == other.preview && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is CodeBundle &&
+ bundleId == other.bundleId &&
+ location == other.location &&
+ runtimeContext == other.runtimeContext &&
+ preview == other.preview &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
- private val hashCode: Int by lazy { Objects.hash(bundleId, location, runtimeContext, preview, additionalProperties) }
- /* spotless:on */
+ private val hashCode: Int by lazy {
+ Objects.hash(bundleId, location, runtimeContext, preview, additionalProperties)
+ }
override fun hashCode(): Int = hashCode
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CreateApiKeyOutput.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CreateApiKeyOutput.kt
index 2cbb41ce..d9bb43d1 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CreateApiKeyOutput.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CreateApiKeyOutput.kt
@@ -381,12 +381,20 @@ private constructor(
return true
}
- return /* spotless:off */ other is CreateApiKeyOutput && id == other.id && key == other.key && name == other.name && previewName == other.previewName && created == other.created && orgId == other.orgId && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is CreateApiKeyOutput &&
+ id == other.id &&
+ key == other.key &&
+ name == other.name &&
+ previewName == other.previewName &&
+ created == other.created &&
+ orgId == other.orgId &&
+ userId == other.userId &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
- private val hashCode: Int by lazy { Objects.hash(id, key, name, previewName, created, orgId, userId, additionalProperties) }
- /* spotless:on */
+ private val hashCode: Int by lazy {
+ Objects.hash(id, key, name, previewName, created, orgId, userId, additionalProperties)
+ }
override fun hashCode(): Int = hashCode
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponse.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponse.kt
index e258e247..b3417eb9 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponse.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/CrossObjectInsertResponse.kt
@@ -322,12 +322,10 @@ private constructor(
return true
}
- return /* spotless:off */ other is Dataset && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Dataset && additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
@@ -424,12 +422,10 @@ private constructor(
return true
}
- return /* spotless:off */ other is Experiment && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Experiment && additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
@@ -526,12 +522,10 @@ private constructor(
return true
}
- return /* spotless:off */ other is ProjectLogs && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is ProjectLogs && additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
@@ -543,12 +537,16 @@ private constructor(
return true
}
- return /* spotless:off */ other is CrossObjectInsertResponse && dataset == other.dataset && experiment == other.experiment && projectLogs == other.projectLogs && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is CrossObjectInsertResponse &&
+ dataset == other.dataset &&
+ experiment == other.experiment &&
+ projectLogs == other.projectLogs &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
- private val hashCode: Int by lazy { Objects.hash(dataset, experiment, projectLogs, additionalProperties) }
- /* spotless:on */
+ private val hashCode: Int by lazy {
+ Objects.hash(dataset, experiment, projectLogs, additionalProperties)
+ }
override fun hashCode(): Int = hashCode
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DataSummary.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DataSummary.kt
index e499cfa4..54ea8627 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DataSummary.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DataSummary.kt
@@ -164,12 +164,12 @@ private constructor(
return true
}
- return /* spotless:off */ other is DataSummary && totalRecords == other.totalRecords && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is DataSummary &&
+ totalRecords == other.totalRecords &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(totalRecords, additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Dataset.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Dataset.kt
index 66fafea8..4c18d5a4 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Dataset.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/Dataset.kt
@@ -512,12 +512,10 @@ private constructor(
return true
}
- return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Metadata && additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
@@ -529,12 +527,31 @@ private constructor(
return true
}
- return /* spotless:off */ other is Dataset && id == other.id && name == other.name && projectId == other.projectId && created == other.created && deletedAt == other.deletedAt && description == other.description && metadata == other.metadata && userId == other.userId && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Dataset &&
+ id == other.id &&
+ name == other.name &&
+ projectId == other.projectId &&
+ created == other.created &&
+ deletedAt == other.deletedAt &&
+ description == other.description &&
+ metadata == other.metadata &&
+ userId == other.userId &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
- private val hashCode: Int by lazy { Objects.hash(id, name, projectId, created, deletedAt, description, metadata, userId, additionalProperties) }
- /* spotless:on */
+ private val hashCode: Int by lazy {
+ Objects.hash(
+ id,
+ name,
+ projectId,
+ created,
+ deletedAt,
+ description,
+ metadata,
+ userId,
+ additionalProperties,
+ )
+ }
override fun hashCode(): Int = hashCode
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt
index b082caaa..b33826d9 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetCreateParams.kt
@@ -94,8 +94,10 @@ private constructor(
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)
@@ -604,12 +606,17 @@ private constructor(
return true
}
- return /* spotless:off */ other is Body && name == other.name && projectId == other.projectId && description == other.description && metadata == other.metadata && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Body &&
+ name == other.name &&
+ projectId == other.projectId &&
+ description == other.description &&
+ metadata == other.metadata &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
- private val hashCode: Int by lazy { Objects.hash(name, projectId, description, metadata, additionalProperties) }
- /* spotless:on */
+ private val hashCode: Int by lazy {
+ Objects.hash(name, projectId, description, metadata, additionalProperties)
+ }
override fun hashCode(): Int = hashCode
@@ -707,12 +714,10 @@ private constructor(
return true
}
- return /* spotless:off */ other is Metadata && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Metadata && additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
@@ -724,10 +729,13 @@ private constructor(
return true
}
- return /* spotless:off */ other is DatasetCreateParams && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
+ return other is DatasetCreateParams &&
+ body == other.body &&
+ additionalHeaders == other.additionalHeaders &&
+ additionalQueryParams == other.additionalQueryParams
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(body, additionalHeaders, additionalQueryParams) /* spotless:on */
+ override fun hashCode(): Int = Objects.hash(body, additionalHeaders, additionalQueryParams)
override fun toString() =
"DatasetCreateParams{body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}"
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetDeleteParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetDeleteParams.kt
index c4238c34..bd822a26 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetDeleteParams.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetDeleteParams.kt
@@ -4,43 +4,41 @@ package com.braintrustdata.api.models
import com.braintrustdata.api.core.JsonValue
import com.braintrustdata.api.core.Params
-import com.braintrustdata.api.core.checkRequired
import com.braintrustdata.api.core.http.Headers
import com.braintrustdata.api.core.http.QueryParams
import com.braintrustdata.api.core.toImmutable
import java.util.Objects
import java.util.Optional
+import kotlin.jvm.optionals.getOrNull
/** Delete a dataset object by its id */
class DatasetDeleteParams
private constructor(
- private val datasetId: String,
+ private val datasetId: String?,
private val additionalHeaders: Headers,
private val additionalQueryParams: QueryParams,
private val additionalBodyProperties: Map,
) : Params {
/** Dataset id */
- fun datasetId(): String = datasetId
+ fun datasetId(): Optional = Optional.ofNullable(datasetId)
+ /** Additional body properties to send with the request. */
fun _additionalBodyProperties(): Map = additionalBodyProperties
+ /** Additional headers to send with the request. */
fun _additionalHeaders(): Headers = additionalHeaders
+ /** Additional query param to send with the request. */
fun _additionalQueryParams(): QueryParams = additionalQueryParams
fun toBuilder() = Builder().from(this)
companion object {
- /**
- * Returns a mutable builder for constructing an instance of [DatasetDeleteParams].
- *
- * The following fields are required:
- * ```java
- * .datasetId()
- * ```
- */
+ @JvmStatic fun none(): DatasetDeleteParams = builder().build()
+
+ /** Returns a mutable builder for constructing an instance of [DatasetDeleteParams]. */
@JvmStatic fun builder() = Builder()
}
@@ -61,7 +59,10 @@ private constructor(
}
/** Dataset id */
- fun datasetId(datasetId: String) = apply { this.datasetId = datasetId }
+ fun datasetId(datasetId: String?) = apply { this.datasetId = datasetId }
+
+ /** Alias for calling [Builder.datasetId] with `datasetId.orElse(null)`. */
+ fun datasetId(datasetId: Optional) = datasetId(datasetId.getOrNull())
fun additionalHeaders(additionalHeaders: Headers) = apply {
this.additionalHeaders.clear()
@@ -187,17 +188,10 @@ private constructor(
* Returns an immutable instance of [DatasetDeleteParams].
*
* Further updates to this [Builder] will not mutate the returned instance.
- *
- * The following fields are required:
- * ```java
- * .datasetId()
- * ```
- *
- * @throws IllegalStateException if any required field is unset.
*/
fun build(): DatasetDeleteParams =
DatasetDeleteParams(
- checkRequired("datasetId", datasetId),
+ datasetId,
additionalHeaders.build(),
additionalQueryParams.build(),
additionalBodyProperties.toImmutable(),
@@ -209,7 +203,7 @@ private constructor(
fun _pathParam(index: Int): String =
when (index) {
- 0 -> datasetId
+ 0 -> datasetId ?: ""
else -> ""
}
@@ -222,10 +216,15 @@ private constructor(
return true
}
- return /* spotless:off */ other is DatasetDeleteParams && datasetId == other.datasetId && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams && additionalBodyProperties == other.additionalBodyProperties /* spotless:on */
+ return other is DatasetDeleteParams &&
+ datasetId == other.datasetId &&
+ additionalHeaders == other.additionalHeaders &&
+ additionalQueryParams == other.additionalQueryParams &&
+ additionalBodyProperties == other.additionalBodyProperties
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(datasetId, additionalHeaders, additionalQueryParams, additionalBodyProperties) /* spotless:on */
+ override fun hashCode(): Int =
+ Objects.hash(datasetId, additionalHeaders, additionalQueryParams, additionalBodyProperties)
override fun toString() =
"DatasetDeleteParams{datasetId=$datasetId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}"
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetEvent.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetEvent.kt
index e3b2abfa..3b9ddfd6 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetEvent.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetEvent.kt
@@ -753,12 +753,12 @@ private constructor(
return true
}
- return /* spotless:off */ other is Metadata && model == other.model && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Metadata &&
+ model == other.model &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(model, additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
@@ -771,12 +771,41 @@ private constructor(
return true
}
- return /* spotless:off */ other is DatasetEvent && id == other.id && _xactId == other._xactId && created == other.created && datasetId == other.datasetId && projectId == other.projectId && rootSpanId == other.rootSpanId && spanId == other.spanId && expected == other.expected && input == other.input && isRoot == other.isRoot && metadata == other.metadata && origin == other.origin && tags == other.tags && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is DatasetEvent &&
+ id == other.id &&
+ _xactId == other._xactId &&
+ created == other.created &&
+ datasetId == other.datasetId &&
+ projectId == other.projectId &&
+ rootSpanId == other.rootSpanId &&
+ spanId == other.spanId &&
+ expected == other.expected &&
+ input == other.input &&
+ isRoot == other.isRoot &&
+ metadata == other.metadata &&
+ origin == other.origin &&
+ tags == other.tags &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
- private val hashCode: Int by lazy { Objects.hash(id, _xactId, created, datasetId, projectId, rootSpanId, spanId, expected, input, isRoot, metadata, origin, tags, additionalProperties) }
- /* spotless:on */
+ private val hashCode: Int by lazy {
+ Objects.hash(
+ id,
+ _xactId,
+ created,
+ datasetId,
+ projectId,
+ rootSpanId,
+ spanId,
+ expected,
+ input,
+ isRoot,
+ metadata,
+ origin,
+ tags,
+ additionalProperties,
+ )
+ }
override fun hashCode(): Int = hashCode
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFeedbackParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFeedbackParams.kt
index e313cd08..c2ae180e 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFeedbackParams.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFeedbackParams.kt
@@ -19,19 +19,20 @@ 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
/** Log feedback for a set of dataset events */
class DatasetFeedbackParams
private constructor(
- private val datasetId: String,
+ private val datasetId: String?,
private val body: Body,
private val additionalHeaders: Headers,
private val additionalQueryParams: QueryParams,
) : Params {
/** Dataset id */
- fun datasetId(): String = datasetId
+ fun datasetId(): Optional = Optional.ofNullable(datasetId)
/**
* A list of dataset feedback items
@@ -50,8 +51,10 @@ private constructor(
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)
@@ -63,7 +66,6 @@ private constructor(
*
* The following fields are required:
* ```java
- * .datasetId()
* .feedback()
* ```
*/
@@ -87,7 +89,10 @@ private constructor(
}
/** Dataset id */
- fun datasetId(datasetId: String) = apply { this.datasetId = datasetId }
+ fun datasetId(datasetId: String?) = apply { this.datasetId = datasetId }
+
+ /** Alias for calling [Builder.datasetId] with `datasetId.orElse(null)`. */
+ fun datasetId(datasetId: Optional) = datasetId(datasetId.getOrNull())
/**
* Sets the entire request body.
@@ -243,7 +248,6 @@ private constructor(
*
* The following fields are required:
* ```java
- * .datasetId()
* .feedback()
* ```
*
@@ -251,7 +255,7 @@ private constructor(
*/
fun build(): DatasetFeedbackParams =
DatasetFeedbackParams(
- checkRequired("datasetId", datasetId),
+ datasetId,
body.build(),
additionalHeaders.build(),
additionalQueryParams.build(),
@@ -262,7 +266,7 @@ private constructor(
fun _pathParam(index: Int): String =
when (index) {
- 0 -> datasetId
+ 0 -> datasetId ?: ""
else -> ""
}
@@ -435,12 +439,12 @@ private constructor(
return true
}
- return /* spotless:off */ other is Body && feedback == other.feedback && additionalProperties == other.additionalProperties /* spotless:on */
+ return other is Body &&
+ feedback == other.feedback &&
+ additionalProperties == other.additionalProperties
}
- /* spotless:off */
private val hashCode: Int by lazy { Objects.hash(feedback, additionalProperties) }
- /* spotless:on */
override fun hashCode(): Int = hashCode
@@ -453,10 +457,15 @@ private constructor(
return true
}
- return /* spotless:off */ other is DatasetFeedbackParams && datasetId == other.datasetId && body == other.body && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
+ return other is DatasetFeedbackParams &&
+ datasetId == other.datasetId &&
+ body == other.body &&
+ additionalHeaders == other.additionalHeaders &&
+ additionalQueryParams == other.additionalQueryParams
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(datasetId, body, additionalHeaders, additionalQueryParams) /* spotless:on */
+ override fun hashCode(): Int =
+ Objects.hash(datasetId, body, additionalHeaders, additionalQueryParams)
override fun toString() =
"DatasetFeedbackParams{datasetId=$datasetId, body=$body, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}"
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchParams.kt
index ac9b82f8..38306f2a 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchParams.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchParams.kt
@@ -3,7 +3,6 @@
package com.braintrustdata.api.models
import com.braintrustdata.api.core.Params
-import com.braintrustdata.api.core.checkRequired
import com.braintrustdata.api.core.http.Headers
import com.braintrustdata.api.core.http.QueryParams
import java.util.Objects
@@ -17,7 +16,7 @@ import kotlin.jvm.optionals.getOrNull
*/
class DatasetFetchParams
private constructor(
- private val datasetId: String,
+ private val datasetId: String?,
private val limit: Long?,
private val maxRootSpanId: String?,
private val maxXactId: String?,
@@ -27,7 +26,7 @@ private constructor(
) : Params {
/** Dataset id */
- fun datasetId(): String = datasetId
+ fun datasetId(): Optional = Optional.ofNullable(datasetId)
/**
* limit the number of traces fetched
@@ -81,22 +80,19 @@ private constructor(
*/
fun version(): Optional = Optional.ofNullable(version)
+ /** 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 [DatasetFetchParams].
- *
- * The following fields are required:
- * ```java
- * .datasetId()
- * ```
- */
+ @JvmStatic fun none(): DatasetFetchParams = builder().build()
+
+ /** Returns a mutable builder for constructing an instance of [DatasetFetchParams]. */
@JvmStatic fun builder() = Builder()
}
@@ -123,7 +119,10 @@ private constructor(
}
/** Dataset id */
- fun datasetId(datasetId: String) = apply { this.datasetId = datasetId }
+ fun datasetId(datasetId: String?) = apply { this.datasetId = datasetId }
+
+ /** Alias for calling [Builder.datasetId] with `datasetId.orElse(null)`. */
+ fun datasetId(datasetId: Optional) = datasetId(datasetId.getOrNull())
/**
* limit the number of traces fetched
@@ -300,17 +299,10 @@ private constructor(
* Returns an immutable instance of [DatasetFetchParams].
*
* Further updates to this [Builder] will not mutate the returned instance.
- *
- * The following fields are required:
- * ```java
- * .datasetId()
- * ```
- *
- * @throws IllegalStateException if any required field is unset.
*/
fun build(): DatasetFetchParams =
DatasetFetchParams(
- checkRequired("datasetId", datasetId),
+ datasetId,
limit,
maxRootSpanId,
maxXactId,
@@ -322,7 +314,7 @@ private constructor(
fun _pathParam(index: Int): String =
when (index) {
- 0 -> datasetId
+ 0 -> datasetId ?: ""
else -> ""
}
@@ -344,10 +336,26 @@ private constructor(
return true
}
- return /* spotless:off */ other is DatasetFetchParams && datasetId == other.datasetId && limit == other.limit && maxRootSpanId == other.maxRootSpanId && maxXactId == other.maxXactId && version == other.version && additionalHeaders == other.additionalHeaders && additionalQueryParams == other.additionalQueryParams /* spotless:on */
+ return other is DatasetFetchParams &&
+ datasetId == other.datasetId &&
+ limit == other.limit &&
+ maxRootSpanId == other.maxRootSpanId &&
+ maxXactId == other.maxXactId &&
+ version == other.version &&
+ additionalHeaders == other.additionalHeaders &&
+ additionalQueryParams == other.additionalQueryParams
}
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(datasetId, limit, maxRootSpanId, maxXactId, version, additionalHeaders, additionalQueryParams) /* spotless:on */
+ override fun hashCode(): Int =
+ Objects.hash(
+ datasetId,
+ limit,
+ maxRootSpanId,
+ maxXactId,
+ version,
+ additionalHeaders,
+ additionalQueryParams,
+ )
override fun toString() =
"DatasetFetchParams{datasetId=$datasetId, limit=$limit, maxRootSpanId=$maxRootSpanId, maxXactId=$maxXactId, version=$version, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}"
diff --git a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt
index 6dd48c3a..2482f698 100755
--- a/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt
+++ b/braintrust-java-core/src/main/kotlin/com/braintrustdata/api/models/DatasetFetchPostParams.kt
@@ -7,7 +7,6 @@ import com.braintrustdata.api.core.JsonField
import com.braintrustdata.api.core.JsonMissing
import com.braintrustdata.api.core.JsonValue
import com.braintrustdata.api.core.Params
-import com.braintrustdata.api.core.checkRequired
import com.braintrustdata.api.core.http.Headers
import com.braintrustdata.api.core.http.QueryParams
import com.braintrustdata.api.errors.BraintrustInvalidDataException
@@ -27,14 +26,14 @@ import kotlin.jvm.optionals.getOrNull
*/
class DatasetFetchPostParams
private constructor(
- private val datasetId: String,
+ private val datasetId: String?,
private val body: Body,
private val additionalHeaders: Headers,
private val additionalQueryParams: QueryParams,
) : Params {
/** Dataset id */
- fun datasetId(): String = datasetId
+ fun datasetId(): Optional = Optional.ofNullable(datasetId)
/**
* An opaque string to be used as a cursor for the next page of results, in order from latest to
@@ -148,22 +147,19 @@ private constructor(
fun _additionalBodyProperties(): Map