diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
new file mode 100644
index 00000000..bd8e2619
--- /dev/null
+++ b/.devcontainer/Dockerfile
@@ -0,0 +1,23 @@
+# syntax=docker/dockerfile:1
+FROM debian:bookworm-slim
+
+RUN apt-get update && apt-get install -y --no-install-recommends \
+ libxkbcommon0 \
+ ca-certificates \
+ ca-certificates-java \
+ make \
+ curl \
+ git \
+ openjdk-17-jdk-headless \
+ unzip \
+ libc++1 \
+ vim \
+ && apt-get clean autoclean
+
+# Ensure UTF-8 encoding
+ENV LANG=C.UTF-8
+ENV LC_ALL=C.UTF-8
+
+WORKDIR /workspace
+
+COPY . /workspace
diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
new file mode 100644
index 00000000..d55fc4d6
--- /dev/null
+++ b/.devcontainer/devcontainer.json
@@ -0,0 +1,20 @@
+// For format details, see https://aka.ms/devcontainer.json. For config options, see the
+// README at: https://github.com/devcontainers/templates/tree/main/src/debian
+{
+ "name": "Debian",
+ "build": {
+ "dockerfile": "Dockerfile"
+ }
+
+ // Features to add to the dev container. More info: https://containers.dev/features.
+ // "features": {},
+
+ // Use 'forwardPorts' to make a list of ports inside the container available locally.
+ // "forwardPorts": [],
+
+ // Configure tool-specific properties.
+ // "customizations": {},
+
+ // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
+ // "remoteUser": "root"
+}
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 00000000..022b8414
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,5 @@
+#
+# https://help.github.com/articles/dealing-with-line-endings/
+#
+# These are explicitly windows files and should use crlf
+*.bat text eol=crlf
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 00000000..72cc5bb5
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,85 @@
+name: CI
+on:
+ push:
+ branches-ignore:
+ - 'generated'
+ - 'codegen/**'
+ - 'integrated/**'
+ - 'stl-preview-head/**'
+ - 'stl-preview-base/**'
+ pull_request:
+ branches-ignore:
+ - 'stl-preview-head/**'
+ - 'stl-preview-base/**'
+
+jobs:
+ lint:
+ timeout-minutes: 15
+ name: lint
+ runs-on: ${{ github.repository == 'stainless-sdks/langsmith-api-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: Run lints
+ run: ./scripts/lint
+
+ build:
+ timeout-minutes: 15
+ name: build
+ runs-on: ${{ github.repository == 'stainless-sdks/langsmith-api-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: 15
+ name: test
+ runs-on: ${{ github.repository == 'stainless-sdks/langsmith-api-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/gradle-build-action@v2
+
+ - name: Run tests
+ run: ./scripts/test
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..b1346e6d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,7 @@
+.prism.log
+.gradle
+.idea
+.kotlin
+build/
+codegen.log
+kls_database.db
diff --git a/.stats.yml b/.stats.yml
new file mode 100644
index 00000000..0310217e
--- /dev/null
+++ b/.stats.yml
@@ -0,0 +1,4 @@
+configured_endpoints: 376
+openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/langsmith%2Flangsmith-api-2381f22916c5094080a5346c9d11ff714fa010aca50964f3607fa43caa99cc59.yml
+openapi_spec_hash: d9381bbd5f5eaffe539fafc00f78a248
+config_hash: f5940867cdcdeda9f806e31d29865247
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 00000000..6cac201b
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright 2025 LangChain
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/README.md b/README.md
new file mode 100644
index 00000000..a1943475
--- /dev/null
+++ b/README.md
@@ -0,0 +1,716 @@
+# LangChain Java API Library
+
+[](https://central.sonatype.com/artifact/com.langchain.smith/langsmith/0.0.1)
+[](https://javadoc.io/doc/com.langchain.smith/langsmith/0.0.1)
+
+The LangChain Java SDK provides convenient access to the LangChain REST API from applications written in Java.
+
+It is generated with [Stainless](https://www.stainless.com/).
+
+Javadocs are available on [javadoc.io](https://javadoc.io/doc/com.langchain.smith/langsmith/0.0.1).
+
+## Installation
+
+### Gradle
+
+```kotlin
+implementation("com.langchain.smith:langsmith:0.0.1")
+```
+
+### Maven
+
+```xml
+
+ com.langchain.smith
+ langsmith
+ 0.0.1
+
+```
+
+## Requirements
+
+This library requires Java 8 or later.
+
+## Usage
+
+```java
+import com.langchain.smith.client.LangsmithClient;
+import com.langchain.smith.client.okhttp.LangsmithOkHttpClient;
+import com.langchain.smith.models.sessions.CustomChartsSection;
+import com.langchain.smith.models.sessions.CustomChartsSectionRequest;
+import com.langchain.smith.models.sessions.SessionDashboardParams;
+
+// Configures using the `langchain.langsmithApiKey`, `langchain.langsmithTenantId`, `langchain.langsmithBearerToken`, `langchain.langsmithOrganizationId` and `langchain.baseUrl` system properties
+// Or configures using the `LANGSMITH_API_KEY`, `LANGSMITH_TENANT_ID`, `LANGSMITH_BEARER_TOKEN`, `LANGSMITH_ORGANIZATION_ID` and `LANGCHAIN_BASE_URL` environment variables
+LangsmithClient client = LangsmithOkHttpClient.fromEnv();
+
+SessionDashboardParams params = SessionDashboardParams.builder()
+ .sessionId("REPLACE_ME")
+ .customChartsSectionRequest(CustomChartsSectionRequest.builder().build())
+ .build();
+CustomChartsSection customChartsSection = client.sessions().dashboard(params);
+```
+
+## Examples
+
+This repository includes runnable examples in the `langsmith-java-example` module to help you get started.
+
+### Running Examples
+
+Examples can be run using Gradle:
+
+```bash
+# Set required environment variables
+export LANGSMITH_API_KEY="your-api-key"
+export LANGSMITH_BASE_URL="https://api.smith.langchain.com"
+
+# Run a specific example
+./gradlew :langsmith-java-example:run -Pexample=ListRuns
+```
+
+### Available Examples
+
+- **ListRuns** - Query and list runs from a project
+
+```bash
+export LANGSMITH_PROJECT_ID="your-project-id"
+./gradlew :langsmith-java-example:run -Pexample=ListRuns
+```
+
+All example source code is available in [`langsmith-java-example/src/main/java/com/langchain/smith/example/`](langsmith-java-example/src/main/java/com/langchain/smith/example/).
+
+## Client configuration
+
+Configure the client using system properties or environment variables:
+
+```java
+import com.langchain.smith.client.LangsmithClient;
+import com.langchain.smith.client.okhttp.LangsmithOkHttpClient;
+
+// Configures using the `langchain.langsmithApiKey`, `langchain.langsmithTenantId`, `langchain.langsmithBearerToken`, `langchain.langsmithOrganizationId` and `langchain.baseUrl` system properties
+// Or configures using the `LANGSMITH_API_KEY`, `LANGSMITH_TENANT_ID`, `LANGSMITH_BEARER_TOKEN`, `LANGSMITH_ORGANIZATION_ID` and `LANGCHAIN_BASE_URL` environment variables
+LangsmithClient client = LangsmithOkHttpClient.fromEnv();
+```
+
+Or manually:
+
+```java
+import com.langchain.smith.client.LangsmithClient;
+import com.langchain.smith.client.okhttp.LangsmithOkHttpClient;
+
+LangsmithClient client = LangsmithOkHttpClient.builder()
+ .apiKey("My API Key")
+ .tenantId("My Tenant ID")
+ .organizationId("My Organization ID")
+ .build();
+```
+
+Or using a combination of the two approaches:
+
+```java
+import com.langchain.smith.client.LangsmithClient;
+import com.langchain.smith.client.okhttp.LangsmithOkHttpClient;
+
+LangsmithClient client = LangsmithOkHttpClient.builder()
+ // Configures using the `langchain.langsmithApiKey`, `langchain.langsmithTenantId`, `langchain.langsmithBearerToken`, `langchain.langsmithOrganizationId` and `langchain.baseUrl` system properties
+ // Or configures using the `LANGSMITH_API_KEY`, `LANGSMITH_TENANT_ID`, `LANGSMITH_BEARER_TOKEN`, `LANGSMITH_ORGANIZATION_ID` and `LANGCHAIN_BASE_URL` environment variables
+ .fromEnv()
+ .apiKey("My API Key")
+ .build();
+```
+
+See this table for the available options:
+
+| Setter | System property | Environment variable | Required | Default value |
+| ---------------- | ----------------------------------- | --------------------------- | -------- | --------------------------- |
+| `apiKey` | `langchain.langsmithApiKey` | `LANGSMITH_API_KEY` | false | - |
+| `tenantId` | `langchain.langsmithTenantId` | `LANGSMITH_TENANT_ID` | false | - |
+| `bearerToken` | `langchain.langsmithBearerToken` | `LANGSMITH_BEARER_TOKEN` | false | - |
+| `organizationId` | `langchain.langsmithOrganizationId` | `LANGSMITH_ORGANIZATION_ID` | false | - |
+| `baseUrl` | `langchain.baseUrl` | `LANGCHAIN_BASE_URL` | true | `"https://api.example.com"` |
+
+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.langchain.smith.client.LangsmithClient;
+
+LangsmithClient 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 LangChain 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.
+
+For example, `client.sessions().dashboard(...)` should be called with an instance of `SessionDashboardParams`, and it will return an instance of `CustomChartsSection`.
+
+## Immutability
+
+Each class in the SDK has an associated [builder](https://blogs.oracle.com/javamagazine/post/exploring-joshua-blochs-builder-design-pattern-in-java) or factory method for constructing it.
+
+Each class is [immutable](https://docs.oracle.com/javase/tutorial/essential/concurrency/immutable.html) once constructed. If the class has an associated builder, then it has a `toBuilder()` method, which can be used to convert it back to a builder for making a modified copy.
+
+Because each class is immutable, builder modification will _never_ affect already built class instances.
+
+## Asynchronous execution
+
+The default client is synchronous. To switch to asynchronous execution, call the `async()` method:
+
+```java
+import com.langchain.smith.client.LangsmithClient;
+import com.langchain.smith.client.okhttp.LangsmithOkHttpClient;
+import com.langchain.smith.models.sessions.CustomChartsSection;
+import com.langchain.smith.models.sessions.CustomChartsSectionRequest;
+import com.langchain.smith.models.sessions.SessionDashboardParams;
+import java.util.concurrent.CompletableFuture;
+
+// Configures using the `langchain.langsmithApiKey`, `langchain.langsmithTenantId`, `langchain.langsmithBearerToken`, `langchain.langsmithOrganizationId` and `langchain.baseUrl` system properties
+// Or configures using the `LANGSMITH_API_KEY`, `LANGSMITH_TENANT_ID`, `LANGSMITH_BEARER_TOKEN`, `LANGSMITH_ORGANIZATION_ID` and `LANGCHAIN_BASE_URL` environment variables
+LangsmithClient client = LangsmithOkHttpClient.fromEnv();
+
+SessionDashboardParams params = SessionDashboardParams.builder()
+ .sessionId("REPLACE_ME")
+ .customChartsSectionRequest(CustomChartsSectionRequest.builder().build())
+ .build();
+CompletableFuture customChartsSection = client.async().sessions().dashboard(params);
+```
+
+Or create an asynchronous client from the beginning:
+
+```java
+import com.langchain.smith.client.LangsmithClientAsync;
+import com.langchain.smith.client.okhttp.LangsmithOkHttpClientAsync;
+import com.langchain.smith.models.sessions.CustomChartsSection;
+import com.langchain.smith.models.sessions.CustomChartsSectionRequest;
+import com.langchain.smith.models.sessions.SessionDashboardParams;
+import java.util.concurrent.CompletableFuture;
+
+// Configures using the `langchain.langsmithApiKey`, `langchain.langsmithTenantId`, `langchain.langsmithBearerToken`, `langchain.langsmithOrganizationId` and `langchain.baseUrl` system properties
+// Or configures using the `LANGSMITH_API_KEY`, `LANGSMITH_TENANT_ID`, `LANGSMITH_BEARER_TOKEN`, `LANGSMITH_ORGANIZATION_ID` and `LANGCHAIN_BASE_URL` environment variables
+LangsmithClientAsync client = LangsmithOkHttpClientAsync.fromEnv();
+
+SessionDashboardParams params = SessionDashboardParams.builder()
+ .sessionId("REPLACE_ME")
+ .customChartsSectionRequest(CustomChartsSectionRequest.builder().build())
+ .build();
+CompletableFuture customChartsSection = client.sessions().dashboard(params);
+```
+
+The asynchronous client supports the same options as the synchronous one, except most methods return `CompletableFuture`s.
+
+## File uploads
+
+The SDK defines methods that accept files.
+
+To upload a file, pass a [`Path`](https://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html):
+
+```java
+import com.langchain.smith.models.examples.Example;
+import com.langchain.smith.models.examples.ExampleUploadFromCsvParams;
+import java.nio.file.Paths;
+
+ExampleUploadFromCsvParams params = ExampleUploadFromCsvParams.builder()
+ .datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
+ .addInputKey("string")
+ .file(Paths.get("/path/to/file"))
+ .build();
+List examples = client.examples().uploadFromCsv(params);
+```
+
+Or an arbitrary [`InputStream`](https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html):
+
+```java
+import com.langchain.smith.models.examples.Example;
+import com.langchain.smith.models.examples.ExampleUploadFromCsvParams;
+import java.net.URL;
+
+ExampleUploadFromCsvParams params = ExampleUploadFromCsvParams.builder()
+ .datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
+ .addInputKey("string")
+ .file(new URL("https://example.com//path/to/file").openStream())
+ .build();
+List examples = client.examples().uploadFromCsv(params);
+```
+
+Or a `byte[]` array:
+
+```java
+import com.langchain.smith.models.examples.Example;
+import com.langchain.smith.models.examples.ExampleUploadFromCsvParams;
+
+ExampleUploadFromCsvParams params = ExampleUploadFromCsvParams.builder()
+ .datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
+ .addInputKey("string")
+ .file("content".getBytes())
+ .build();
+List examples = client.examples().uploadFromCsv(params);
+```
+
+Note that when passing a non-`Path` its filename is unknown so it will not be included in the request. To manually set a filename, pass a [`MultipartField`](langsmith-core/src/main/kotlin/com/langchain/smith/core/Values.kt):
+
+```java
+import com.langchain.smith.core.MultipartField;
+import com.langchain.smith.models.examples.Example;
+import com.langchain.smith.models.examples.ExampleUploadFromCsvParams;
+import java.io.InputStream;
+import java.net.URL;
+
+ExampleUploadFromCsvParams params = ExampleUploadFromCsvParams.builder()
+ .datasetId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
+ .addInputKey("string")
+ .file(MultipartField.builder()
+ .value(new URL("https://example.com//path/to/file").openStream())
+ .filename("/path/to/file")
+ .build())
+ .build();
+List examples = client.examples().uploadFromCsv(params);
+```
+
+## Raw responses
+
+The SDK defines methods that deserialize responses into instances of Java classes. However, these methods don't provide access to the response headers, status code, or the raw response body.
+
+To access this data, prefix any HTTP method call on a client or service with `withRawResponse()`:
+
+```java
+import com.langchain.smith.core.http.Headers;
+import com.langchain.smith.core.http.HttpResponseFor;
+import com.langchain.smith.models.sessions.CustomChartsSection;
+import com.langchain.smith.models.sessions.CustomChartsSectionRequest;
+import com.langchain.smith.models.sessions.SessionDashboardParams;
+
+SessionDashboardParams params = SessionDashboardParams.builder()
+ .sessionId("REPLACE_ME")
+ .customChartsSectionRequest(CustomChartsSectionRequest.builder().build())
+ .build();
+HttpResponseFor customChartsSection = client.sessions().withRawResponse().dashboard(params);
+
+int statusCode = customChartsSection.statusCode();
+Headers headers = customChartsSection.headers();
+```
+
+You can still deserialize the response into an instance of a Java class if needed:
+
+```java
+import com.langchain.smith.models.sessions.CustomChartsSection;
+
+CustomChartsSection parsedCustomChartsSection = customChartsSection.parse();
+```
+
+## Error handling
+
+The SDK throws custom unchecked exception types:
+
+- [`LangChainServiceException`](langsmith-core/src/main/kotlin/com/langchain/smith/errors/LangChainServiceException.kt): Base class for HTTP errors. See this table for which exception subclass is thrown for each HTTP status code:
+
+ | Status | Exception |
+ | ------ | ----------------------------------------------------------------------------------------------------------------------------- |
+ | 400 | [`BadRequestException`](langsmith-core/src/main/kotlin/com/langchain/smith/errors/BadRequestException.kt) |
+ | 401 | [`UnauthorizedException`](langsmith-core/src/main/kotlin/com/langchain/smith/errors/UnauthorizedException.kt) |
+ | 403 | [`PermissionDeniedException`](langsmith-core/src/main/kotlin/com/langchain/smith/errors/PermissionDeniedException.kt) |
+ | 404 | [`NotFoundException`](langsmith-core/src/main/kotlin/com/langchain/smith/errors/NotFoundException.kt) |
+ | 422 | [`UnprocessableEntityException`](langsmith-core/src/main/kotlin/com/langchain/smith/errors/UnprocessableEntityException.kt) |
+ | 429 | [`RateLimitException`](langsmith-core/src/main/kotlin/com/langchain/smith/errors/RateLimitException.kt) |
+ | 5xx | [`InternalServerException`](langsmith-core/src/main/kotlin/com/langchain/smith/errors/InternalServerException.kt) |
+ | others | [`UnexpectedStatusCodeException`](langsmith-core/src/main/kotlin/com/langchain/smith/errors/UnexpectedStatusCodeException.kt) |
+
+- [`LangChainIoException`](langsmith-core/src/main/kotlin/com/langchain/smith/errors/LangChainIoException.kt): I/O networking errors.
+
+- [`LangChainRetryableException`](langsmith-core/src/main/kotlin/com/langchain/smith/errors/LangChainRetryableException.kt): Generic error indicating a failure that could be retried by the client.
+
+- [`LangChainInvalidDataException`](langsmith-core/src/main/kotlin/com/langchain/smith/errors/LangChainInvalidDataException.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.
+
+- [`LangChainException`](langsmith-core/src/main/kotlin/com/langchain/smith/errors/LangChainException.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.
+
+## Logging
+
+The SDK uses the standard [OkHttp logging interceptor](https://github.com/square/okhttp/tree/master/okhttp-logging-interceptor).
+
+Enable logging by setting the `LANGCHAIN_LOG` environment variable to `info`:
+
+```sh
+$ export LANGCHAIN_LOG=info
+```
+
+Or to `debug` for more verbose logging:
+
+```sh
+$ export LANGCHAIN_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 `langsmith-core` is published with a [configuration file](langsmith-core/src/main/resources/META-INF/proguard/langsmith-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.
+
+The SDK throws an exception if it detects an incompatible Jackson version at runtime (e.g. if the default version was overridden in your Maven or Gradle config).
+
+If the SDK threw an exception, but you're _certain_ the version is compatible, then disable the version check using the `checkJacksonVersionCompatibility` on [`LangsmithOkHttpClient`](langsmith-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/LangsmithOkHttpClient.kt) or [`LangsmithOkHttpClientAsync`](langsmith-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/LangsmithOkHttpClientAsync.kt).
+
+> [!CAUTION]
+> We make no guarantee that the SDK works correctly when the Jackson version check is disabled.
+
+## Network options
+
+### Retries
+
+The SDK automatically retries 2 times by default, 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.
+
+To set a custom number of retries, configure the client using the `maxRetries` method:
+
+```java
+import com.langchain.smith.client.LangsmithClient;
+import com.langchain.smith.client.okhttp.LangsmithOkHttpClient;
+
+LangsmithClient client = LangsmithOkHttpClient.builder()
+ .fromEnv()
+ .maxRetries(4)
+ .build();
+```
+
+### Timeouts
+
+Requests time out after 1 minute by default.
+
+To set a custom timeout, configure the method call using the `timeout` method:
+
+```java
+import com.langchain.smith.models.sessions.CustomChartsSection;
+
+CustomChartsSection customChartsSection = client.sessions().dashboard(
+ params, RequestOptions.builder().timeout(Duration.ofSeconds(30)).build()
+);
+```
+
+Or configure the default for all method calls at the client level:
+
+```java
+import com.langchain.smith.client.LangsmithClient;
+import com.langchain.smith.client.okhttp.LangsmithOkHttpClient;
+import java.time.Duration;
+
+LangsmithClient client = LangsmithOkHttpClient.builder()
+ .fromEnv()
+ .timeout(Duration.ofSeconds(30))
+ .build();
+```
+
+### Proxies
+
+To route requests through a proxy, configure the client using the `proxy` method:
+
+```java
+import com.langchain.smith.client.LangsmithClient;
+import com.langchain.smith.client.okhttp.LangsmithOkHttpClient;
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+
+LangsmithClient client = LangsmithOkHttpClient.builder()
+ .fromEnv()
+ .proxy(new Proxy(
+ Proxy.Type.HTTP, new InetSocketAddress(
+ "https://example.com", 8080
+ )
+ ))
+ .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.langchain.smith.client.LangsmithClient;
+import com.langchain.smith.client.okhttp.LangsmithOkHttpClient;
+
+LangsmithClient client = LangsmithOkHttpClient.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:
+
+- `langsmith-core`
+ - Contains core SDK logic
+ - Does not depend on [OkHttp](https://square.github.io/okhttp)
+ - Exposes [`LangsmithClient`](langsmith-core/src/main/kotlin/com/langchain/smith/client/LangsmithClient.kt), [`LangsmithClientAsync`](langsmith-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientAsync.kt), [`LangsmithClientImpl`](langsmith-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientImpl.kt), and [`LangsmithClientAsyncImpl`](langsmith-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientAsyncImpl.kt), all of which can work with any HTTP client
+- `langsmith-client-okhttp`
+ - Depends on [OkHttp](https://square.github.io/okhttp)
+ - Exposes [`LangsmithOkHttpClient`](langsmith-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/LangsmithOkHttpClient.kt) and [`LangsmithOkHttpClientAsync`](langsmith-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/LangsmithOkHttpClientAsync.kt), which provide a way to construct [`LangsmithClientImpl`](langsmith-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientImpl.kt) and [`LangsmithClientAsyncImpl`](langsmith-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientAsyncImpl.kt), respectively, using OkHttp
+- `langsmith`
+ - Depends on and exposes the APIs of both `langsmith-core` and `langsmith-client-okhttp`
+ - Does not have its own logic
+
+This structure allows replacing the SDK's default HTTP client without pulling in unnecessary dependencies.
+
+#### Customized [`OkHttpClient`](https://square.github.io/okhttp/3.x/okhttp/okhttp3/OkHttpClient.html)
+
+> [!TIP]
+> Try the available [network options](#network-options) before replacing the default client.
+
+To use a customized `OkHttpClient`:
+
+1. Replace your [`langsmith` dependency](#installation) with `langsmith-core`
+2. Copy `langsmith-client-okhttp`'s [`OkHttpClient`](langsmith-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/OkHttpClient.kt) class into your code and customize it
+3. Construct [`LangsmithClientImpl`](langsmith-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientImpl.kt) or [`LangsmithClientAsyncImpl`](langsmith-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientAsyncImpl.kt), similarly to [`LangsmithOkHttpClient`](langsmith-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/LangsmithOkHttpClient.kt) or [`LangsmithOkHttpClientAsync`](langsmith-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/LangsmithOkHttpClientAsync.kt), using your customized client
+
+### Completely custom HTTP client
+
+To use a completely custom HTTP client:
+
+1. Replace your [`langsmith` dependency](#installation) with `langsmith-core`
+2. Write a class that implements the [`HttpClient`](langsmith-core/src/main/kotlin/com/langchain/smith/core/http/HttpClient.kt) interface
+3. Construct [`LangsmithClientImpl`](langsmith-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientImpl.kt) or [`LangsmithClientAsyncImpl`](langsmith-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientAsyncImpl.kt), similarly to [`LangsmithOkHttpClient`](langsmith-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/LangsmithOkHttpClient.kt) or [`LangsmithOkHttpClientAsync`](langsmith-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/LangsmithOkHttpClientAsync.kt), using your new client class
+
+## Undocumented API functionality
+
+The SDK is typed for convenient usage of the documented API. However, it also supports working with undocumented or not yet supported parts of the API.
+
+### Parameters
+
+To set undocumented parameters, call the `putAdditionalHeader`, `putAdditionalQueryParam`, or `putAdditionalBodyProperty` methods on any `Params` class:
+
+```java
+import com.langchain.smith.core.JsonValue;
+import com.langchain.smith.models.sessions.SessionDashboardParams;
+
+SessionDashboardParams params = SessionDashboardParams.builder()
+ .putAdditionalHeader("Secret-Header", "42")
+ .putAdditionalQueryParam("secret_query_param", "42")
+ .putAdditionalBodyProperty("secretProperty", JsonValue.from("42"))
+ .build();
+```
+
+These can be accessed on the built object later using the `_additionalHeaders()`, `_additionalQueryParams()`, and `_additionalBodyProperties()` methods.
+
+To set a documented parameter or property to an undocumented or not yet supported _value_, pass a [`JsonValue`](langsmith-core/src/main/kotlin/com/langchain/smith/core/Values.kt) object to its setter:
+
+```java
+import com.langchain.smith.models.sessions.CustomChartsSectionRequest;
+import com.langchain.smith.models.sessions.SessionDashboardParams;
+
+SessionDashboardParams params = SessionDashboardParams.builder()
+ .customChartsSectionRequest(CustomChartsSectionRequest.builder().build())
+ .build();
+```
+
+The most straightforward way to create a [`JsonValue`](langsmith-core/src/main/kotlin/com/langchain/smith/core/Values.kt) is using its `from(...)` method:
+
+```java
+import com.langchain.smith.core.JsonValue;
+import java.util.List;
+import java.util.Map;
+
+// Create primitive JSON values
+JsonValue nullValue = JsonValue.from(null);
+JsonValue booleanValue = JsonValue.from(true);
+JsonValue numberValue = JsonValue.from(42);
+JsonValue stringValue = JsonValue.from("Hello World!");
+
+// Create a JSON array value equivalent to `["Hello", "World"]`
+JsonValue arrayValue = JsonValue.from(List.of(
+ "Hello", "World"
+));
+
+// Create a JSON object value equivalent to `{ "a": 1, "b": 2 }`
+JsonValue objectValue = JsonValue.from(Map.of(
+ "a", 1,
+ "b", 2
+));
+
+// Create an arbitrarily nested JSON equivalent to:
+// {
+// "a": [1, 2],
+// "b": [3, 4]
+// }
+JsonValue complexValue = JsonValue.from(Map.of(
+ "a", List.of(
+ 1, 2
+ ),
+ "b", List.of(
+ 3, 4
+ )
+));
+```
+
+Normally a `Builder` class's `build` method will throw [`IllegalStateException`](https://docs.oracle.com/javase/8/docs/api/java/lang/IllegalStateException.html) if any required parameter or property is unset.
+
+To forcibly omit a required parameter or property, pass [`JsonMissing`](langsmith-core/src/main/kotlin/com/langchain/smith/core/Values.kt):
+
+```java
+import com.langchain.smith.core.JsonMissing;
+import com.langchain.smith.models.sessions.CustomChartsSectionRequest;
+import com.langchain.smith.models.sessions.SessionDashboardParams;
+
+SessionDashboardParams params = SessionDashboardParams.builder()
+ .customChartsSectionRequest(CustomChartsSectionRequest.builder().build())
+ .sessionId(JsonMissing.of())
+ .build();
+```
+
+### Response properties
+
+To access undocumented response properties, call the `_additionalProperties()` method:
+
+```java
+import com.langchain.smith.core.JsonValue;
+import java.util.Map;
+
+Map additionalProperties = client.sessions().dashboard(params)._additionalProperties();
+JsonValue secretPropertyValue = additionalProperties.get("secretProperty");
+
+String result = secretPropertyValue.accept(new JsonValue.Visitor<>() {
+ @Override
+ public String visitNull() {
+ return "It's null!";
+ }
+
+ @Override
+ public String visitBoolean(boolean value) {
+ return "It's a boolean!";
+ }
+
+ @Override
+ public String visitNumber(Number value) {
+ return "It's a number!";
+ }
+
+ // Other methods include `visitMissing`, `visitString`, `visitArray`, and `visitObject`
+ // The default implementation of each unimplemented method delegates to `visitDefault`, which throws by default, but can also be overridden
+});
+```
+
+To access a property's raw JSON value, which may be undocumented, call its `_` prefixed method:
+
+```java
+import com.langchain.smith.core.JsonField;
+import java.util.Optional;
+
+JsonField field = client.sessions().dashboard(params)._field();
+
+if (field.isMissing()) {
+ // The property is absent from the JSON response
+} else if (field.isNull()) {
+ // The property was set to literal null
+} else {
+ // Check if value was provided as a string
+ // Other methods include `asNumber()`, `asBoolean()`, etc.
+ Optional jsonString = field.asString();
+
+ // Try to deserialize into a custom type
+ MyClass myObject = field.asUnknown().orElseThrow().convert(MyClass.class);
+}
+```
+
+### Response validation
+
+In rare cases, the API may return a response that doesn't match the expected type. For example, the SDK may expect a property to contain a `String`, but the API could return something else.
+
+By default, the SDK will not throw an exception in this case. It will throw [`LangChainInvalidDataException`](langsmith-core/src/main/kotlin/com/langchain/smith/errors/LangChainInvalidDataException.kt) only if you directly access the property.
+
+If you would prefer to check that the response is completely well-typed upfront, then either call `validate()`:
+
+```java
+import com.langchain.smith.models.sessions.CustomChartsSection;
+
+CustomChartsSection customChartsSection = client.sessions().dashboard(params).validate();
+```
+
+Or configure the method call to validate the response using the `responseValidation` method:
+
+```java
+import com.langchain.smith.models.sessions.CustomChartsSection;
+
+CustomChartsSection customChartsSection = client.sessions().dashboard(
+ params, RequestOptions.builder().responseValidation(true).build()
+);
+```
+
+Or configure the default for all method calls at the client level:
+
+```java
+import com.langchain.smith.client.LangsmithClient;
+import com.langchain.smith.client.okhttp.LangsmithOkHttpClient;
+
+LangsmithClient client = LangsmithOkHttpClient.builder()
+ .fromEnv()
+ .responseValidation(true)
+ .build();
+```
+
+## FAQ
+
+### Why don't you use plain `enum` classes?
+
+Java `enum` classes are not trivially [forwards compatible](https://www.stainless.com/blog/making-java-enums-forwards-compatible). Using them in the SDK could cause runtime exceptions if the API is updated to respond with a new enum value.
+
+### Why do you represent fields using `JsonField` instead of just plain `T`?
+
+Using `JsonField` enables a few features:
+
+- Allowing usage of [undocumented API functionality](#undocumented-api-functionality)
+- Lazily [validating the API response against the expected shape](#response-validation)
+- Representing absent vs explicitly null values
+
+### Why don't you use [`data` classes](https://kotlinlang.org/docs/data-classes.html)?
+
+It is not [backwards compatible to add new fields to a data class](https://kotlinlang.org/docs/api-guidelines-backward-compatibility.html#avoid-using-data-classes-in-your-api) and we don't want to introduce a breaking change every time we add a field to a class.
+
+### Why don't you use checked exceptions?
+
+Checked exceptions are widely considered a mistake in the Java programming language. In fact, they were omitted from Kotlin for this reason.
+
+Checked exceptions:
+
+- Are verbose to handle
+- Encourage error handling at the wrong level of abstraction, where nothing can be done about the error
+- Are tedious to propagate due to the [function coloring problem](https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function)
+- Don't play well with lambdas (also due to the function coloring problem)
+
+## Semantic versioning
+
+This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
+
+1. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_
+2. Changes that we do not expect to impact the vast majority of users in practice.
+
+We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
+
+We are keen for your feedback; please open an [issue](https://www.github.com/stainless-sdks/langsmith-api-java/issues) with questions, bugs, or suggestions.
diff --git a/SECURITY.md b/SECURITY.md
new file mode 100644
index 00000000..628142ee
--- /dev/null
+++ b/SECURITY.md
@@ -0,0 +1,23 @@
+# Security Policy
+
+## Reporting Security Issues
+
+This SDK is generated by [Stainless Software Inc](http://stainless.com). Stainless takes security seriously, and encourages you to report any security vulnerability promptly so that appropriate action can be taken.
+
+To report a security issue, please contact the Stainless team at security@stainless.com.
+
+## Responsible Disclosure
+
+We appreciate the efforts of security researchers and individuals who help us maintain the security of
+SDKs we generate. If you believe you have found a security vulnerability, please adhere to responsible
+disclosure practices by allowing us a reasonable amount of time to investigate and address the issue
+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 LangChain, please follow the respective company's security reporting guidelines.
+
+---
+
+Thank you for helping us keep the SDKs and systems they interact with secure.
diff --git a/build.gradle.kts b/build.gradle.kts
new file mode 100644
index 00000000..e6f5e623
--- /dev/null
+++ b/build.gradle.kts
@@ -0,0 +1,49 @@
+plugins {
+ id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
+ id("org.jetbrains.dokka") version "2.0.0"
+}
+
+repositories {
+ mavenCentral()
+}
+
+allprojects {
+ group = "com.langchain.smith"
+ version = "0.0.1"
+}
+
+subprojects {
+ // These are populated with dependencies by `buildSrc` scripts.
+ tasks.register("format") {
+ group = "Verification"
+ description = "Formats all source files."
+ }
+ tasks.register("lint") {
+ group = "Verification"
+ description = "Verifies all source files are formatted."
+ }
+ apply(plugin = "org.jetbrains.dokka")
+}
+
+subprojects {
+ apply(plugin = "org.jetbrains.dokka")
+}
+
+// Avoid race conditions between `dokkaJavadocCollector` and `dokkaJavadocJar` tasks
+tasks.named("dokkaJavadocCollector").configure {
+ subprojects.flatMap { it.tasks }
+ .filter { it.project.name != "langsmith" && it.name == "dokkaJavadocJar" }
+ .forEach { mustRunAfter(it) }
+}
+
+nexusPublishing {
+ repositories {
+ sonatype {
+ nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
+ snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
+
+ username.set(System.getenv("SONATYPE_USERNAME"))
+ password.set(System.getenv("SONATYPE_PASSWORD"))
+ }
+ }
+}
diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts
new file mode 100644
index 00000000..0b141353
--- /dev/null
+++ b/buildSrc/build.gradle.kts
@@ -0,0 +1,12 @@
+plugins {
+ `kotlin-dsl`
+ kotlin("jvm") version "1.9.20"
+}
+
+repositories {
+ gradlePluginPortal()
+}
+
+dependencies {
+ implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.20")
+}
diff --git a/buildSrc/src/main/kotlin/langchain.java.gradle.kts b/buildSrc/src/main/kotlin/langchain.java.gradle.kts
new file mode 100644
index 00000000..81d5d32b
--- /dev/null
+++ b/buildSrc/src/main/kotlin/langchain.java.gradle.kts
@@ -0,0 +1,136 @@
+import org.gradle.api.tasks.testing.logging.TestExceptionFormat
+
+plugins {
+ `java-library`
+}
+
+repositories {
+ mavenCentral()
+}
+
+configure {
+ withJavadocJar()
+ withSourcesJar()
+}
+
+java {
+ toolchain {
+ languageVersion.set(JavaLanguageVersion.of(21))
+ }
+
+ sourceCompatibility = JavaVersion.VERSION_1_8
+ targetCompatibility = JavaVersion.VERSION_1_8
+}
+
+tasks.withType().configureEach {
+ options.compilerArgs.add("-Werror")
+ options.release.set(8)
+}
+
+tasks.named("javadocJar") {
+ setZip64(true)
+}
+
+tasks.named("jar") {
+ manifest {
+ attributes(mapOf(
+ "Implementation-Title" to project.name,
+ "Implementation-Version" to project.version
+ ))
+ }
+}
+
+tasks.withType().configureEach {
+ useJUnitPlatform()
+
+ // Run tests in parallel to some degree.
+ maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).coerceAtLeast(1)
+ forkEvery = 100
+
+ testLogging {
+ exceptionFormat = TestExceptionFormat.FULL
+ }
+}
+
+val palantir by configurations.creating
+dependencies {
+ palantir("com.palantir.javaformat:palantir-java-format:2.73.0")
+}
+
+fun registerPalantir(
+ name: String,
+ description: String,
+) {
+ val javaName = "${name}Java"
+ tasks.register(javaName) {
+ group = "Verification"
+ this.description = description
+
+ classpath = palantir
+ mainClass = "com.palantir.javaformat.java.Main"
+
+ // Avoid an `IllegalAccessError` on Java 9+.
+ jvmArgs(
+ "--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
+ "--add-exports", "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
+ "--add-exports", "jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
+ "--add-exports", "jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
+ "--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
+ )
+
+ // Use paths relative to the current module.
+ val argumentFile =
+ project.layout.buildDirectory.file("palantir-$name-args.txt").get().asFile
+ val lastRunTimeFile =
+ project.layout.buildDirectory.file("palantir-$name-last-run.txt").get().asFile
+
+ // Read the time when this task was last executed for this module (if ever).
+ val lastRunTime = lastRunTimeFile.takeIf { it.exists() }?.readText()?.toLongOrNull() ?: 0L
+
+ // Use a `fileTree` relative to the module's source directory.
+ val javaFiles = project.fileTree("src") { include("**/*.java") }
+
+ // Determine if any files need to be formatted or linted and continue only if there is at least
+ // one file.
+ onlyIf { javaFiles.any { it.lastModified() > lastRunTime } }
+
+ inputs.files(javaFiles)
+
+ doFirst {
+ // Create the argument file and set the preferred formatting style.
+ argumentFile.parentFile.mkdirs()
+ argumentFile.writeText("--palantir\n")
+
+ if (name == "lint") {
+ // For lint, do a dry run, so no files are modified. Set the exit code to 1 (instead of
+ // the default 0) if any files need to be formatted, indicating that linting has failed.
+ argumentFile.appendText("--dry-run\n")
+ argumentFile.appendText("--set-exit-if-changed\n")
+ } else {
+ // `--dry-run` and `--replace` (for in-place formatting) are mutually exclusive.
+ argumentFile.appendText("--replace\n")
+ }
+
+ // Write the modified files to the argument file.
+ javaFiles.filter { it.lastModified() > lastRunTime }
+ .forEach { argumentFile.appendText("${it.absolutePath}\n") }
+ }
+
+ doLast {
+ // Record the last execution time for later up-to-date checking.
+ lastRunTimeFile.writeText(System.currentTimeMillis().toString())
+ }
+
+ // Pass the argument file using the @ symbol
+ args = listOf("@${argumentFile.absolutePath}")
+
+ outputs.upToDateWhen { javaFiles.none { it.lastModified() > lastRunTime } }
+ }
+
+ tasks.named(name) {
+ dependsOn(tasks.named(javaName))
+ }
+}
+
+registerPalantir(name = "format", description = "Formats all Java source files.")
+registerPalantir(name = "lint", description = "Verifies all Java source files are formatted.")
diff --git a/buildSrc/src/main/kotlin/langchain.kotlin.gradle.kts b/buildSrc/src/main/kotlin/langchain.kotlin.gradle.kts
new file mode 100644
index 00000000..81cad354
--- /dev/null
+++ b/buildSrc/src/main/kotlin/langchain.kotlin.gradle.kts
@@ -0,0 +1,106 @@
+import org.jetbrains.kotlin.gradle.dsl.JvmTarget
+import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
+
+plugins {
+ id("langchain.java")
+ kotlin("jvm")
+}
+
+repositories {
+ mavenCentral()
+}
+
+kotlin {
+ jvmToolchain {
+ languageVersion.set(JavaLanguageVersion.of(21))
+ }
+
+ compilerOptions {
+ freeCompilerArgs = listOf(
+ "-Xjvm-default=all",
+ "-Xjdk-release=1.8",
+ // Suppress deprecation warnings because we may still reference and test deprecated members.
+ // TODO: Replace with `-Xsuppress-warning=DEPRECATION` once we use Kotlin compiler 2.1.0+.
+ "-nowarn",
+ )
+ jvmTarget.set(JvmTarget.JVM_1_8)
+ languageVersion.set(KotlinVersion.KOTLIN_1_8)
+ apiVersion.set(KotlinVersion.KOTLIN_1_8)
+ coreLibrariesVersion = "1.8.0"
+ }
+}
+
+tasks.withType().configureEach {
+ systemProperty("junit.jupiter.execution.parallel.enabled", true)
+ systemProperty("junit.jupiter.execution.parallel.mode.default", "concurrent")
+}
+
+val ktfmt by configurations.creating
+dependencies {
+ ktfmt("com.facebook:ktfmt:0.56")
+}
+
+fun registerKtfmt(
+ name: String,
+ description: String,
+) {
+ val kotlinName = "${name}Kotlin"
+ tasks.register(kotlinName) {
+ group = "Verification"
+ this.description = description
+
+ classpath = ktfmt
+ mainClass = "com.facebook.ktfmt.cli.Main"
+
+ // Use paths relative to the current module.
+ val argumentFile = project.layout.buildDirectory.file("ktfmt-$name-args.txt").get().asFile
+ val lastRunTimeFile =
+ project.layout.buildDirectory.file("ktfmt-$name-last-run.txt").get().asFile
+
+ // Read the time when this task was last executed for this module (if ever).
+ val lastRunTime = lastRunTimeFile.takeIf { it.exists() }?.readText()?.toLongOrNull() ?: 0L
+
+ // Use a `fileTree` relative to the module's source directory.
+ val kotlinFiles = project.fileTree("src") { include("**/*.kt") }
+
+ // Determine if any files need to be formatted or linted and continue only if there is at least
+ // one file (otherwise Ktfmt will fail).
+ onlyIf { kotlinFiles.any { it.lastModified() > lastRunTime } }
+
+ inputs.files(kotlinFiles)
+
+ doFirst {
+ // Create the argument file and set the preferred formatting style.
+ argumentFile.parentFile.mkdirs()
+ argumentFile.writeText("--kotlinlang-style\n")
+
+ if (name == "lint") {
+ // For lint, do a dry run, so no files are modified. Set the exit code to 1 (instead of
+ // the default 0) if any files need to be formatted, indicating that linting has failed.
+ argumentFile.appendText("--dry-run\n")
+ argumentFile.appendText("--set-exit-if-changed\n")
+ }
+
+ // Write the modified files to the argument file.
+ kotlinFiles.filter { it.lastModified() > lastRunTime }
+ .forEach { argumentFile.appendText("${it.absolutePath}\n") }
+ }
+
+ doLast {
+ // Record the last execution time for later up-to-date checking.
+ lastRunTimeFile.writeText(System.currentTimeMillis().toString())
+ }
+
+ // Pass the argument file using the @ symbol
+ args = listOf("@${argumentFile.absolutePath}")
+
+ outputs.upToDateWhen { kotlinFiles.none { it.lastModified() > lastRunTime } }
+ }
+
+ tasks.named(name) {
+ dependsOn(tasks.named(kotlinName))
+ }
+}
+
+registerKtfmt(name = "format", description = "Formats all Kotlin source files.")
+registerKtfmt(name = "lint", description = "Verifies all Kotlin source files are formatted.")
diff --git a/buildSrc/src/main/kotlin/langchain.publish.gradle.kts b/buildSrc/src/main/kotlin/langchain.publish.gradle.kts
new file mode 100644
index 00000000..e1777a54
--- /dev/null
+++ b/buildSrc/src/main/kotlin/langchain.publish.gradle.kts
@@ -0,0 +1,60 @@
+plugins {
+ `maven-publish`
+ signing
+}
+
+configure {
+ publications {
+ register("maven") {
+ from(components["java"])
+
+ pom {
+ name.set("LangSmith")
+ description.set("The LangSmith API is used to programmatically create and manage LangSmith\nresources.\n\n## Host\n\nhttps://api.smith.langchain.com\n\n## Authentication\n\nTo authenticate with the LangSmith API, set the `X-Api-Key` header to a valid\n[LangSmith API key](https://docs.langchain.com/langsmith/create-account-api-key#create-an-api-key).")
+ url.set("https://www.github.com/stainless-sdks/langsmith-api-java")
+
+ licenses {
+ license {
+ name.set("Apache-2.0")
+ }
+ }
+
+ developers {
+ developer {
+ name.set("LangChain")
+ }
+ }
+
+ scm {
+ connection.set("scm:git:git://github.com/stainless-sdks/langsmith-api-java.git")
+ developerConnection.set("scm:git:git://github.com/stainless-sdks/langsmith-api-java.git")
+ url.set("https://github.com/stainless-sdks/langsmith-api-java")
+ }
+
+ versionMapping {
+ allVariants {
+ fromResolutionResult()
+ }
+ }
+ }
+ }
+ }
+}
+
+signing {
+ val signingKeyId = System.getenv("GPG_SIGNING_KEY_ID")?.ifBlank { null }
+ val signingKey = System.getenv("GPG_SIGNING_KEY")?.ifBlank { null }
+ val signingPassword = System.getenv("GPG_SIGNING_PASSWORD")?.ifBlank { null }
+ if (signingKey != null && signingPassword != null) {
+ useInMemoryPgpKeys(
+ signingKeyId,
+ signingKey,
+ signingPassword,
+ )
+ sign(publishing.publications["maven"])
+ }
+}
+
+tasks.named("publish") {
+ dependsOn(":closeAndReleaseSonatypeStagingRepository")
+}
diff --git a/gradle.properties b/gradle.properties
new file mode 100644
index 00000000..6680f9ce
--- /dev/null
+++ b/gradle.properties
@@ -0,0 +1,18 @@
+org.gradle.caching=true
+org.gradle.configuration-cache=true
+org.gradle.parallel=true
+org.gradle.daemon=false
+# These options improve our compilation and test performance. They are inherited by the Kotlin daemon.
+org.gradle.jvmargs=\
+ -Xms2g \
+ -Xmx8g \
+ -XX:+UseParallelGC \
+ -XX:InitialCodeCacheSize=256m \
+ -XX:ReservedCodeCacheSize=1G \
+ -XX:MetaspaceSize=512m \
+ -XX:MaxMetaspaceSize=2G \
+ -XX:TieredStopAtLevel=1 \
+ -XX:GCTimeRatio=4 \
+ -XX:CICompilerCount=4 \
+ -XX:+OptimizeStringConcat \
+ -XX:+UseStringDeduplication
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 00000000..a4b76b95
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 00000000..cea7a793
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,7 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
+networkTimeout=10000
+validateDistributionUrl=true
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
new file mode 100755
index 00000000..f3b75f3b
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,251 @@
+#!/bin/sh
+
+#
+# Copyright © 2015-2021 the original authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+
+##############################################################################
+#
+# Gradle start up script for POSIX generated by Gradle.
+#
+# Important for running:
+#
+# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
+# noncompliant, but you have some other compliant shell such as ksh or
+# bash, then to run this script, type that shell name before the whole
+# command line, like:
+#
+# ksh Gradle
+#
+# Busybox and similar reduced shells will NOT work, because this script
+# requires all of these POSIX shell features:
+# * functions;
+# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+# * compound commands having a testable exit status, especially «case»;
+# * various built-in commands including «command», «set», and «ulimit».
+#
+# Important for patching:
+#
+# (2) This script targets any POSIX shell, so it avoids extensions provided
+# by Bash, Ksh, etc; in particular arrays are avoided.
+#
+# The "traditional" practice of packing multiple parameters into a
+# space-separated string is a well documented source of bugs and security
+# problems, so this is (mostly) avoided, by progressively accumulating
+# options in "$@", and eventually passing that to Java.
+#
+# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
+# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
+# see the in-line comments for details.
+#
+# There are tweaks for specific operating systems such as AIX, CygWin,
+# Darwin, MinGW, and NonStop.
+#
+# (3) This script is generated from the Groovy template
+# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+# within the Gradle project.
+#
+# You can find Gradle at https://github.com/gradle/gradle/.
+#
+##############################################################################
+
+# Attempt to set APP_HOME
+
+# Resolve links: $0 may be a link
+app_path=$0
+
+# Need this for daisy-chained symlinks.
+while
+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
+ [ -h "$app_path" ]
+do
+ ls=$( ls -ld "$app_path" )
+ link=${ls#*' -> '}
+ case $link in #(
+ /*) app_path=$link ;; #(
+ *) app_path=$APP_HOME$link ;;
+ esac
+done
+
+# This is normally unused
+# shellcheck disable=SC2034
+APP_BASE_NAME=${0##*/}
+# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
+APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD=maximum
+
+warn () {
+ echo "$*"
+} >&2
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+} >&2
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "$( uname )" in #(
+ CYGWIN* ) cygwin=true ;; #(
+ Darwin* ) darwin=true ;; #(
+ MSYS* | MINGW* ) msys=true ;; #(
+ NONSTOP* ) nonstop=true ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD=$JAVA_HOME/jre/sh/java
+ else
+ JAVACMD=$JAVA_HOME/bin/java
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD=java
+ if ! command -v java >/dev/null 2>&1
+ then
+ die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+fi
+
+# Increase the maximum file descriptors if we can.
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+ case $MAX_FD in #(
+ max*)
+ # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ MAX_FD=$( ulimit -H -n ) ||
+ warn "Could not query maximum file descriptor limit"
+ esac
+ case $MAX_FD in #(
+ '' | soft) :;; #(
+ *)
+ # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ ulimit -n "$MAX_FD" ||
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
+ esac
+fi
+
+# Collect all arguments for the java command, stacking in reverse order:
+# * args from the command line
+# * the main class name
+# * -classpath
+# * -D...appname settings
+# * --module-path (only if needed)
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if "$cygwin" || "$msys" ; then
+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+ CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+ JAVACMD=$( cygpath --unix "$JAVACMD" )
+
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ for arg do
+ if
+ case $arg in #(
+ -*) false ;; # don't mess with options #(
+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
+ [ -e "$t" ] ;; #(
+ *) false ;;
+ esac
+ then
+ arg=$( cygpath --path --ignore --mixed "$arg" )
+ fi
+ # Roll the args list around exactly as many times as the number of
+ # args, so each arg winds up back in the position where it started, but
+ # possibly modified.
+ #
+ # NB: a `for` loop captures its iteration list before it begins, so
+ # changing the positional parameters here affects neither the number of
+ # iterations, nor the values presented in `arg`.
+ shift # remove old arg
+ set -- "$@" "$arg" # push replacement arg
+ done
+fi
+
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Collect all arguments for the java command:
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
+# and any embedded shellness will be escaped.
+# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
+# treated as '${Hostname}' itself on the command line.
+
+set -- \
+ "-Dorg.gradle.appname=$APP_BASE_NAME" \
+ -classpath "$CLASSPATH" \
+ org.gradle.wrapper.GradleWrapperMain \
+ "$@"
+
+# Stop when "xargs" is not available.
+if ! command -v xargs >/dev/null 2>&1
+then
+ die "xargs is not available"
+fi
+
+# Use "xargs" to parse quoted args.
+#
+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
+#
+# In Bash we could simply go:
+#
+# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
+# set -- "${ARGS[@]}" "$@"
+#
+# but POSIX shell has neither arrays nor command substitution, so instead we
+# post-process each arg (as a line of input to sed) to backslash-escape any
+# character that might be a shell metacharacter, then use eval to reverse
+# that process (while maintaining the separation between arguments), and wrap
+# the whole thing up as a single "set" statement.
+#
+# This will of course break if any of these variables contains a newline or
+# an unmatched quote.
+#
+
+eval "set -- $(
+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
+ xargs -n1 |
+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
+ tr '\n' ' '
+ )" '"$@"'
+
+exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 00000000..9d21a218
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,94 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+@rem SPDX-License-Identifier: Apache-2.0
+@rem
+
+@if "%DEBUG%"=="" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%"=="" set DIRNAME=.
+@rem This is normally unused
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if %ERRORLEVEL% equ 0 goto execute
+
+echo. 1>&2
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo. 1>&2
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if %ERRORLEVEL% equ 0 goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+set EXIT_CODE=%ERRORLEVEL%
+if %EXIT_CODE% equ 0 set EXIT_CODE=1
+if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
+exit /b %EXIT_CODE%
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/langsmith-api-java-example/build.gradle.kts b/langsmith-api-java-example/build.gradle.kts
new file mode 100644
index 00000000..4c15ab77
--- /dev/null
+++ b/langsmith-api-java-example/build.gradle.kts
@@ -0,0 +1,28 @@
+plugins {
+ id("langsmith-api.java")
+ application
+}
+
+repositories {
+ mavenCentral()
+}
+
+dependencies {
+ implementation(project(":langsmith-api-java"))
+}
+
+tasks.withType().configureEach {
+ // Allow using more modern APIs, like `List.of` and `Map.of`, in examples.
+ options.release.set(9)
+}
+
+application {
+ // Use `./gradlew :langsmith-api-java-example:run` to run `Main`
+ // Use `./gradlew :langsmith-api-java-example:run -Pexample=Something` to run `SomethingExample`
+ mainClass = "com.langsmith_api.api.example.${
+ if (project.hasProperty("example"))
+ "${project.property("example")}Example"
+ else
+ "Main"
+ }"
+}
diff --git a/langsmith-api-java-lib/.keep b/langsmith-api-java-lib/.keep
new file mode 100644
index 00000000..5e2c99fd
--- /dev/null
+++ b/langsmith-api-java-lib/.keep
@@ -0,0 +1,4 @@
+File generated from our OpenAPI spec by Stainless.
+
+This directory can be used to store custom files to expand the SDK.
+It is ignored by Stainless code generation and its content (other than this keep file) won't be touched.
\ No newline at end of file
diff --git a/langsmith-client-okhttp/build.gradle.kts b/langsmith-client-okhttp/build.gradle.kts
new file mode 100644
index 00000000..99e89474
--- /dev/null
+++ b/langsmith-client-okhttp/build.gradle.kts
@@ -0,0 +1,14 @@
+plugins {
+ id("langchain.kotlin")
+ id("langchain.publish")
+}
+
+dependencies {
+ api(project(":langsmith-core"))
+
+ implementation("com.squareup.okhttp3:okhttp:4.12.0")
+ implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")
+
+ testImplementation(kotlin("test"))
+ testImplementation("org.assertj:assertj-core:3.25.3")
+}
diff --git a/langsmith-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/LangsmithOkHttpClient.kt b/langsmith-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/LangsmithOkHttpClient.kt
new file mode 100644
index 00000000..aa5c68c7
--- /dev/null
+++ b/langsmith-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/LangsmithOkHttpClient.kt
@@ -0,0 +1,332 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.langchain.smith.client.okhttp
+
+import com.fasterxml.jackson.databind.json.JsonMapper
+import com.langchain.smith.client.LangsmithClient
+import com.langchain.smith.client.LangsmithClientImpl
+import com.langchain.smith.core.ClientOptions
+import com.langchain.smith.core.Sleeper
+import com.langchain.smith.core.Timeout
+import com.langchain.smith.core.http.Headers
+import com.langchain.smith.core.http.HttpClient
+import com.langchain.smith.core.http.QueryParams
+import com.langchain.smith.core.jsonMapper
+import java.net.Proxy
+import java.time.Clock
+import java.time.Duration
+import java.util.Optional
+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 [LangsmithClient] with [OkHttpClient] as the
+ * underlying [HttpClient].
+ */
+class LangsmithOkHttpClient private constructor() {
+
+ companion object {
+
+ /** Returns a mutable builder for constructing an instance of [LangsmithClient]. */
+ @JvmStatic fun builder() = Builder()
+
+ /**
+ * Returns a client configured using system properties and environment variables.
+ *
+ * @see ClientOptions.Builder.fromEnv
+ */
+ @JvmStatic fun fromEnv(): LangsmithClient = builder().fromEnv().build()
+ }
+
+ /** A builder for [LangsmithOkHttpClient]. */
+ class Builder internal constructor() {
+
+ private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
+ 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
+ }
+
+ /** 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
+ * 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 {
+ clientOptions.checkJacksonVersionCompatibility(checkJacksonVersionCompatibility)
+ }
+
+ /**
+ * The Jackson JSON mapper to use for serializing and deserializing JSON.
+ *
+ * Defaults to [com.langchain.smith.core.jsonMapper]. The default is usually sufficient and
+ * rarely needs to be overridden.
+ */
+ fun jsonMapper(jsonMapper: JsonMapper) = apply { clientOptions.jsonMapper(jsonMapper) }
+
+ /**
+ * The interface to use for delaying execution, like during retries.
+ *
+ * This is primarily useful for using fake delays in tests.
+ *
+ * Defaults to real execution delays.
+ *
+ * This class takes ownership of the sleeper and closes it when closed.
+ */
+ fun sleeper(sleeper: Sleeper) = apply { clientOptions.sleeper(sleeper) }
+
+ /**
+ * 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.example.com`.
+ */
+ 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 tenantId(tenantId: String?) = apply { clientOptions.tenantId(tenantId) }
+
+ /** Alias for calling [Builder.tenantId] with `tenantId.orElse(null)`. */
+ fun tenantId(tenantId: Optional) = tenantId(tenantId.getOrNull())
+
+ /**
+ * Bearer tokens are used to authenticate from the UI. Must also specify x-tenant-id or
+ * x-organization-id (for org scoped apis).
+ */
+ fun bearerToken(bearerToken: String?) = apply { clientOptions.bearerToken(bearerToken) }
+
+ /** Alias for calling [Builder.bearerToken] with `bearerToken.orElse(null)`. */
+ fun bearerToken(bearerToken: Optional) = bearerToken(bearerToken.getOrNull())
+
+ fun organizationId(organizationId: String?) = apply {
+ clientOptions.organizationId(organizationId)
+ }
+
+ /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */
+ fun organizationId(organizationId: Optional) =
+ organizationId(organizationId.getOrNull())
+
+ fun headers(headers: Headers) = apply { clientOptions.headers(headers) }
+
+ fun headers(headers: Map>) = apply {
+ clientOptions.headers(headers)
+ }
+
+ fun putHeader(name: String, value: String) = apply { clientOptions.putHeader(name, value) }
+
+ fun putHeaders(name: String, values: Iterable) = apply {
+ clientOptions.putHeaders(name, values)
+ }
+
+ fun putAllHeaders(headers: Headers) = apply { clientOptions.putAllHeaders(headers) }
+
+ fun putAllHeaders(headers: Map>) = apply {
+ clientOptions.putAllHeaders(headers)
+ }
+
+ fun replaceHeaders(name: String, value: String) = apply {
+ clientOptions.replaceHeaders(name, value)
+ }
+
+ fun replaceHeaders(name: String, values: Iterable) = apply {
+ clientOptions.replaceHeaders(name, values)
+ }
+
+ fun replaceAllHeaders(headers: Headers) = apply { clientOptions.replaceAllHeaders(headers) }
+
+ fun replaceAllHeaders(headers: Map>) = apply {
+ clientOptions.replaceAllHeaders(headers)
+ }
+
+ fun removeHeaders(name: String) = apply { clientOptions.removeHeaders(name) }
+
+ fun removeAllHeaders(names: Set) = apply { clientOptions.removeAllHeaders(names) }
+
+ fun queryParams(queryParams: QueryParams) = apply { clientOptions.queryParams(queryParams) }
+
+ fun queryParams(queryParams: Map>) = apply {
+ clientOptions.queryParams(queryParams)
+ }
+
+ fun putQueryParam(key: String, value: String) = apply {
+ clientOptions.putQueryParam(key, value)
+ }
+
+ fun putQueryParams(key: String, values: Iterable) = apply {
+ clientOptions.putQueryParams(key, values)
+ }
+
+ fun putAllQueryParams(queryParams: QueryParams) = apply {
+ clientOptions.putAllQueryParams(queryParams)
+ }
+
+ fun putAllQueryParams(queryParams: Map>) = apply {
+ clientOptions.putAllQueryParams(queryParams)
+ }
+
+ fun replaceQueryParams(key: String, value: String) = apply {
+ clientOptions.replaceQueryParams(key, value)
+ }
+
+ fun replaceQueryParams(key: String, values: Iterable) = apply {
+ clientOptions.replaceQueryParams(key, values)
+ }
+
+ fun replaceAllQueryParams(queryParams: QueryParams) = apply {
+ clientOptions.replaceAllQueryParams(queryParams)
+ }
+
+ fun replaceAllQueryParams(queryParams: Map>) = apply {
+ clientOptions.replaceAllQueryParams(queryParams)
+ }
+
+ fun removeQueryParams(key: String) = apply { clientOptions.removeQueryParams(key) }
+
+ fun removeAllQueryParams(keys: Set) = apply {
+ clientOptions.removeAllQueryParams(keys)
+ }
+
+ /**
+ * Updates configuration using system properties and environment variables.
+ *
+ * @see ClientOptions.Builder.fromEnv
+ */
+ fun fromEnv() = apply { clientOptions.fromEnv() }
+
+ /**
+ * Returns an immutable instance of [LangsmithClient].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ */
+ fun build(): LangsmithClient =
+ LangsmithClientImpl(
+ clientOptions
+ .httpClient(
+ OkHttpClient.builder()
+ .timeout(clientOptions.timeout())
+ .proxy(proxy)
+ .sslSocketFactory(sslSocketFactory)
+ .trustManager(trustManager)
+ .hostnameVerifier(hostnameVerifier)
+ .build()
+ )
+ .build()
+ )
+ }
+}
diff --git a/langsmith-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/LangsmithOkHttpClientAsync.kt b/langsmith-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/LangsmithOkHttpClientAsync.kt
new file mode 100644
index 00000000..b85533eb
--- /dev/null
+++ b/langsmith-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/LangsmithOkHttpClientAsync.kt
@@ -0,0 +1,332 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.langchain.smith.client.okhttp
+
+import com.fasterxml.jackson.databind.json.JsonMapper
+import com.langchain.smith.client.LangsmithClientAsync
+import com.langchain.smith.client.LangsmithClientAsyncImpl
+import com.langchain.smith.core.ClientOptions
+import com.langchain.smith.core.Sleeper
+import com.langchain.smith.core.Timeout
+import com.langchain.smith.core.http.Headers
+import com.langchain.smith.core.http.HttpClient
+import com.langchain.smith.core.http.QueryParams
+import com.langchain.smith.core.jsonMapper
+import java.net.Proxy
+import java.time.Clock
+import java.time.Duration
+import java.util.Optional
+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 [LangsmithClientAsync] with [OkHttpClient] as the
+ * underlying [HttpClient].
+ */
+class LangsmithOkHttpClientAsync private constructor() {
+
+ companion object {
+
+ /** Returns a mutable builder for constructing an instance of [LangsmithClientAsync]. */
+ @JvmStatic fun builder() = Builder()
+
+ /**
+ * Returns a client configured using system properties and environment variables.
+ *
+ * @see ClientOptions.Builder.fromEnv
+ */
+ @JvmStatic fun fromEnv(): LangsmithClientAsync = builder().fromEnv().build()
+ }
+
+ /** A builder for [LangsmithOkHttpClientAsync]. */
+ class Builder internal constructor() {
+
+ private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
+ 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
+ }
+
+ /** 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
+ * 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 {
+ clientOptions.checkJacksonVersionCompatibility(checkJacksonVersionCompatibility)
+ }
+
+ /**
+ * The Jackson JSON mapper to use for serializing and deserializing JSON.
+ *
+ * Defaults to [com.langchain.smith.core.jsonMapper]. The default is usually sufficient and
+ * rarely needs to be overridden.
+ */
+ fun jsonMapper(jsonMapper: JsonMapper) = apply { clientOptions.jsonMapper(jsonMapper) }
+
+ /**
+ * The interface to use for delaying execution, like during retries.
+ *
+ * This is primarily useful for using fake delays in tests.
+ *
+ * Defaults to real execution delays.
+ *
+ * This class takes ownership of the sleeper and closes it when closed.
+ */
+ fun sleeper(sleeper: Sleeper) = apply { clientOptions.sleeper(sleeper) }
+
+ /**
+ * 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.example.com`.
+ */
+ 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 tenantId(tenantId: String?) = apply { clientOptions.tenantId(tenantId) }
+
+ /** Alias for calling [Builder.tenantId] with `tenantId.orElse(null)`. */
+ fun tenantId(tenantId: Optional) = tenantId(tenantId.getOrNull())
+
+ /**
+ * Bearer tokens are used to authenticate from the UI. Must also specify x-tenant-id or
+ * x-organization-id (for org scoped apis).
+ */
+ fun bearerToken(bearerToken: String?) = apply { clientOptions.bearerToken(bearerToken) }
+
+ /** Alias for calling [Builder.bearerToken] with `bearerToken.orElse(null)`. */
+ fun bearerToken(bearerToken: Optional) = bearerToken(bearerToken.getOrNull())
+
+ fun organizationId(organizationId: String?) = apply {
+ clientOptions.organizationId(organizationId)
+ }
+
+ /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */
+ fun organizationId(organizationId: Optional) =
+ organizationId(organizationId.getOrNull())
+
+ fun headers(headers: Headers) = apply { clientOptions.headers(headers) }
+
+ fun headers(headers: Map>) = apply {
+ clientOptions.headers(headers)
+ }
+
+ fun putHeader(name: String, value: String) = apply { clientOptions.putHeader(name, value) }
+
+ fun putHeaders(name: String, values: Iterable) = apply {
+ clientOptions.putHeaders(name, values)
+ }
+
+ fun putAllHeaders(headers: Headers) = apply { clientOptions.putAllHeaders(headers) }
+
+ fun putAllHeaders(headers: Map>) = apply {
+ clientOptions.putAllHeaders(headers)
+ }
+
+ fun replaceHeaders(name: String, value: String) = apply {
+ clientOptions.replaceHeaders(name, value)
+ }
+
+ fun replaceHeaders(name: String, values: Iterable) = apply {
+ clientOptions.replaceHeaders(name, values)
+ }
+
+ fun replaceAllHeaders(headers: Headers) = apply { clientOptions.replaceAllHeaders(headers) }
+
+ fun replaceAllHeaders(headers: Map>) = apply {
+ clientOptions.replaceAllHeaders(headers)
+ }
+
+ fun removeHeaders(name: String) = apply { clientOptions.removeHeaders(name) }
+
+ fun removeAllHeaders(names: Set) = apply { clientOptions.removeAllHeaders(names) }
+
+ fun queryParams(queryParams: QueryParams) = apply { clientOptions.queryParams(queryParams) }
+
+ fun queryParams(queryParams: Map>) = apply {
+ clientOptions.queryParams(queryParams)
+ }
+
+ fun putQueryParam(key: String, value: String) = apply {
+ clientOptions.putQueryParam(key, value)
+ }
+
+ fun putQueryParams(key: String, values: Iterable) = apply {
+ clientOptions.putQueryParams(key, values)
+ }
+
+ fun putAllQueryParams(queryParams: QueryParams) = apply {
+ clientOptions.putAllQueryParams(queryParams)
+ }
+
+ fun putAllQueryParams(queryParams: Map>) = apply {
+ clientOptions.putAllQueryParams(queryParams)
+ }
+
+ fun replaceQueryParams(key: String, value: String) = apply {
+ clientOptions.replaceQueryParams(key, value)
+ }
+
+ fun replaceQueryParams(key: String, values: Iterable) = apply {
+ clientOptions.replaceQueryParams(key, values)
+ }
+
+ fun replaceAllQueryParams(queryParams: QueryParams) = apply {
+ clientOptions.replaceAllQueryParams(queryParams)
+ }
+
+ fun replaceAllQueryParams(queryParams: Map>) = apply {
+ clientOptions.replaceAllQueryParams(queryParams)
+ }
+
+ fun removeQueryParams(key: String) = apply { clientOptions.removeQueryParams(key) }
+
+ fun removeAllQueryParams(keys: Set) = apply {
+ clientOptions.removeAllQueryParams(keys)
+ }
+
+ /**
+ * Updates configuration using system properties and environment variables.
+ *
+ * @see ClientOptions.Builder.fromEnv
+ */
+ fun fromEnv() = apply { clientOptions.fromEnv() }
+
+ /**
+ * Returns an immutable instance of [LangsmithClientAsync].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ */
+ fun build(): LangsmithClientAsync =
+ LangsmithClientAsyncImpl(
+ clientOptions
+ .httpClient(
+ OkHttpClient.builder()
+ .timeout(clientOptions.timeout())
+ .proxy(proxy)
+ .sslSocketFactory(sslSocketFactory)
+ .trustManager(trustManager)
+ .hostnameVerifier(hostnameVerifier)
+ .build()
+ )
+ .build()
+ )
+ }
+}
diff --git a/langsmith-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/OkHttpClient.kt b/langsmith-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/OkHttpClient.kt
new file mode 100644
index 00000000..de9333ac
--- /dev/null
+++ b/langsmith-client-okhttp/src/main/kotlin/com/langchain/smith/client/okhttp/OkHttpClient.kt
@@ -0,0 +1,251 @@
+package com.langchain.smith.client.okhttp
+
+import com.langchain.smith.core.RequestOptions
+import com.langchain.smith.core.Timeout
+import com.langchain.smith.core.http.Headers
+import com.langchain.smith.core.http.HttpClient
+import com.langchain.smith.core.http.HttpMethod
+import com.langchain.smith.core.http.HttpRequest
+import com.langchain.smith.core.http.HttpRequestBody
+import com.langchain.smith.core.http.HttpResponse
+import com.langchain.smith.errors.LangChainIoException
+import java.io.IOException
+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.Companion.toHttpUrl
+import okhttp3.MediaType
+import okhttp3.MediaType.Companion.toMediaType
+import okhttp3.Request
+import okhttp3.RequestBody
+import okhttp3.RequestBody.Companion.toRequestBody
+import okhttp3.Response
+import okhttp3.logging.HttpLoggingInterceptor
+import okio.BufferedSink
+
+class OkHttpClient private constructor(private val okHttpClient: okhttp3.OkHttpClient) :
+ HttpClient {
+
+ override fun execute(request: HttpRequest, requestOptions: RequestOptions): HttpResponse {
+ val call = newCall(request, requestOptions)
+
+ return try {
+ call.execute().toResponse()
+ } catch (e: IOException) {
+ throw LangChainIoException("Request failed", e)
+ } finally {
+ request.body?.close()
+ }
+ }
+
+ override fun executeAsync(
+ request: HttpRequest,
+ requestOptions: RequestOptions,
+ ): CompletableFuture {
+ val future = CompletableFuture()
+
+ request.body?.run { future.whenComplete { _, _ -> close() } }
+
+ newCall(request, requestOptions)
+ .enqueue(
+ object : Callback {
+ override fun onResponse(call: Call, response: Response) {
+ future.complete(response.toResponse())
+ }
+
+ override fun onFailure(call: Call, e: IOException) {
+ future.completeExceptionally(LangChainIoException("Request failed", e))
+ }
+ }
+ )
+
+ return future
+ }
+
+ override fun close() {
+ okHttpClient.dispatcher.executorService.shutdown()
+ okHttpClient.connectionPool.evictAll()
+ okHttpClient.cache?.close()
+ }
+
+ private fun newCall(request: HttpRequest, requestOptions: RequestOptions): Call {
+ val clientBuilder = okHttpClient.newBuilder()
+
+ val logLevel =
+ when (System.getenv("LANGCHAIN_LOG")?.lowercase()) {
+ "info" -> HttpLoggingInterceptor.Level.BASIC
+ "debug" -> HttpLoggingInterceptor.Level.BODY
+ else -> null
+ }
+ if (logLevel != null) {
+ clientBuilder.addNetworkInterceptor(
+ HttpLoggingInterceptor().setLevel(logLevel).apply {
+ redactHeader("X-API-Key")
+ redactHeader("X-Tenant-Id")
+ redactHeader("Authorization")
+ redactHeader("X-Organization-Id")
+ }
+ )
+ }
+
+ requestOptions.timeout?.let {
+ clientBuilder
+ .connectTimeout(it.connect())
+ .readTimeout(it.read())
+ .writeTimeout(it.write())
+ .callTimeout(it.request())
+ }
+
+ val client = clientBuilder.build()
+ return client.newCall(request.toRequest(client))
+ }
+
+ private fun HttpRequest.toRequest(client: okhttp3.OkHttpClient): Request {
+ var body: RequestBody? = body?.toRequestBody()
+ if (body == null && requiresBody(method)) {
+ body = "".toRequestBody()
+ }
+
+ val builder = Request.Builder().url(toUrl()).method(method.name, body)
+ headers.names().forEach { name ->
+ headers.values(name).forEach { builder.header(name, it) }
+ }
+
+ if (
+ !headers.names().contains("X-Stainless-Read-Timeout") && client.readTimeoutMillis != 0
+ ) {
+ builder.header(
+ "X-Stainless-Read-Timeout",
+ Duration.ofMillis(client.readTimeoutMillis.toLong()).seconds.toString(),
+ )
+ }
+ if (!headers.names().contains("X-Stainless-Timeout") && client.callTimeoutMillis != 0) {
+ builder.header(
+ "X-Stainless-Timeout",
+ Duration.ofMillis(client.callTimeoutMillis.toLong()).seconds.toString(),
+ )
+ }
+
+ return builder.build()
+ }
+
+ /** `OkHttpClient` always requires a request body for some methods. */
+ private fun requiresBody(method: HttpMethod): Boolean =
+ when (method) {
+ HttpMethod.POST,
+ HttpMethod.PUT,
+ HttpMethod.PATCH -> true
+ else -> false
+ }
+
+ private fun HttpRequest.toUrl(): String {
+ val builder = baseUrl.toHttpUrl().newBuilder()
+ pathSegments.forEach(builder::addPathSegment)
+ queryParams.keys().forEach { key ->
+ queryParams.values(key).forEach { builder.addQueryParameter(key, it) }
+ }
+
+ return builder.toString()
+ }
+
+ private fun HttpRequestBody.toRequestBody(): RequestBody {
+ val mediaType = contentType()?.toMediaType()
+ val length = contentLength()
+
+ return object : RequestBody() {
+ override fun contentType(): MediaType? = mediaType
+
+ override fun contentLength(): Long = length
+
+ override fun isOneShot(): Boolean = !repeatable()
+
+ override fun writeTo(sink: BufferedSink) = writeTo(sink.outputStream())
+ }
+ }
+
+ private fun Response.toResponse(): HttpResponse {
+ val headers = headers.toHeaders()
+
+ return object : HttpResponse {
+ override fun statusCode(): Int = code
+
+ override fun headers(): Headers = headers
+
+ override fun body(): InputStream = body!!.byteStream()
+
+ override fun close() = body!!.close()
+ }
+ }
+
+ private fun okhttp3.Headers.toHeaders(): Headers {
+ val headersBuilder = Headers.builder()
+ forEach { (name, value) -> headersBuilder.put(name, value) }
+ return headersBuilder.build()
+ }
+
+ companion object {
+ @JvmStatic fun builder() = Builder()
+ }
+
+ class Builder internal constructor() {
+
+ 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 timeout(timeout: Timeout) = apply { this.timeout = timeout }
+
+ fun timeout(timeout: Duration) = timeout(Timeout.builder().request(timeout).build())
+
+ 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()
+ .connectTimeout(timeout.connect())
+ .readTimeout(timeout.read())
+ .writeTimeout(timeout.write())
+ .callTimeout(timeout.request())
+ .proxy(proxy)
+ .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/langsmith-core/build.gradle.kts b/langsmith-core/build.gradle.kts
new file mode 100644
index 00000000..1f4627ad
--- /dev/null
+++ b/langsmith-core/build.gradle.kts
@@ -0,0 +1,41 @@
+plugins {
+ id("langchain.kotlin")
+ id("langchain.publish")
+}
+
+configurations.all {
+ resolutionStrategy {
+ // Compile and test against a lower Jackson version to ensure we're compatible with it.
+ // We publish with a higher version (see below) to ensure users depend on a secure version by default.
+ force("com.fasterxml.jackson.core:jackson-core:2.13.4")
+ force("com.fasterxml.jackson.core:jackson-databind:2.13.4")
+ force("com.fasterxml.jackson.core:jackson-annotations:2.13.4")
+ force("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.13.4")
+ force("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.4")
+ force("com.fasterxml.jackson.module:jackson-module-kotlin:2.13.4")
+ }
+}
+
+dependencies {
+ api("com.fasterxml.jackson.core:jackson-core:2.18.2")
+ api("com.fasterxml.jackson.core:jackson-databind:2.18.2")
+ api("com.google.errorprone:error_prone_annotations:2.33.0")
+
+ implementation("com.fasterxml.jackson.core:jackson-annotations:2.18.2")
+ implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.18.2")
+ implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.18.2")
+ implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.18.2")
+ implementation("org.apache.httpcomponents.core5:httpcore5:5.2.4")
+ implementation("org.apache.httpcomponents.client5:httpclient5:5.3.1")
+
+ testImplementation(kotlin("test"))
+ testImplementation(project(":langsmith-client-okhttp"))
+ testImplementation("com.github.tomakehurst:wiremock-jre8:2.35.2")
+ testImplementation("org.assertj:assertj-core:3.25.3")
+ testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3")
+ testImplementation("org.junit.jupiter:junit-jupiter-params:5.9.3")
+ testImplementation("org.junit-pioneer:junit-pioneer:1.9.1")
+ testImplementation("org.mockito:mockito-core:5.14.2")
+ testImplementation("org.mockito:mockito-junit-jupiter:5.14.2")
+ testImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0")
+}
diff --git a/langsmith-core/src/main/kotlin/com/langchain/smith/client/LangsmithClient.kt b/langsmith-core/src/main/kotlin/com/langchain/smith/client/LangsmithClient.kt
new file mode 100644
index 00000000..1f0c8d31
--- /dev/null
+++ b/langsmith-core/src/main/kotlin/com/langchain/smith/client/LangsmithClient.kt
@@ -0,0 +1,401 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.langchain.smith.client
+
+import com.google.errorprone.annotations.MustBeClosed
+import com.langchain.smith.core.ClientOptions
+import com.langchain.smith.core.RequestOptions
+import com.langchain.smith.core.http.HttpResponseFor
+import com.langchain.smith.models.ClientEventsParams
+import com.langchain.smith.models.ClientEventsResponse
+import com.langchain.smith.models.ClientLoginParams
+import com.langchain.smith.models.ClientLoginResponse
+import com.langchain.smith.models.ClientRetrieveOkParams
+import com.langchain.smith.models.ClientRetrieveOkResponse
+import com.langchain.smith.models.ClientUpdateParams
+import com.langchain.smith.models.ClientUpdateResponse
+import com.langchain.smith.services.blocking.AceService
+import com.langchain.smith.services.blocking.AnnotationQueueService
+import com.langchain.smith.services.blocking.ApiKeyService
+import com.langchain.smith.services.blocking.BulkExportService
+import com.langchain.smith.services.blocking.ChartService
+import com.langchain.smith.services.blocking.CommentService
+import com.langchain.smith.services.blocking.CommitService
+import com.langchain.smith.services.blocking.DatasetService
+import com.langchain.smith.services.blocking.ExampleService
+import com.langchain.smith.services.blocking.FeedbackConfigService
+import com.langchain.smith.services.blocking.FeedbackService
+import com.langchain.smith.services.blocking.InfoService
+import com.langchain.smith.services.blocking.MeService
+import com.langchain.smith.services.blocking.ModelPriceMapService
+import com.langchain.smith.services.blocking.OAuthService
+import com.langchain.smith.services.blocking.OrgChartService
+import com.langchain.smith.services.blocking.OrgService
+import com.langchain.smith.services.blocking.PlatformService
+import com.langchain.smith.services.blocking.PlaygroundSettingService
+import com.langchain.smith.services.blocking.PromptService
+import com.langchain.smith.services.blocking.PromptWebhookService
+import com.langchain.smith.services.blocking.PublicService
+import com.langchain.smith.services.blocking.RepoService
+import com.langchain.smith.services.blocking.RunService
+import com.langchain.smith.services.blocking.ServiceAccountService
+import com.langchain.smith.services.blocking.SessionService
+import com.langchain.smith.services.blocking.SettingService
+import com.langchain.smith.services.blocking.SsoService
+import com.langchain.smith.services.blocking.TenantService
+import com.langchain.smith.services.blocking.TtlSettingService
+import com.langchain.smith.services.blocking.UsageLimitService
+import com.langchain.smith.services.blocking.WorkspaceService
+import java.util.function.Consumer
+
+/**
+ * A client for interacting with the LangChain REST API synchronously. You can also switch to
+ * asynchronous execution via the [async] method.
+ *
+ * This client performs best when you create a single instance and reuse it for all interactions
+ * with the REST API. This is because each client holds its own connection pool and thread pools.
+ * Reusing connections and threads reduces latency and saves memory. The client also handles rate
+ * limiting per client. This means that creating and using multiple instances at the same time will
+ * not respect rate limits.
+ *
+ * The threads and connections that are held will be released automatically if they remain idle. But
+ * if you are writing an application that needs to aggressively release unused resources, then you
+ * may call [close].
+ */
+interface LangsmithClient {
+
+ /**
+ * Returns a version of this client that uses asynchronous execution.
+ *
+ * The returned client shares its resources, like its connection pool and thread pools, with
+ * this client.
+ */
+ fun async(): LangsmithClientAsync
+
+ /**
+ * Returns a view of this service that provides access to raw HTTP responses for each method.
+ */
+ fun withRawResponse(): WithRawResponse
+
+ /**
+ * Returns a view of this service with the given option modifications applied.
+ *
+ * The original service is not modified.
+ */
+ fun withOptions(modifier: Consumer): LangsmithClient
+
+ fun sessions(): SessionService
+
+ fun orgs(): OrgService
+
+ fun oauth(): OAuthService
+
+ fun sso(): SsoService
+
+ fun apiKey(): ApiKeyService
+
+ fun examples(): ExampleService
+
+ fun datasets(): DatasetService
+
+ fun runs(): RunService
+
+ fun feedback(): FeedbackService
+
+ fun public_(): PublicService
+
+ fun annotationQueues(): AnnotationQueueService
+
+ fun ace(): AceService
+
+ fun bulkExports(): BulkExportService
+
+ fun tenants(): TenantService
+
+ fun info(): InfoService
+
+ fun feedbackConfigs(): FeedbackConfigService
+
+ fun modelPriceMap(): ModelPriceMapService
+
+ fun usageLimits(): UsageLimitService
+
+ fun ttlSettings(): TtlSettingService
+
+ fun prompts(): PromptService
+
+ fun promptWebhooks(): PromptWebhookService
+
+ fun workspaces(): WorkspaceService
+
+ fun playgroundSettings(): PlaygroundSettingService
+
+ fun me(): MeService
+
+ fun serviceAccounts(): ServiceAccountService
+
+ fun charts(): ChartService
+
+ fun orgCharts(): OrgChartService
+
+ fun repos(): RepoService
+
+ fun commits(): CommitService
+
+ fun settings(): SettingService
+
+ fun comments(): CommentService
+
+ fun platform(): PlatformService
+
+ /** Like a repo. */
+ fun update(repo: String, params: ClientUpdateParams): ClientUpdateResponse =
+ update(repo, params, RequestOptions.none())
+
+ /** @see update */
+ fun update(
+ repo: String,
+ params: ClientUpdateParams,
+ requestOptions: RequestOptions = RequestOptions.none(),
+ ): ClientUpdateResponse = update(params.toBuilder().repo(repo).build(), requestOptions)
+
+ /** @see update */
+ fun update(params: ClientUpdateParams): ClientUpdateResponse =
+ update(params, RequestOptions.none())
+
+ /** @see update */
+ fun update(
+ params: ClientUpdateParams,
+ requestOptions: RequestOptions = RequestOptions.none(),
+ ): ClientUpdateResponse
+
+ /** Create Event */
+ fun events(params: ClientEventsParams): ClientEventsResponse =
+ events(params, RequestOptions.none())
+
+ /** @see events */
+ fun events(
+ params: ClientEventsParams,
+ requestOptions: RequestOptions = RequestOptions.none(),
+ ): ClientEventsResponse
+
+ /** Login */
+ fun login(): ClientLoginResponse = login(ClientLoginParams.none())
+
+ /** @see login */
+ fun login(
+ params: ClientLoginParams = ClientLoginParams.none(),
+ requestOptions: RequestOptions = RequestOptions.none(),
+ ): ClientLoginResponse
+
+ /** @see login */
+ fun login(params: ClientLoginParams = ClientLoginParams.none()): ClientLoginResponse =
+ login(params, RequestOptions.none())
+
+ /** @see login */
+ fun login(requestOptions: RequestOptions): ClientLoginResponse =
+ login(ClientLoginParams.none(), requestOptions)
+
+ /** Ok */
+ fun retrieveOk(): ClientRetrieveOkResponse = retrieveOk(ClientRetrieveOkParams.none())
+
+ /** @see retrieveOk */
+ fun retrieveOk(
+ params: ClientRetrieveOkParams = ClientRetrieveOkParams.none(),
+ requestOptions: RequestOptions = RequestOptions.none(),
+ ): ClientRetrieveOkResponse
+
+ /** @see retrieveOk */
+ fun retrieveOk(
+ params: ClientRetrieveOkParams = ClientRetrieveOkParams.none()
+ ): ClientRetrieveOkResponse = retrieveOk(params, RequestOptions.none())
+
+ /** @see retrieveOk */
+ fun retrieveOk(requestOptions: RequestOptions): ClientRetrieveOkResponse =
+ retrieveOk(ClientRetrieveOkParams.none(), requestOptions)
+
+ /**
+ * Closes this client, relinquishing any underlying resources.
+ *
+ * This is purposefully not inherited from [AutoCloseable] because the client is 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 HTTP 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()
+
+ /** A view of [LangsmithClient] 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): LangsmithClient.WithRawResponse
+
+ fun sessions(): SessionService.WithRawResponse
+
+ fun orgs(): OrgService.WithRawResponse
+
+ fun oauth(): OAuthService.WithRawResponse
+
+ fun sso(): SsoService.WithRawResponse
+
+ fun apiKey(): ApiKeyService.WithRawResponse
+
+ fun examples(): ExampleService.WithRawResponse
+
+ fun datasets(): DatasetService.WithRawResponse
+
+ fun runs(): RunService.WithRawResponse
+
+ fun feedback(): FeedbackService.WithRawResponse
+
+ fun public_(): PublicService.WithRawResponse
+
+ fun annotationQueues(): AnnotationQueueService.WithRawResponse
+
+ fun ace(): AceService.WithRawResponse
+
+ fun bulkExports(): BulkExportService.WithRawResponse
+
+ fun tenants(): TenantService.WithRawResponse
+
+ fun info(): InfoService.WithRawResponse
+
+ fun feedbackConfigs(): FeedbackConfigService.WithRawResponse
+
+ fun modelPriceMap(): ModelPriceMapService.WithRawResponse
+
+ fun usageLimits(): UsageLimitService.WithRawResponse
+
+ fun ttlSettings(): TtlSettingService.WithRawResponse
+
+ fun prompts(): PromptService.WithRawResponse
+
+ fun promptWebhooks(): PromptWebhookService.WithRawResponse
+
+ fun workspaces(): WorkspaceService.WithRawResponse
+
+ fun playgroundSettings(): PlaygroundSettingService.WithRawResponse
+
+ fun me(): MeService.WithRawResponse
+
+ fun serviceAccounts(): ServiceAccountService.WithRawResponse
+
+ fun charts(): ChartService.WithRawResponse
+
+ fun orgCharts(): OrgChartService.WithRawResponse
+
+ fun repos(): RepoService.WithRawResponse
+
+ fun commits(): CommitService.WithRawResponse
+
+ fun settings(): SettingService.WithRawResponse
+
+ fun comments(): CommentService.WithRawResponse
+
+ fun platform(): PlatformService.WithRawResponse
+
+ /**
+ * Returns a raw HTTP response for `post /api/v1/likes/{owner}/{repo}`, but is otherwise the
+ * same as [LangsmithClient.update].
+ */
+ @MustBeClosed
+ fun update(
+ repo: String,
+ params: ClientUpdateParams,
+ ): HttpResponseFor = update(repo, params, RequestOptions.none())
+
+ /** @see update */
+ @MustBeClosed
+ fun update(
+ repo: String,
+ params: ClientUpdateParams,
+ requestOptions: RequestOptions = RequestOptions.none(),
+ ): HttpResponseFor =
+ update(params.toBuilder().repo(repo).build(), requestOptions)
+
+ /** @see update */
+ @MustBeClosed
+ fun update(params: ClientUpdateParams): HttpResponseFor =
+ update(params, RequestOptions.none())
+
+ /** @see update */
+ @MustBeClosed
+ fun update(
+ params: ClientUpdateParams,
+ requestOptions: RequestOptions = RequestOptions.none(),
+ ): HttpResponseFor
+
+ /**
+ * Returns a raw HTTP response for `post /api/v1/events`, but is otherwise the same as
+ * [LangsmithClient.events].
+ */
+ @MustBeClosed
+ fun events(params: ClientEventsParams): HttpResponseFor =
+ events(params, RequestOptions.none())
+
+ /** @see events */
+ @MustBeClosed
+ fun events(
+ params: ClientEventsParams,
+ requestOptions: RequestOptions = RequestOptions.none(),
+ ): HttpResponseFor
+
+ /**
+ * Returns a raw HTTP response for `post /api/v1/login`, but is otherwise the same as
+ * [LangsmithClient.login].
+ */
+ @MustBeClosed
+ fun login(): HttpResponseFor = login(ClientLoginParams.none())
+
+ /** @see login */
+ @MustBeClosed
+ fun login(
+ params: ClientLoginParams = ClientLoginParams.none(),
+ requestOptions: RequestOptions = RequestOptions.none(),
+ ): HttpResponseFor
+
+ /** @see login */
+ @MustBeClosed
+ fun login(
+ params: ClientLoginParams = ClientLoginParams.none()
+ ): HttpResponseFor = login(params, RequestOptions.none())
+
+ /** @see login */
+ @MustBeClosed
+ fun login(requestOptions: RequestOptions): HttpResponseFor =
+ login(ClientLoginParams.none(), requestOptions)
+
+ /**
+ * Returns a raw HTTP response for `get /api/v1/ok`, but is otherwise the same as
+ * [LangsmithClient.retrieveOk].
+ */
+ @MustBeClosed
+ fun retrieveOk(): HttpResponseFor =
+ retrieveOk(ClientRetrieveOkParams.none())
+
+ /** @see retrieveOk */
+ @MustBeClosed
+ fun retrieveOk(
+ params: ClientRetrieveOkParams = ClientRetrieveOkParams.none(),
+ requestOptions: RequestOptions = RequestOptions.none(),
+ ): HttpResponseFor
+
+ /** @see retrieveOk */
+ @MustBeClosed
+ fun retrieveOk(
+ params: ClientRetrieveOkParams = ClientRetrieveOkParams.none()
+ ): HttpResponseFor = retrieveOk(params, RequestOptions.none())
+
+ /** @see retrieveOk */
+ @MustBeClosed
+ fun retrieveOk(requestOptions: RequestOptions): HttpResponseFor =
+ retrieveOk(ClientRetrieveOkParams.none(), requestOptions)
+ }
+}
diff --git a/langsmith-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientAsync.kt b/langsmith-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientAsync.kt
new file mode 100644
index 00000000..1bdb2e70
--- /dev/null
+++ b/langsmith-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientAsync.kt
@@ -0,0 +1,406 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.langchain.smith.client
+
+import com.langchain.smith.core.ClientOptions
+import com.langchain.smith.core.RequestOptions
+import com.langchain.smith.core.http.HttpResponseFor
+import com.langchain.smith.models.ClientEventsParams
+import com.langchain.smith.models.ClientEventsResponse
+import com.langchain.smith.models.ClientLoginParams
+import com.langchain.smith.models.ClientLoginResponse
+import com.langchain.smith.models.ClientRetrieveOkParams
+import com.langchain.smith.models.ClientRetrieveOkResponse
+import com.langchain.smith.models.ClientUpdateParams
+import com.langchain.smith.models.ClientUpdateResponse
+import com.langchain.smith.services.async.AceServiceAsync
+import com.langchain.smith.services.async.AnnotationQueueServiceAsync
+import com.langchain.smith.services.async.ApiKeyServiceAsync
+import com.langchain.smith.services.async.BulkExportServiceAsync
+import com.langchain.smith.services.async.ChartServiceAsync
+import com.langchain.smith.services.async.CommentServiceAsync
+import com.langchain.smith.services.async.CommitServiceAsync
+import com.langchain.smith.services.async.DatasetServiceAsync
+import com.langchain.smith.services.async.ExampleServiceAsync
+import com.langchain.smith.services.async.FeedbackConfigServiceAsync
+import com.langchain.smith.services.async.FeedbackServiceAsync
+import com.langchain.smith.services.async.InfoServiceAsync
+import com.langchain.smith.services.async.MeServiceAsync
+import com.langchain.smith.services.async.ModelPriceMapServiceAsync
+import com.langchain.smith.services.async.OAuthServiceAsync
+import com.langchain.smith.services.async.OrgChartServiceAsync
+import com.langchain.smith.services.async.OrgServiceAsync
+import com.langchain.smith.services.async.PlatformServiceAsync
+import com.langchain.smith.services.async.PlaygroundSettingServiceAsync
+import com.langchain.smith.services.async.PromptServiceAsync
+import com.langchain.smith.services.async.PromptWebhookServiceAsync
+import com.langchain.smith.services.async.PublicServiceAsync
+import com.langchain.smith.services.async.RepoServiceAsync
+import com.langchain.smith.services.async.RunServiceAsync
+import com.langchain.smith.services.async.ServiceAccountServiceAsync
+import com.langchain.smith.services.async.SessionServiceAsync
+import com.langchain.smith.services.async.SettingServiceAsync
+import com.langchain.smith.services.async.SsoServiceAsync
+import com.langchain.smith.services.async.TenantServiceAsync
+import com.langchain.smith.services.async.TtlSettingServiceAsync
+import com.langchain.smith.services.async.UsageLimitServiceAsync
+import com.langchain.smith.services.async.WorkspaceServiceAsync
+import java.util.concurrent.CompletableFuture
+import java.util.function.Consumer
+
+/**
+ * A client for interacting with the LangChain REST API asynchronously. You can also switch to
+ * synchronous execution via the [sync] method.
+ *
+ * This client performs best when you create a single instance and reuse it for all interactions
+ * with the REST API. This is because each client holds its own connection pool and thread pools.
+ * Reusing connections and threads reduces latency and saves memory. The client also handles rate
+ * limiting per client. This means that creating and using multiple instances at the same time will
+ * not respect rate limits.
+ *
+ * The threads and connections that are held will be released automatically if they remain idle. But
+ * if you are writing an application that needs to aggressively release unused resources, then you
+ * may call [close].
+ */
+interface LangsmithClientAsync {
+
+ /**
+ * Returns a version of this client that uses synchronous execution.
+ *
+ * The returned client shares its resources, like its connection pool and thread pools, with
+ * this client.
+ */
+ fun sync(): LangsmithClient
+
+ /**
+ * Returns a view of this service that provides access to raw HTTP responses for each method.
+ */
+ fun withRawResponse(): WithRawResponse
+
+ /**
+ * Returns a view of this service with the given option modifications applied.
+ *
+ * The original service is not modified.
+ */
+ fun withOptions(modifier: Consumer): LangsmithClientAsync
+
+ fun sessions(): SessionServiceAsync
+
+ fun orgs(): OrgServiceAsync
+
+ fun oauth(): OAuthServiceAsync
+
+ fun sso(): SsoServiceAsync
+
+ fun apiKey(): ApiKeyServiceAsync
+
+ fun examples(): ExampleServiceAsync
+
+ fun datasets(): DatasetServiceAsync
+
+ fun runs(): RunServiceAsync
+
+ fun feedback(): FeedbackServiceAsync
+
+ fun public_(): PublicServiceAsync
+
+ fun annotationQueues(): AnnotationQueueServiceAsync
+
+ fun ace(): AceServiceAsync
+
+ fun bulkExports(): BulkExportServiceAsync
+
+ fun tenants(): TenantServiceAsync
+
+ fun info(): InfoServiceAsync
+
+ fun feedbackConfigs(): FeedbackConfigServiceAsync
+
+ fun modelPriceMap(): ModelPriceMapServiceAsync
+
+ fun usageLimits(): UsageLimitServiceAsync
+
+ fun ttlSettings(): TtlSettingServiceAsync
+
+ fun prompts(): PromptServiceAsync
+
+ fun promptWebhooks(): PromptWebhookServiceAsync
+
+ fun workspaces(): WorkspaceServiceAsync
+
+ fun playgroundSettings(): PlaygroundSettingServiceAsync
+
+ fun me(): MeServiceAsync
+
+ fun serviceAccounts(): ServiceAccountServiceAsync
+
+ fun charts(): ChartServiceAsync
+
+ fun orgCharts(): OrgChartServiceAsync
+
+ fun repos(): RepoServiceAsync
+
+ fun commits(): CommitServiceAsync
+
+ fun settings(): SettingServiceAsync
+
+ fun comments(): CommentServiceAsync
+
+ fun platform(): PlatformServiceAsync
+
+ /** Like a repo. */
+ fun update(repo: String, params: ClientUpdateParams): CompletableFuture =
+ update(repo, params, RequestOptions.none())
+
+ /** @see update */
+ fun update(
+ repo: String,
+ params: ClientUpdateParams,
+ requestOptions: RequestOptions = RequestOptions.none(),
+ ): CompletableFuture =
+ update(params.toBuilder().repo(repo).build(), requestOptions)
+
+ /** @see update */
+ fun update(params: ClientUpdateParams): CompletableFuture =
+ update(params, RequestOptions.none())
+
+ /** @see update */
+ fun update(
+ params: ClientUpdateParams,
+ requestOptions: RequestOptions = RequestOptions.none(),
+ ): CompletableFuture
+
+ /** Create Event */
+ fun events(params: ClientEventsParams): CompletableFuture =
+ events(params, RequestOptions.none())
+
+ /** @see events */
+ fun events(
+ params: ClientEventsParams,
+ requestOptions: RequestOptions = RequestOptions.none(),
+ ): CompletableFuture
+
+ /** Login */
+ fun login(): CompletableFuture = login(ClientLoginParams.none())
+
+ /** @see login */
+ fun login(
+ params: ClientLoginParams = ClientLoginParams.none(),
+ requestOptions: RequestOptions = RequestOptions.none(),
+ ): CompletableFuture
+
+ /** @see login */
+ fun login(
+ params: ClientLoginParams = ClientLoginParams.none()
+ ): CompletableFuture = login(params, RequestOptions.none())
+
+ /** @see login */
+ fun login(requestOptions: RequestOptions): CompletableFuture =
+ login(ClientLoginParams.none(), requestOptions)
+
+ /** Ok */
+ fun retrieveOk(): CompletableFuture =
+ retrieveOk(ClientRetrieveOkParams.none())
+
+ /** @see retrieveOk */
+ fun retrieveOk(
+ params: ClientRetrieveOkParams = ClientRetrieveOkParams.none(),
+ requestOptions: RequestOptions = RequestOptions.none(),
+ ): CompletableFuture
+
+ /** @see retrieveOk */
+ fun retrieveOk(
+ params: ClientRetrieveOkParams = ClientRetrieveOkParams.none()
+ ): CompletableFuture = retrieveOk(params, RequestOptions.none())
+
+ /** @see retrieveOk */
+ fun retrieveOk(requestOptions: RequestOptions): CompletableFuture =
+ retrieveOk(ClientRetrieveOkParams.none(), requestOptions)
+
+ /**
+ * Closes this client, relinquishing any underlying resources.
+ *
+ * This is purposefully not inherited from [AutoCloseable] because the client is 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 HTTP 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()
+
+ /**
+ * A view of [LangsmithClientAsync] 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
+ ): LangsmithClientAsync.WithRawResponse
+
+ fun sessions(): SessionServiceAsync.WithRawResponse
+
+ fun orgs(): OrgServiceAsync.WithRawResponse
+
+ fun oauth(): OAuthServiceAsync.WithRawResponse
+
+ fun sso(): SsoServiceAsync.WithRawResponse
+
+ fun apiKey(): ApiKeyServiceAsync.WithRawResponse
+
+ fun examples(): ExampleServiceAsync.WithRawResponse
+
+ fun datasets(): DatasetServiceAsync.WithRawResponse
+
+ fun runs(): RunServiceAsync.WithRawResponse
+
+ fun feedback(): FeedbackServiceAsync.WithRawResponse
+
+ fun public_(): PublicServiceAsync.WithRawResponse
+
+ fun annotationQueues(): AnnotationQueueServiceAsync.WithRawResponse
+
+ fun ace(): AceServiceAsync.WithRawResponse
+
+ fun bulkExports(): BulkExportServiceAsync.WithRawResponse
+
+ fun tenants(): TenantServiceAsync.WithRawResponse
+
+ fun info(): InfoServiceAsync.WithRawResponse
+
+ fun feedbackConfigs(): FeedbackConfigServiceAsync.WithRawResponse
+
+ fun modelPriceMap(): ModelPriceMapServiceAsync.WithRawResponse
+
+ fun usageLimits(): UsageLimitServiceAsync.WithRawResponse
+
+ fun ttlSettings(): TtlSettingServiceAsync.WithRawResponse
+
+ fun prompts(): PromptServiceAsync.WithRawResponse
+
+ fun promptWebhooks(): PromptWebhookServiceAsync.WithRawResponse
+
+ fun workspaces(): WorkspaceServiceAsync.WithRawResponse
+
+ fun playgroundSettings(): PlaygroundSettingServiceAsync.WithRawResponse
+
+ fun me(): MeServiceAsync.WithRawResponse
+
+ fun serviceAccounts(): ServiceAccountServiceAsync.WithRawResponse
+
+ fun charts(): ChartServiceAsync.WithRawResponse
+
+ fun orgCharts(): OrgChartServiceAsync.WithRawResponse
+
+ fun repos(): RepoServiceAsync.WithRawResponse
+
+ fun commits(): CommitServiceAsync.WithRawResponse
+
+ fun settings(): SettingServiceAsync.WithRawResponse
+
+ fun comments(): CommentServiceAsync.WithRawResponse
+
+ fun platform(): PlatformServiceAsync.WithRawResponse
+
+ /**
+ * Returns a raw HTTP response for `post /api/v1/likes/{owner}/{repo}`, but is otherwise the
+ * same as [LangsmithClientAsync.update].
+ */
+ fun update(
+ repo: String,
+ params: ClientUpdateParams,
+ ): CompletableFuture> =
+ update(repo, params, RequestOptions.none())
+
+ /** @see update */
+ fun update(
+ repo: String,
+ params: ClientUpdateParams,
+ requestOptions: RequestOptions = RequestOptions.none(),
+ ): CompletableFuture> =
+ update(params.toBuilder().repo(repo).build(), requestOptions)
+
+ /** @see update */
+ fun update(
+ params: ClientUpdateParams
+ ): CompletableFuture> =
+ update(params, RequestOptions.none())
+
+ /** @see update */
+ fun update(
+ params: ClientUpdateParams,
+ requestOptions: RequestOptions = RequestOptions.none(),
+ ): CompletableFuture>
+
+ /**
+ * Returns a raw HTTP response for `post /api/v1/events`, but is otherwise the same as
+ * [LangsmithClientAsync.events].
+ */
+ fun events(
+ params: ClientEventsParams
+ ): CompletableFuture> =
+ events(params, RequestOptions.none())
+
+ /** @see events */
+ fun events(
+ params: ClientEventsParams,
+ requestOptions: RequestOptions = RequestOptions.none(),
+ ): CompletableFuture>
+
+ /**
+ * Returns a raw HTTP response for `post /api/v1/login`, but is otherwise the same as
+ * [LangsmithClientAsync.login].
+ */
+ fun login(): CompletableFuture> =
+ login(ClientLoginParams.none())
+
+ /** @see login */
+ fun login(
+ params: ClientLoginParams = ClientLoginParams.none(),
+ requestOptions: RequestOptions = RequestOptions.none(),
+ ): CompletableFuture>
+
+ /** @see login */
+ fun login(
+ params: ClientLoginParams = ClientLoginParams.none()
+ ): CompletableFuture> =
+ login(params, RequestOptions.none())
+
+ /** @see login */
+ fun login(
+ requestOptions: RequestOptions
+ ): CompletableFuture> =
+ login(ClientLoginParams.none(), requestOptions)
+
+ /**
+ * Returns a raw HTTP response for `get /api/v1/ok`, but is otherwise the same as
+ * [LangsmithClientAsync.retrieveOk].
+ */
+ fun retrieveOk(): CompletableFuture> =
+ retrieveOk(ClientRetrieveOkParams.none())
+
+ /** @see retrieveOk */
+ fun retrieveOk(
+ params: ClientRetrieveOkParams = ClientRetrieveOkParams.none(),
+ requestOptions: RequestOptions = RequestOptions.none(),
+ ): CompletableFuture>
+
+ /** @see retrieveOk */
+ fun retrieveOk(
+ params: ClientRetrieveOkParams = ClientRetrieveOkParams.none()
+ ): CompletableFuture> =
+ retrieveOk(params, RequestOptions.none())
+
+ /** @see retrieveOk */
+ fun retrieveOk(
+ requestOptions: RequestOptions
+ ): CompletableFuture> =
+ retrieveOk(ClientRetrieveOkParams.none(), requestOptions)
+ }
+}
diff --git a/langsmith-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientAsyncImpl.kt b/langsmith-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientAsyncImpl.kt
new file mode 100644
index 00000000..97e7b2ae
--- /dev/null
+++ b/langsmith-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientAsyncImpl.kt
@@ -0,0 +1,667 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.langchain.smith.client
+
+import com.langchain.smith.core.ClientOptions
+import com.langchain.smith.core.RequestOptions
+import com.langchain.smith.core.checkRequired
+import com.langchain.smith.core.getPackageVersion
+import com.langchain.smith.core.handlers.errorBodyHandler
+import com.langchain.smith.core.handlers.errorHandler
+import com.langchain.smith.core.handlers.jsonHandler
+import com.langchain.smith.core.http.HttpMethod
+import com.langchain.smith.core.http.HttpRequest
+import com.langchain.smith.core.http.HttpResponse
+import com.langchain.smith.core.http.HttpResponse.Handler
+import com.langchain.smith.core.http.HttpResponseFor
+import com.langchain.smith.core.http.json
+import com.langchain.smith.core.http.parseable
+import com.langchain.smith.core.prepareAsync
+import com.langchain.smith.models.ClientEventsParams
+import com.langchain.smith.models.ClientEventsResponse
+import com.langchain.smith.models.ClientLoginParams
+import com.langchain.smith.models.ClientLoginResponse
+import com.langchain.smith.models.ClientRetrieveOkParams
+import com.langchain.smith.models.ClientRetrieveOkResponse
+import com.langchain.smith.models.ClientUpdateParams
+import com.langchain.smith.models.ClientUpdateResponse
+import com.langchain.smith.services.async.AceServiceAsync
+import com.langchain.smith.services.async.AceServiceAsyncImpl
+import com.langchain.smith.services.async.AnnotationQueueServiceAsync
+import com.langchain.smith.services.async.AnnotationQueueServiceAsyncImpl
+import com.langchain.smith.services.async.ApiKeyServiceAsync
+import com.langchain.smith.services.async.ApiKeyServiceAsyncImpl
+import com.langchain.smith.services.async.BulkExportServiceAsync
+import com.langchain.smith.services.async.BulkExportServiceAsyncImpl
+import com.langchain.smith.services.async.ChartServiceAsync
+import com.langchain.smith.services.async.ChartServiceAsyncImpl
+import com.langchain.smith.services.async.CommentServiceAsync
+import com.langchain.smith.services.async.CommentServiceAsyncImpl
+import com.langchain.smith.services.async.CommitServiceAsync
+import com.langchain.smith.services.async.CommitServiceAsyncImpl
+import com.langchain.smith.services.async.DatasetServiceAsync
+import com.langchain.smith.services.async.DatasetServiceAsyncImpl
+import com.langchain.smith.services.async.ExampleServiceAsync
+import com.langchain.smith.services.async.ExampleServiceAsyncImpl
+import com.langchain.smith.services.async.FeedbackConfigServiceAsync
+import com.langchain.smith.services.async.FeedbackConfigServiceAsyncImpl
+import com.langchain.smith.services.async.FeedbackServiceAsync
+import com.langchain.smith.services.async.FeedbackServiceAsyncImpl
+import com.langchain.smith.services.async.InfoServiceAsync
+import com.langchain.smith.services.async.InfoServiceAsyncImpl
+import com.langchain.smith.services.async.MeServiceAsync
+import com.langchain.smith.services.async.MeServiceAsyncImpl
+import com.langchain.smith.services.async.ModelPriceMapServiceAsync
+import com.langchain.smith.services.async.ModelPriceMapServiceAsyncImpl
+import com.langchain.smith.services.async.OAuthServiceAsync
+import com.langchain.smith.services.async.OAuthServiceAsyncImpl
+import com.langchain.smith.services.async.OrgChartServiceAsync
+import com.langchain.smith.services.async.OrgChartServiceAsyncImpl
+import com.langchain.smith.services.async.OrgServiceAsync
+import com.langchain.smith.services.async.OrgServiceAsyncImpl
+import com.langchain.smith.services.async.PlatformServiceAsync
+import com.langchain.smith.services.async.PlatformServiceAsyncImpl
+import com.langchain.smith.services.async.PlaygroundSettingServiceAsync
+import com.langchain.smith.services.async.PlaygroundSettingServiceAsyncImpl
+import com.langchain.smith.services.async.PromptServiceAsync
+import com.langchain.smith.services.async.PromptServiceAsyncImpl
+import com.langchain.smith.services.async.PromptWebhookServiceAsync
+import com.langchain.smith.services.async.PromptWebhookServiceAsyncImpl
+import com.langchain.smith.services.async.PublicServiceAsync
+import com.langchain.smith.services.async.PublicServiceAsyncImpl
+import com.langchain.smith.services.async.RepoServiceAsync
+import com.langchain.smith.services.async.RepoServiceAsyncImpl
+import com.langchain.smith.services.async.RunServiceAsync
+import com.langchain.smith.services.async.RunServiceAsyncImpl
+import com.langchain.smith.services.async.ServiceAccountServiceAsync
+import com.langchain.smith.services.async.ServiceAccountServiceAsyncImpl
+import com.langchain.smith.services.async.SessionServiceAsync
+import com.langchain.smith.services.async.SessionServiceAsyncImpl
+import com.langchain.smith.services.async.SettingServiceAsync
+import com.langchain.smith.services.async.SettingServiceAsyncImpl
+import com.langchain.smith.services.async.SsoServiceAsync
+import com.langchain.smith.services.async.SsoServiceAsyncImpl
+import com.langchain.smith.services.async.TenantServiceAsync
+import com.langchain.smith.services.async.TenantServiceAsyncImpl
+import com.langchain.smith.services.async.TtlSettingServiceAsync
+import com.langchain.smith.services.async.TtlSettingServiceAsyncImpl
+import com.langchain.smith.services.async.UsageLimitServiceAsync
+import com.langchain.smith.services.async.UsageLimitServiceAsyncImpl
+import com.langchain.smith.services.async.WorkspaceServiceAsync
+import com.langchain.smith.services.async.WorkspaceServiceAsyncImpl
+import java.util.concurrent.CompletableFuture
+import java.util.function.Consumer
+import kotlin.jvm.optionals.getOrNull
+
+class LangsmithClientAsyncImpl(private val clientOptions: ClientOptions) : LangsmithClientAsync {
+
+ private val clientOptionsWithUserAgent =
+ if (clientOptions.headers.names().contains("User-Agent")) clientOptions
+ else
+ clientOptions
+ .toBuilder()
+ .putHeader("User-Agent", "${javaClass.simpleName}/Java ${getPackageVersion()}")
+ .build()
+
+ // Pass the original clientOptions so that this client sets its own User-Agent.
+ private val sync: LangsmithClient by lazy { LangsmithClientImpl(clientOptions) }
+
+ private val withRawResponse: LangsmithClientAsync.WithRawResponse by lazy {
+ WithRawResponseImpl(clientOptions)
+ }
+
+ private val sessions: SessionServiceAsync by lazy {
+ SessionServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ private val orgs: OrgServiceAsync by lazy { OrgServiceAsyncImpl(clientOptionsWithUserAgent) }
+
+ private val oauth: OAuthServiceAsync by lazy {
+ OAuthServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ private val sso: SsoServiceAsync by lazy { SsoServiceAsyncImpl(clientOptionsWithUserAgent) }
+
+ private val apiKey: ApiKeyServiceAsync by lazy {
+ ApiKeyServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ private val examples: ExampleServiceAsync by lazy {
+ ExampleServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ private val datasets: DatasetServiceAsync by lazy {
+ DatasetServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ private val runs: RunServiceAsync by lazy { RunServiceAsyncImpl(clientOptionsWithUserAgent) }
+
+ private val feedback: FeedbackServiceAsync by lazy {
+ FeedbackServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ private val public_: PublicServiceAsync by lazy {
+ PublicServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ private val annotationQueues: AnnotationQueueServiceAsync by lazy {
+ AnnotationQueueServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ private val ace: AceServiceAsync by lazy { AceServiceAsyncImpl(clientOptionsWithUserAgent) }
+
+ private val bulkExports: BulkExportServiceAsync by lazy {
+ BulkExportServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ private val tenants: TenantServiceAsync by lazy {
+ TenantServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ private val info: InfoServiceAsync by lazy { InfoServiceAsyncImpl(clientOptionsWithUserAgent) }
+
+ private val feedbackConfigs: FeedbackConfigServiceAsync by lazy {
+ FeedbackConfigServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ private val modelPriceMap: ModelPriceMapServiceAsync by lazy {
+ ModelPriceMapServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ private val usageLimits: UsageLimitServiceAsync by lazy {
+ UsageLimitServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ private val ttlSettings: TtlSettingServiceAsync by lazy {
+ TtlSettingServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ private val prompts: PromptServiceAsync by lazy {
+ PromptServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ private val promptWebhooks: PromptWebhookServiceAsync by lazy {
+ PromptWebhookServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ private val workspaces: WorkspaceServiceAsync by lazy {
+ WorkspaceServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ private val playgroundSettings: PlaygroundSettingServiceAsync by lazy {
+ PlaygroundSettingServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ private val me: MeServiceAsync by lazy { MeServiceAsyncImpl(clientOptionsWithUserAgent) }
+
+ private val serviceAccounts: ServiceAccountServiceAsync by lazy {
+ ServiceAccountServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ private val charts: ChartServiceAsync by lazy {
+ ChartServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ private val orgCharts: OrgChartServiceAsync by lazy {
+ OrgChartServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ private val repos: RepoServiceAsync by lazy { RepoServiceAsyncImpl(clientOptionsWithUserAgent) }
+
+ private val commits: CommitServiceAsync by lazy {
+ CommitServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ private val settings: SettingServiceAsync by lazy {
+ SettingServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ private val comments: CommentServiceAsync by lazy {
+ CommentServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ private val platform: PlatformServiceAsync by lazy {
+ PlatformServiceAsyncImpl(clientOptionsWithUserAgent)
+ }
+
+ override fun sync(): LangsmithClient = sync
+
+ override fun withRawResponse(): LangsmithClientAsync.WithRawResponse = withRawResponse
+
+ override fun withOptions(modifier: Consumer): LangsmithClientAsync =
+ LangsmithClientAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build())
+
+ override fun sessions(): SessionServiceAsync = sessions
+
+ override fun orgs(): OrgServiceAsync = orgs
+
+ override fun oauth(): OAuthServiceAsync = oauth
+
+ override fun sso(): SsoServiceAsync = sso
+
+ override fun apiKey(): ApiKeyServiceAsync = apiKey
+
+ override fun examples(): ExampleServiceAsync = examples
+
+ override fun datasets(): DatasetServiceAsync = datasets
+
+ override fun runs(): RunServiceAsync = runs
+
+ override fun feedback(): FeedbackServiceAsync = feedback
+
+ override fun public_(): PublicServiceAsync = public_
+
+ override fun annotationQueues(): AnnotationQueueServiceAsync = annotationQueues
+
+ override fun ace(): AceServiceAsync = ace
+
+ override fun bulkExports(): BulkExportServiceAsync = bulkExports
+
+ override fun tenants(): TenantServiceAsync = tenants
+
+ override fun info(): InfoServiceAsync = info
+
+ override fun feedbackConfigs(): FeedbackConfigServiceAsync = feedbackConfigs
+
+ override fun modelPriceMap(): ModelPriceMapServiceAsync = modelPriceMap
+
+ override fun usageLimits(): UsageLimitServiceAsync = usageLimits
+
+ override fun ttlSettings(): TtlSettingServiceAsync = ttlSettings
+
+ override fun prompts(): PromptServiceAsync = prompts
+
+ override fun promptWebhooks(): PromptWebhookServiceAsync = promptWebhooks
+
+ override fun workspaces(): WorkspaceServiceAsync = workspaces
+
+ override fun playgroundSettings(): PlaygroundSettingServiceAsync = playgroundSettings
+
+ override fun me(): MeServiceAsync = me
+
+ override fun serviceAccounts(): ServiceAccountServiceAsync = serviceAccounts
+
+ override fun charts(): ChartServiceAsync = charts
+
+ override fun orgCharts(): OrgChartServiceAsync = orgCharts
+
+ override fun repos(): RepoServiceAsync = repos
+
+ override fun commits(): CommitServiceAsync = commits
+
+ override fun settings(): SettingServiceAsync = settings
+
+ override fun comments(): CommentServiceAsync = comments
+
+ override fun platform(): PlatformServiceAsync = platform
+
+ override fun update(
+ params: ClientUpdateParams,
+ requestOptions: RequestOptions,
+ ): CompletableFuture =
+ // post /api/v1/likes/{owner}/{repo}
+ withRawResponse().update(params, requestOptions).thenApply { it.parse() }
+
+ override fun events(
+ params: ClientEventsParams,
+ requestOptions: RequestOptions,
+ ): CompletableFuture =
+ // post /api/v1/events
+ withRawResponse().events(params, requestOptions).thenApply { it.parse() }
+
+ override fun login(
+ params: ClientLoginParams,
+ requestOptions: RequestOptions,
+ ): CompletableFuture =
+ // post /api/v1/login
+ withRawResponse().login(params, requestOptions).thenApply { it.parse() }
+
+ override fun retrieveOk(
+ params: ClientRetrieveOkParams,
+ requestOptions: RequestOptions,
+ ): CompletableFuture =
+ // get /api/v1/ok
+ withRawResponse().retrieveOk(params, requestOptions).thenApply { it.parse() }
+
+ override fun close() = clientOptions.close()
+
+ class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) :
+ LangsmithClientAsync.WithRawResponse {
+
+ private val errorHandler: Handler =
+ errorHandler(errorBodyHandler(clientOptions.jsonMapper))
+
+ private val sessions: SessionServiceAsync.WithRawResponse by lazy {
+ SessionServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val orgs: OrgServiceAsync.WithRawResponse by lazy {
+ OrgServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val oauth: OAuthServiceAsync.WithRawResponse by lazy {
+ OAuthServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val sso: SsoServiceAsync.WithRawResponse by lazy {
+ SsoServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val apiKey: ApiKeyServiceAsync.WithRawResponse by lazy {
+ ApiKeyServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val examples: ExampleServiceAsync.WithRawResponse by lazy {
+ ExampleServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val datasets: DatasetServiceAsync.WithRawResponse by lazy {
+ DatasetServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val runs: RunServiceAsync.WithRawResponse by lazy {
+ RunServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val feedback: FeedbackServiceAsync.WithRawResponse by lazy {
+ FeedbackServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val public_: PublicServiceAsync.WithRawResponse by lazy {
+ PublicServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val annotationQueues: AnnotationQueueServiceAsync.WithRawResponse by lazy {
+ AnnotationQueueServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val ace: AceServiceAsync.WithRawResponse by lazy {
+ AceServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val bulkExports: BulkExportServiceAsync.WithRawResponse by lazy {
+ BulkExportServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val tenants: TenantServiceAsync.WithRawResponse by lazy {
+ TenantServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val info: InfoServiceAsync.WithRawResponse by lazy {
+ InfoServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val feedbackConfigs: FeedbackConfigServiceAsync.WithRawResponse by lazy {
+ FeedbackConfigServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val modelPriceMap: ModelPriceMapServiceAsync.WithRawResponse by lazy {
+ ModelPriceMapServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val usageLimits: UsageLimitServiceAsync.WithRawResponse by lazy {
+ UsageLimitServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val ttlSettings: TtlSettingServiceAsync.WithRawResponse by lazy {
+ TtlSettingServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val prompts: PromptServiceAsync.WithRawResponse by lazy {
+ PromptServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val promptWebhooks: PromptWebhookServiceAsync.WithRawResponse by lazy {
+ PromptWebhookServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val workspaces: WorkspaceServiceAsync.WithRawResponse by lazy {
+ WorkspaceServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val playgroundSettings: PlaygroundSettingServiceAsync.WithRawResponse by lazy {
+ PlaygroundSettingServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val me: MeServiceAsync.WithRawResponse by lazy {
+ MeServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val serviceAccounts: ServiceAccountServiceAsync.WithRawResponse by lazy {
+ ServiceAccountServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val charts: ChartServiceAsync.WithRawResponse by lazy {
+ ChartServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val orgCharts: OrgChartServiceAsync.WithRawResponse by lazy {
+ OrgChartServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val repos: RepoServiceAsync.WithRawResponse by lazy {
+ RepoServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val commits: CommitServiceAsync.WithRawResponse by lazy {
+ CommitServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val settings: SettingServiceAsync.WithRawResponse by lazy {
+ SettingServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val comments: CommentServiceAsync.WithRawResponse by lazy {
+ CommentServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val platform: PlatformServiceAsync.WithRawResponse by lazy {
+ PlatformServiceAsyncImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ override fun withOptions(
+ modifier: Consumer
+ ): LangsmithClientAsync.WithRawResponse =
+ LangsmithClientAsyncImpl.WithRawResponseImpl(
+ clientOptions.toBuilder().apply(modifier::accept).build()
+ )
+
+ override fun sessions(): SessionServiceAsync.WithRawResponse = sessions
+
+ override fun orgs(): OrgServiceAsync.WithRawResponse = orgs
+
+ override fun oauth(): OAuthServiceAsync.WithRawResponse = oauth
+
+ override fun sso(): SsoServiceAsync.WithRawResponse = sso
+
+ override fun apiKey(): ApiKeyServiceAsync.WithRawResponse = apiKey
+
+ override fun examples(): ExampleServiceAsync.WithRawResponse = examples
+
+ override fun datasets(): DatasetServiceAsync.WithRawResponse = datasets
+
+ override fun runs(): RunServiceAsync.WithRawResponse = runs
+
+ override fun feedback(): FeedbackServiceAsync.WithRawResponse = feedback
+
+ override fun public_(): PublicServiceAsync.WithRawResponse = public_
+
+ override fun annotationQueues(): AnnotationQueueServiceAsync.WithRawResponse =
+ annotationQueues
+
+ override fun ace(): AceServiceAsync.WithRawResponse = ace
+
+ override fun bulkExports(): BulkExportServiceAsync.WithRawResponse = bulkExports
+
+ override fun tenants(): TenantServiceAsync.WithRawResponse = tenants
+
+ override fun info(): InfoServiceAsync.WithRawResponse = info
+
+ override fun feedbackConfigs(): FeedbackConfigServiceAsync.WithRawResponse = feedbackConfigs
+
+ override fun modelPriceMap(): ModelPriceMapServiceAsync.WithRawResponse = modelPriceMap
+
+ override fun usageLimits(): UsageLimitServiceAsync.WithRawResponse = usageLimits
+
+ override fun ttlSettings(): TtlSettingServiceAsync.WithRawResponse = ttlSettings
+
+ override fun prompts(): PromptServiceAsync.WithRawResponse = prompts
+
+ override fun promptWebhooks(): PromptWebhookServiceAsync.WithRawResponse = promptWebhooks
+
+ override fun workspaces(): WorkspaceServiceAsync.WithRawResponse = workspaces
+
+ override fun playgroundSettings(): PlaygroundSettingServiceAsync.WithRawResponse =
+ playgroundSettings
+
+ override fun me(): MeServiceAsync.WithRawResponse = me
+
+ override fun serviceAccounts(): ServiceAccountServiceAsync.WithRawResponse = serviceAccounts
+
+ override fun charts(): ChartServiceAsync.WithRawResponse = charts
+
+ override fun orgCharts(): OrgChartServiceAsync.WithRawResponse = orgCharts
+
+ override fun repos(): RepoServiceAsync.WithRawResponse = repos
+
+ override fun commits(): CommitServiceAsync.WithRawResponse = commits
+
+ override fun settings(): SettingServiceAsync.WithRawResponse = settings
+
+ override fun comments(): CommentServiceAsync.WithRawResponse = comments
+
+ override fun platform(): PlatformServiceAsync.WithRawResponse = platform
+
+ private val updateHandler: Handler =
+ jsonHandler(clientOptions.jsonMapper)
+
+ override fun update(
+ params: ClientUpdateParams,
+ requestOptions: RequestOptions,
+ ): CompletableFuture> {
+ // We check here instead of in the params builder because this can be specified
+ // positionally or in the params class.
+ checkRequired("repo", params.repo().getOrNull())
+ val request =
+ HttpRequest.builder()
+ .method(HttpMethod.POST)
+ .baseUrl(clientOptions.baseUrl())
+ .addPathSegments(
+ "api",
+ "v1",
+ "likes",
+ params._pathParam(0),
+ params._pathParam(1),
+ )
+ .body(json(clientOptions.jsonMapper, params._body()))
+ .build()
+ .prepareAsync(clientOptions, params)
+ val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions))
+ return request
+ .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) }
+ .thenApply { response ->
+ errorHandler.handle(response).parseable {
+ response
+ .use { updateHandler.handle(it) }
+ .also {
+ if (requestOptions.responseValidation!!) {
+ it.validate()
+ }
+ }
+ }
+ }
+ }
+
+ private val eventsHandler: Handler =
+ jsonHandler(clientOptions.jsonMapper)
+
+ override fun events(
+ params: ClientEventsParams,
+ requestOptions: RequestOptions,
+ ): CompletableFuture> {
+ val request =
+ HttpRequest.builder()
+ .method(HttpMethod.POST)
+ .baseUrl(clientOptions.baseUrl())
+ .addPathSegments("api", "v1", "events")
+ .body(json(clientOptions.jsonMapper, params._body()))
+ .build()
+ .prepareAsync(clientOptions, params)
+ val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions))
+ return request
+ .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) }
+ .thenApply { response ->
+ errorHandler.handle(response).parseable {
+ response
+ .use { eventsHandler.handle(it) }
+ .also {
+ if (requestOptions.responseValidation!!) {
+ it.validate()
+ }
+ }
+ }
+ }
+ }
+
+ private val loginHandler: Handler =
+ jsonHandler(clientOptions.jsonMapper)
+
+ override fun login(
+ params: ClientLoginParams,
+ requestOptions: RequestOptions,
+ ): CompletableFuture> {
+ val request =
+ HttpRequest.builder()
+ .method(HttpMethod.POST)
+ .baseUrl(clientOptions.baseUrl())
+ .addPathSegments("api", "v1", "login")
+ .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } }
+ .build()
+ .prepareAsync(clientOptions, params)
+ val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions))
+ return request
+ .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) }
+ .thenApply { response ->
+ errorHandler.handle(response).parseable {
+ response
+ .use { loginHandler.handle(it) }
+ .also {
+ if (requestOptions.responseValidation!!) {
+ it.validate()
+ }
+ }
+ }
+ }
+ }
+
+ private val retrieveOkHandler: Handler =
+ jsonHandler(clientOptions.jsonMapper)
+
+ override fun retrieveOk(
+ params: ClientRetrieveOkParams,
+ requestOptions: RequestOptions,
+ ): CompletableFuture> {
+ val request =
+ HttpRequest.builder()
+ .method(HttpMethod.GET)
+ .baseUrl(clientOptions.baseUrl())
+ .addPathSegments("api", "v1", "ok")
+ .build()
+ .prepareAsync(clientOptions, params)
+ val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions))
+ return request
+ .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) }
+ .thenApply { response ->
+ errorHandler.handle(response).parseable {
+ response
+ .use { retrieveOkHandler.handle(it) }
+ .also {
+ if (requestOptions.responseValidation!!) {
+ it.validate()
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/langsmith-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientImpl.kt b/langsmith-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientImpl.kt
new file mode 100644
index 00000000..4cdfb4d8
--- /dev/null
+++ b/langsmith-core/src/main/kotlin/com/langchain/smith/client/LangsmithClientImpl.kt
@@ -0,0 +1,629 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.langchain.smith.client
+
+import com.langchain.smith.core.ClientOptions
+import com.langchain.smith.core.RequestOptions
+import com.langchain.smith.core.checkRequired
+import com.langchain.smith.core.getPackageVersion
+import com.langchain.smith.core.handlers.errorBodyHandler
+import com.langchain.smith.core.handlers.errorHandler
+import com.langchain.smith.core.handlers.jsonHandler
+import com.langchain.smith.core.http.HttpMethod
+import com.langchain.smith.core.http.HttpRequest
+import com.langchain.smith.core.http.HttpResponse
+import com.langchain.smith.core.http.HttpResponse.Handler
+import com.langchain.smith.core.http.HttpResponseFor
+import com.langchain.smith.core.http.json
+import com.langchain.smith.core.http.parseable
+import com.langchain.smith.core.prepare
+import com.langchain.smith.models.ClientEventsParams
+import com.langchain.smith.models.ClientEventsResponse
+import com.langchain.smith.models.ClientLoginParams
+import com.langchain.smith.models.ClientLoginResponse
+import com.langchain.smith.models.ClientRetrieveOkParams
+import com.langchain.smith.models.ClientRetrieveOkResponse
+import com.langchain.smith.models.ClientUpdateParams
+import com.langchain.smith.models.ClientUpdateResponse
+import com.langchain.smith.services.blocking.AceService
+import com.langchain.smith.services.blocking.AceServiceImpl
+import com.langchain.smith.services.blocking.AnnotationQueueService
+import com.langchain.smith.services.blocking.AnnotationQueueServiceImpl
+import com.langchain.smith.services.blocking.ApiKeyService
+import com.langchain.smith.services.blocking.ApiKeyServiceImpl
+import com.langchain.smith.services.blocking.BulkExportService
+import com.langchain.smith.services.blocking.BulkExportServiceImpl
+import com.langchain.smith.services.blocking.ChartService
+import com.langchain.smith.services.blocking.ChartServiceImpl
+import com.langchain.smith.services.blocking.CommentService
+import com.langchain.smith.services.blocking.CommentServiceImpl
+import com.langchain.smith.services.blocking.CommitService
+import com.langchain.smith.services.blocking.CommitServiceImpl
+import com.langchain.smith.services.blocking.DatasetService
+import com.langchain.smith.services.blocking.DatasetServiceImpl
+import com.langchain.smith.services.blocking.ExampleService
+import com.langchain.smith.services.blocking.ExampleServiceImpl
+import com.langchain.smith.services.blocking.FeedbackConfigService
+import com.langchain.smith.services.blocking.FeedbackConfigServiceImpl
+import com.langchain.smith.services.blocking.FeedbackService
+import com.langchain.smith.services.blocking.FeedbackServiceImpl
+import com.langchain.smith.services.blocking.InfoService
+import com.langchain.smith.services.blocking.InfoServiceImpl
+import com.langchain.smith.services.blocking.MeService
+import com.langchain.smith.services.blocking.MeServiceImpl
+import com.langchain.smith.services.blocking.ModelPriceMapService
+import com.langchain.smith.services.blocking.ModelPriceMapServiceImpl
+import com.langchain.smith.services.blocking.OAuthService
+import com.langchain.smith.services.blocking.OAuthServiceImpl
+import com.langchain.smith.services.blocking.OrgChartService
+import com.langchain.smith.services.blocking.OrgChartServiceImpl
+import com.langchain.smith.services.blocking.OrgService
+import com.langchain.smith.services.blocking.OrgServiceImpl
+import com.langchain.smith.services.blocking.PlatformService
+import com.langchain.smith.services.blocking.PlatformServiceImpl
+import com.langchain.smith.services.blocking.PlaygroundSettingService
+import com.langchain.smith.services.blocking.PlaygroundSettingServiceImpl
+import com.langchain.smith.services.blocking.PromptService
+import com.langchain.smith.services.blocking.PromptServiceImpl
+import com.langchain.smith.services.blocking.PromptWebhookService
+import com.langchain.smith.services.blocking.PromptWebhookServiceImpl
+import com.langchain.smith.services.blocking.PublicService
+import com.langchain.smith.services.blocking.PublicServiceImpl
+import com.langchain.smith.services.blocking.RepoService
+import com.langchain.smith.services.blocking.RepoServiceImpl
+import com.langchain.smith.services.blocking.RunService
+import com.langchain.smith.services.blocking.RunServiceImpl
+import com.langchain.smith.services.blocking.ServiceAccountService
+import com.langchain.smith.services.blocking.ServiceAccountServiceImpl
+import com.langchain.smith.services.blocking.SessionService
+import com.langchain.smith.services.blocking.SessionServiceImpl
+import com.langchain.smith.services.blocking.SettingService
+import com.langchain.smith.services.blocking.SettingServiceImpl
+import com.langchain.smith.services.blocking.SsoService
+import com.langchain.smith.services.blocking.SsoServiceImpl
+import com.langchain.smith.services.blocking.TenantService
+import com.langchain.smith.services.blocking.TenantServiceImpl
+import com.langchain.smith.services.blocking.TtlSettingService
+import com.langchain.smith.services.blocking.TtlSettingServiceImpl
+import com.langchain.smith.services.blocking.UsageLimitService
+import com.langchain.smith.services.blocking.UsageLimitServiceImpl
+import com.langchain.smith.services.blocking.WorkspaceService
+import com.langchain.smith.services.blocking.WorkspaceServiceImpl
+import java.util.function.Consumer
+import kotlin.jvm.optionals.getOrNull
+
+class LangsmithClientImpl(private val clientOptions: ClientOptions) : LangsmithClient {
+
+ private val clientOptionsWithUserAgent =
+ if (clientOptions.headers.names().contains("User-Agent")) clientOptions
+ else
+ clientOptions
+ .toBuilder()
+ .putHeader("User-Agent", "${javaClass.simpleName}/Java ${getPackageVersion()}")
+ .build()
+
+ // Pass the original clientOptions so that this client sets its own User-Agent.
+ private val async: LangsmithClientAsync by lazy { LangsmithClientAsyncImpl(clientOptions) }
+
+ private val withRawResponse: LangsmithClient.WithRawResponse by lazy {
+ WithRawResponseImpl(clientOptions)
+ }
+
+ private val sessions: SessionService by lazy { SessionServiceImpl(clientOptionsWithUserAgent) }
+
+ private val orgs: OrgService by lazy { OrgServiceImpl(clientOptionsWithUserAgent) }
+
+ private val oauth: OAuthService by lazy { OAuthServiceImpl(clientOptionsWithUserAgent) }
+
+ private val sso: SsoService by lazy { SsoServiceImpl(clientOptionsWithUserAgent) }
+
+ private val apiKey: ApiKeyService by lazy { ApiKeyServiceImpl(clientOptionsWithUserAgent) }
+
+ private val examples: ExampleService by lazy { ExampleServiceImpl(clientOptionsWithUserAgent) }
+
+ private val datasets: DatasetService by lazy { DatasetServiceImpl(clientOptionsWithUserAgent) }
+
+ private val runs: RunService by lazy { RunServiceImpl(clientOptionsWithUserAgent) }
+
+ private val feedback: FeedbackService by lazy {
+ FeedbackServiceImpl(clientOptionsWithUserAgent)
+ }
+
+ private val public_: PublicService by lazy { PublicServiceImpl(clientOptionsWithUserAgent) }
+
+ private val annotationQueues: AnnotationQueueService by lazy {
+ AnnotationQueueServiceImpl(clientOptionsWithUserAgent)
+ }
+
+ private val ace: AceService by lazy { AceServiceImpl(clientOptionsWithUserAgent) }
+
+ private val bulkExports: BulkExportService by lazy {
+ BulkExportServiceImpl(clientOptionsWithUserAgent)
+ }
+
+ private val tenants: TenantService by lazy { TenantServiceImpl(clientOptionsWithUserAgent) }
+
+ private val info: InfoService by lazy { InfoServiceImpl(clientOptionsWithUserAgent) }
+
+ private val feedbackConfigs: FeedbackConfigService by lazy {
+ FeedbackConfigServiceImpl(clientOptionsWithUserAgent)
+ }
+
+ private val modelPriceMap: ModelPriceMapService by lazy {
+ ModelPriceMapServiceImpl(clientOptionsWithUserAgent)
+ }
+
+ private val usageLimits: UsageLimitService by lazy {
+ UsageLimitServiceImpl(clientOptionsWithUserAgent)
+ }
+
+ private val ttlSettings: TtlSettingService by lazy {
+ TtlSettingServiceImpl(clientOptionsWithUserAgent)
+ }
+
+ private val prompts: PromptService by lazy { PromptServiceImpl(clientOptionsWithUserAgent) }
+
+ private val promptWebhooks: PromptWebhookService by lazy {
+ PromptWebhookServiceImpl(clientOptionsWithUserAgent)
+ }
+
+ private val workspaces: WorkspaceService by lazy {
+ WorkspaceServiceImpl(clientOptionsWithUserAgent)
+ }
+
+ private val playgroundSettings: PlaygroundSettingService by lazy {
+ PlaygroundSettingServiceImpl(clientOptionsWithUserAgent)
+ }
+
+ private val me: MeService by lazy { MeServiceImpl(clientOptionsWithUserAgent) }
+
+ private val serviceAccounts: ServiceAccountService by lazy {
+ ServiceAccountServiceImpl(clientOptionsWithUserAgent)
+ }
+
+ private val charts: ChartService by lazy { ChartServiceImpl(clientOptionsWithUserAgent) }
+
+ private val orgCharts: OrgChartService by lazy {
+ OrgChartServiceImpl(clientOptionsWithUserAgent)
+ }
+
+ private val repos: RepoService by lazy { RepoServiceImpl(clientOptionsWithUserAgent) }
+
+ private val commits: CommitService by lazy { CommitServiceImpl(clientOptionsWithUserAgent) }
+
+ private val settings: SettingService by lazy { SettingServiceImpl(clientOptionsWithUserAgent) }
+
+ private val comments: CommentService by lazy { CommentServiceImpl(clientOptionsWithUserAgent) }
+
+ private val platform: PlatformService by lazy {
+ PlatformServiceImpl(clientOptionsWithUserAgent)
+ }
+
+ override fun async(): LangsmithClientAsync = async
+
+ override fun withRawResponse(): LangsmithClient.WithRawResponse = withRawResponse
+
+ override fun withOptions(modifier: Consumer): LangsmithClient =
+ LangsmithClientImpl(clientOptions.toBuilder().apply(modifier::accept).build())
+
+ override fun sessions(): SessionService = sessions
+
+ override fun orgs(): OrgService = orgs
+
+ override fun oauth(): OAuthService = oauth
+
+ override fun sso(): SsoService = sso
+
+ override fun apiKey(): ApiKeyService = apiKey
+
+ override fun examples(): ExampleService = examples
+
+ override fun datasets(): DatasetService = datasets
+
+ override fun runs(): RunService = runs
+
+ override fun feedback(): FeedbackService = feedback
+
+ override fun public_(): PublicService = public_
+
+ override fun annotationQueues(): AnnotationQueueService = annotationQueues
+
+ override fun ace(): AceService = ace
+
+ override fun bulkExports(): BulkExportService = bulkExports
+
+ override fun tenants(): TenantService = tenants
+
+ override fun info(): InfoService = info
+
+ override fun feedbackConfigs(): FeedbackConfigService = feedbackConfigs
+
+ override fun modelPriceMap(): ModelPriceMapService = modelPriceMap
+
+ override fun usageLimits(): UsageLimitService = usageLimits
+
+ override fun ttlSettings(): TtlSettingService = ttlSettings
+
+ override fun prompts(): PromptService = prompts
+
+ override fun promptWebhooks(): PromptWebhookService = promptWebhooks
+
+ override fun workspaces(): WorkspaceService = workspaces
+
+ override fun playgroundSettings(): PlaygroundSettingService = playgroundSettings
+
+ override fun me(): MeService = me
+
+ override fun serviceAccounts(): ServiceAccountService = serviceAccounts
+
+ override fun charts(): ChartService = charts
+
+ override fun orgCharts(): OrgChartService = orgCharts
+
+ override fun repos(): RepoService = repos
+
+ override fun commits(): CommitService = commits
+
+ override fun settings(): SettingService = settings
+
+ override fun comments(): CommentService = comments
+
+ override fun platform(): PlatformService = platform
+
+ override fun update(
+ params: ClientUpdateParams,
+ requestOptions: RequestOptions,
+ ): ClientUpdateResponse =
+ // post /api/v1/likes/{owner}/{repo}
+ withRawResponse().update(params, requestOptions).parse()
+
+ override fun events(
+ params: ClientEventsParams,
+ requestOptions: RequestOptions,
+ ): ClientEventsResponse =
+ // post /api/v1/events
+ withRawResponse().events(params, requestOptions).parse()
+
+ override fun login(
+ params: ClientLoginParams,
+ requestOptions: RequestOptions,
+ ): ClientLoginResponse =
+ // post /api/v1/login
+ withRawResponse().login(params, requestOptions).parse()
+
+ override fun retrieveOk(
+ params: ClientRetrieveOkParams,
+ requestOptions: RequestOptions,
+ ): ClientRetrieveOkResponse =
+ // get /api/v1/ok
+ withRawResponse().retrieveOk(params, requestOptions).parse()
+
+ override fun close() = clientOptions.close()
+
+ class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) :
+ LangsmithClient.WithRawResponse {
+
+ private val errorHandler: Handler =
+ errorHandler(errorBodyHandler(clientOptions.jsonMapper))
+
+ private val sessions: SessionService.WithRawResponse by lazy {
+ SessionServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val orgs: OrgService.WithRawResponse by lazy {
+ OrgServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val oauth: OAuthService.WithRawResponse by lazy {
+ OAuthServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val sso: SsoService.WithRawResponse by lazy {
+ SsoServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val apiKey: ApiKeyService.WithRawResponse by lazy {
+ ApiKeyServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val examples: ExampleService.WithRawResponse by lazy {
+ ExampleServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val datasets: DatasetService.WithRawResponse by lazy {
+ DatasetServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val runs: RunService.WithRawResponse by lazy {
+ RunServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val feedback: FeedbackService.WithRawResponse by lazy {
+ FeedbackServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val public_: PublicService.WithRawResponse by lazy {
+ PublicServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val annotationQueues: AnnotationQueueService.WithRawResponse by lazy {
+ AnnotationQueueServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val ace: AceService.WithRawResponse by lazy {
+ AceServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val bulkExports: BulkExportService.WithRawResponse by lazy {
+ BulkExportServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val tenants: TenantService.WithRawResponse by lazy {
+ TenantServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val info: InfoService.WithRawResponse by lazy {
+ InfoServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val feedbackConfigs: FeedbackConfigService.WithRawResponse by lazy {
+ FeedbackConfigServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val modelPriceMap: ModelPriceMapService.WithRawResponse by lazy {
+ ModelPriceMapServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val usageLimits: UsageLimitService.WithRawResponse by lazy {
+ UsageLimitServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val ttlSettings: TtlSettingService.WithRawResponse by lazy {
+ TtlSettingServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val prompts: PromptService.WithRawResponse by lazy {
+ PromptServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val promptWebhooks: PromptWebhookService.WithRawResponse by lazy {
+ PromptWebhookServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val workspaces: WorkspaceService.WithRawResponse by lazy {
+ WorkspaceServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val playgroundSettings: PlaygroundSettingService.WithRawResponse by lazy {
+ PlaygroundSettingServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val me: MeService.WithRawResponse by lazy {
+ MeServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val serviceAccounts: ServiceAccountService.WithRawResponse by lazy {
+ ServiceAccountServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val charts: ChartService.WithRawResponse by lazy {
+ ChartServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val orgCharts: OrgChartService.WithRawResponse by lazy {
+ OrgChartServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val repos: RepoService.WithRawResponse by lazy {
+ RepoServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val commits: CommitService.WithRawResponse by lazy {
+ CommitServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val settings: SettingService.WithRawResponse by lazy {
+ SettingServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val comments: CommentService.WithRawResponse by lazy {
+ CommentServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ private val platform: PlatformService.WithRawResponse by lazy {
+ PlatformServiceImpl.WithRawResponseImpl(clientOptions)
+ }
+
+ override fun withOptions(
+ modifier: Consumer
+ ): LangsmithClient.WithRawResponse =
+ LangsmithClientImpl.WithRawResponseImpl(
+ clientOptions.toBuilder().apply(modifier::accept).build()
+ )
+
+ override fun sessions(): SessionService.WithRawResponse = sessions
+
+ override fun orgs(): OrgService.WithRawResponse = orgs
+
+ override fun oauth(): OAuthService.WithRawResponse = oauth
+
+ override fun sso(): SsoService.WithRawResponse = sso
+
+ override fun apiKey(): ApiKeyService.WithRawResponse = apiKey
+
+ override fun examples(): ExampleService.WithRawResponse = examples
+
+ override fun datasets(): DatasetService.WithRawResponse = datasets
+
+ override fun runs(): RunService.WithRawResponse = runs
+
+ override fun feedback(): FeedbackService.WithRawResponse = feedback
+
+ override fun public_(): PublicService.WithRawResponse = public_
+
+ override fun annotationQueues(): AnnotationQueueService.WithRawResponse = annotationQueues
+
+ override fun ace(): AceService.WithRawResponse = ace
+
+ override fun bulkExports(): BulkExportService.WithRawResponse = bulkExports
+
+ override fun tenants(): TenantService.WithRawResponse = tenants
+
+ override fun info(): InfoService.WithRawResponse = info
+
+ override fun feedbackConfigs(): FeedbackConfigService.WithRawResponse = feedbackConfigs
+
+ override fun modelPriceMap(): ModelPriceMapService.WithRawResponse = modelPriceMap
+
+ override fun usageLimits(): UsageLimitService.WithRawResponse = usageLimits
+
+ override fun ttlSettings(): TtlSettingService.WithRawResponse = ttlSettings
+
+ override fun prompts(): PromptService.WithRawResponse = prompts
+
+ override fun promptWebhooks(): PromptWebhookService.WithRawResponse = promptWebhooks
+
+ override fun workspaces(): WorkspaceService.WithRawResponse = workspaces
+
+ override fun playgroundSettings(): PlaygroundSettingService.WithRawResponse =
+ playgroundSettings
+
+ override fun me(): MeService.WithRawResponse = me
+
+ override fun serviceAccounts(): ServiceAccountService.WithRawResponse = serviceAccounts
+
+ override fun charts(): ChartService.WithRawResponse = charts
+
+ override fun orgCharts(): OrgChartService.WithRawResponse = orgCharts
+
+ override fun repos(): RepoService.WithRawResponse = repos
+
+ override fun commits(): CommitService.WithRawResponse = commits
+
+ override fun settings(): SettingService.WithRawResponse = settings
+
+ override fun comments(): CommentService.WithRawResponse = comments
+
+ override fun platform(): PlatformService.WithRawResponse = platform
+
+ private val updateHandler: Handler =
+ jsonHandler(clientOptions.jsonMapper)
+
+ override fun update(
+ params: ClientUpdateParams,
+ requestOptions: RequestOptions,
+ ): HttpResponseFor {
+ // We check here instead of in the params builder because this can be specified
+ // positionally or in the params class.
+ checkRequired("repo", params.repo().getOrNull())
+ val request =
+ HttpRequest.builder()
+ .method(HttpMethod.POST)
+ .baseUrl(clientOptions.baseUrl())
+ .addPathSegments(
+ "api",
+ "v1",
+ "likes",
+ params._pathParam(0),
+ params._pathParam(1),
+ )
+ .body(json(clientOptions.jsonMapper, params._body()))
+ .build()
+ .prepare(clientOptions, params)
+ val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions))
+ val response = clientOptions.httpClient.execute(request, requestOptions)
+ return errorHandler.handle(response).parseable {
+ response
+ .use { updateHandler.handle(it) }
+ .also {
+ if (requestOptions.responseValidation!!) {
+ it.validate()
+ }
+ }
+ }
+ }
+
+ private val eventsHandler: Handler =
+ jsonHandler(clientOptions.jsonMapper)
+
+ override fun events(
+ params: ClientEventsParams,
+ requestOptions: RequestOptions,
+ ): HttpResponseFor {
+ val request =
+ HttpRequest.builder()
+ .method(HttpMethod.POST)
+ .baseUrl(clientOptions.baseUrl())
+ .addPathSegments("api", "v1", "events")
+ .body(json(clientOptions.jsonMapper, params._body()))
+ .build()
+ .prepare(clientOptions, params)
+ val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions))
+ val response = clientOptions.httpClient.execute(request, requestOptions)
+ return errorHandler.handle(response).parseable {
+ response
+ .use { eventsHandler.handle(it) }
+ .also {
+ if (requestOptions.responseValidation!!) {
+ it.validate()
+ }
+ }
+ }
+ }
+
+ private val loginHandler: Handler =
+ jsonHandler(clientOptions.jsonMapper)
+
+ override fun login(
+ params: ClientLoginParams,
+ requestOptions: RequestOptions,
+ ): HttpResponseFor {
+ val request =
+ HttpRequest.builder()
+ .method(HttpMethod.POST)
+ .baseUrl(clientOptions.baseUrl())
+ .addPathSegments("api", "v1", "login")
+ .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } }
+ .build()
+ .prepare(clientOptions, params)
+ val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions))
+ val response = clientOptions.httpClient.execute(request, requestOptions)
+ return errorHandler.handle(response).parseable {
+ response
+ .use { loginHandler.handle(it) }
+ .also {
+ if (requestOptions.responseValidation!!) {
+ it.validate()
+ }
+ }
+ }
+ }
+
+ private val retrieveOkHandler: Handler =
+ jsonHandler(clientOptions.jsonMapper)
+
+ override fun retrieveOk(
+ params: ClientRetrieveOkParams,
+ requestOptions: RequestOptions,
+ ): HttpResponseFor {
+ val request =
+ HttpRequest.builder()
+ .method(HttpMethod.GET)
+ .baseUrl(clientOptions.baseUrl())
+ .addPathSegments("api", "v1", "ok")
+ .build()
+ .prepare(clientOptions, params)
+ val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions))
+ val response = clientOptions.httpClient.execute(request, requestOptions)
+ return errorHandler.handle(response).parseable {
+ response
+ .use { retrieveOkHandler.handle(it) }
+ .also {
+ if (requestOptions.responseValidation!!) {
+ it.validate()
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/langsmith-core/src/main/kotlin/com/langchain/smith/core/BaseDeserializer.kt b/langsmith-core/src/main/kotlin/com/langchain/smith/core/BaseDeserializer.kt
new file mode 100644
index 00000000..01abff27
--- /dev/null
+++ b/langsmith-core/src/main/kotlin/com/langchain/smith/core/BaseDeserializer.kt
@@ -0,0 +1,44 @@
+package com.langchain.smith.core
+
+import com.fasterxml.jackson.core.JsonParser
+import com.fasterxml.jackson.core.ObjectCodec
+import com.fasterxml.jackson.core.type.TypeReference
+import com.fasterxml.jackson.databind.BeanProperty
+import com.fasterxml.jackson.databind.DeserializationContext
+import com.fasterxml.jackson.databind.JavaType
+import com.fasterxml.jackson.databind.JsonDeserializer
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.deser.ContextualDeserializer
+import com.fasterxml.jackson.databind.deser.std.StdDeserializer
+import kotlin.reflect.KClass
+
+abstract class BaseDeserializer(type: KClass) :
+ StdDeserializer(type.java), ContextualDeserializer {
+
+ override fun createContextual(
+ context: DeserializationContext,
+ property: BeanProperty?,
+ ): JsonDeserializer {
+ return this
+ }
+
+ override fun deserialize(parser: JsonParser, context: DeserializationContext): T {
+ return parser.codec.deserialize(parser.readValueAsTree())
+ }
+
+ protected abstract fun ObjectCodec.deserialize(node: JsonNode): T
+
+ protected fun ObjectCodec.tryDeserialize(node: JsonNode, type: TypeReference): T? =
+ try {
+ readValue(treeAsTokens(node), type)
+ } catch (e: Exception) {
+ null
+ }
+
+ protected fun ObjectCodec.tryDeserialize(node: JsonNode, type: JavaType): T? =
+ try {
+ readValue(treeAsTokens(node), type)
+ } catch (e: Exception) {
+ null
+ }
+}
diff --git a/langsmith-core/src/main/kotlin/com/langchain/smith/core/BaseSerializer.kt b/langsmith-core/src/main/kotlin/com/langchain/smith/core/BaseSerializer.kt
new file mode 100644
index 00000000..46ab325a
--- /dev/null
+++ b/langsmith-core/src/main/kotlin/com/langchain/smith/core/BaseSerializer.kt
@@ -0,0 +1,6 @@
+package com.langchain.smith.core
+
+import com.fasterxml.jackson.databind.ser.std.StdSerializer
+import kotlin.reflect.KClass
+
+abstract class BaseSerializer(type: KClass) : StdSerializer(type.java)
diff --git a/langsmith-core/src/main/kotlin/com/langchain/smith/core/Check.kt b/langsmith-core/src/main/kotlin/com/langchain/smith/core/Check.kt
new file mode 100644
index 00000000..0d2d8455
--- /dev/null
+++ b/langsmith-core/src/main/kotlin/com/langchain/smith/core/Check.kt
@@ -0,0 +1,96 @@
+@file:JvmName("Check")
+
+package com.langchain.smith.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" }
+
+@JvmSynthetic
+internal fun checkKnown(name: String, value: JsonField): T =
+ value.asKnown().orElseThrow {
+ IllegalStateException("`$name` is not a known type: ${value.javaClass.simpleName}")
+ }
+
+@JvmSynthetic
+internal fun checkKnown(name: String, value: MultipartField): T =
+ value.value.asKnown().orElseThrow {
+ IllegalStateException("`$name` is not a known type: ${value.javaClass.simpleName}")
+ }
+
+@JvmSynthetic
+internal fun checkLength(name: String, value: String, length: Int): String =
+ value.also {
+ check(it.length == length) { "`$name` must have length $length, but was ${it.length}" }
+ }
+
+@JvmSynthetic
+internal fun checkMinLength(name: String, value: String, minLength: Int): String =
+ value.also {
+ check(it.length >= minLength) {
+ if (minLength == 1) "`$name` must be non-empty, but was empty"
+ else "`$name` must have at least length $minLength, but was ${it.length}"
+ }
+ }
+
+@JvmSynthetic
+internal fun checkMaxLength(name: String, value: String, maxLength: Int): String =
+ value.also {
+ check(it.length <= maxLength) {
+ "`$name` must have at most length $maxLength, but was ${it.length}"
+ }
+ }
+
+@JvmSynthetic
+internal fun checkJacksonVersionCompatibility() {
+ val incompatibleJacksonVersions =
+ RUNTIME_JACKSON_VERSIONS.mapNotNull {
+ val badVersionReason = BAD_JACKSON_VERSIONS[it.toString()]
+ when {
+ it.majorVersion != MINIMUM_JACKSON_VERSION.majorVersion ->
+ it to "incompatible major version"
+ it.minorVersion < MINIMUM_JACKSON_VERSION.minorVersion ->
+ it to "minor version too low"
+ it.minorVersion == MINIMUM_JACKSON_VERSION.minorVersion &&
+ it.patchLevel < MINIMUM_JACKSON_VERSION.patchLevel ->
+ it to "patch version too low"
+ badVersionReason != null -> it to badVersionReason
+ else -> null
+ }
+ }
+ check(incompatibleJacksonVersions.isEmpty()) {
+ """
+This SDK requires a minimum Jackson version of $MINIMUM_JACKSON_VERSION, but the following incompatible Jackson versions were detected at runtime:
+
+${incompatibleJacksonVersions.asSequence().map { (version, incompatibilityReason) ->
+ "- `${version.toFullString().replace("/", ":")}` ($incompatibilityReason)"
+}.joinToString("\n")}
+
+This can happen if you are either:
+1. Directly depending on different Jackson versions
+2. Depending on some library that depends on different Jackson versions, potentially transitively
+
+Double-check that you are depending on compatible Jackson versions.
+
+See https://www.github.com/stainless-sdks/langsmith-api-java#jackson for more information.
+ """
+ .trimIndent()
+ }
+}
+
+private val MINIMUM_JACKSON_VERSION: Version = VersionUtil.parseVersion("2.13.4", null, null)
+private val BAD_JACKSON_VERSIONS: Map =
+ mapOf("2.18.1" to "due to https://github.com/FasterXML/jackson-databind/issues/4639")
+private val RUNTIME_JACKSON_VERSIONS: List =
+ listOf(
+ com.fasterxml.jackson.core.json.PackageVersion.VERSION,
+ com.fasterxml.jackson.databind.cfg.PackageVersion.VERSION,
+ com.fasterxml.jackson.datatype.jdk8.PackageVersion.VERSION,
+ com.fasterxml.jackson.datatype.jsr310.PackageVersion.VERSION,
+ com.fasterxml.jackson.module.kotlin.PackageVersion.VERSION,
+ )
diff --git a/langsmith-core/src/main/kotlin/com/langchain/smith/core/ClientOptions.kt b/langsmith-core/src/main/kotlin/com/langchain/smith/core/ClientOptions.kt
new file mode 100644
index 00000000..7fb70a01
--- /dev/null
+++ b/langsmith-core/src/main/kotlin/com/langchain/smith/core/ClientOptions.kt
@@ -0,0 +1,520 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.langchain.smith.core
+
+import com.fasterxml.jackson.databind.json.JsonMapper
+import com.langchain.smith.core.http.Headers
+import com.langchain.smith.core.http.HttpClient
+import com.langchain.smith.core.http.PhantomReachableClosingHttpClient
+import com.langchain.smith.core.http.QueryParams
+import com.langchain.smith.core.http.RetryingHttpClient
+import java.time.Clock
+import java.time.Duration
+import java.util.Optional
+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 `langsmith-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.langchain.smith.core.jsonMapper]. The default is usually sufficient and
+ * rarely needs to be overridden.
+ */
+ @get:JvmName("jsonMapper") val jsonMapper: JsonMapper,
+ /**
+ * The interface to use for delaying execution, like during retries.
+ *
+ * This is primarily useful for using fake delays in tests.
+ *
+ * Defaults to real execution delays.
+ *
+ * This class takes ownership of the sleeper and closes it when closed.
+ */
+ @get:JvmName("sleeper") val sleeper: Sleeper,
+ /**
+ * 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,
+ 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?,
+ private val tenantId: String?,
+ private val bearerToken: String?,
+ private val organizationId: String?,
+) {
+
+ init {
+ if (checkJacksonVersionCompatibility) {
+ checkJacksonVersionCompatibility()
+ }
+ }
+
+ /**
+ * The base URL to use for every request.
+ *
+ * Defaults to the production environment: `https://api.example.com`.
+ */
+ fun baseUrl(): String = baseUrl ?: PRODUCTION_URL
+
+ fun apiKey(): Optional = Optional.ofNullable(apiKey)
+
+ fun tenantId(): Optional = Optional.ofNullable(tenantId)
+
+ /**
+ * Bearer tokens are used to authenticate from the UI. Must also specify x-tenant-id or
+ * x-organization-id (for org scoped apis).
+ */
+ fun bearerToken(): Optional = Optional.ofNullable(bearerToken)
+
+ fun organizationId(): Optional = Optional.ofNullable(organizationId)
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ const val PRODUCTION_URL = "https://api.example.com"
+
+ /**
+ * Returns a mutable builder for constructing an instance of [ClientOptions].
+ *
+ * The following fields are required:
+ * ```java
+ * .httpClient()
+ * ```
+ */
+ @JvmStatic fun builder() = Builder()
+
+ /**
+ * Returns options configured using system properties and environment variables.
+ *
+ * @see Builder.fromEnv
+ */
+ @JvmStatic fun fromEnv(): ClientOptions = builder().fromEnv().build()
+ }
+
+ /** A builder for [ClientOptions]. */
+ class Builder internal constructor() {
+
+ private var httpClient: HttpClient? = null
+ private var checkJacksonVersionCompatibility: Boolean = true
+ private var jsonMapper: JsonMapper = jsonMapper()
+ private var sleeper: Sleeper? = null
+ private var clock: Clock = Clock.systemUTC()
+ private var baseUrl: String? = null
+ private var headers: Headers.Builder = Headers.builder()
+ private var queryParams: QueryParams.Builder = QueryParams.builder()
+ private var responseValidation: Boolean = false
+ private var timeout: Timeout = Timeout.default()
+ private var maxRetries: Int = 2
+ private var apiKey: String? = null
+ private var tenantId: String? = null
+ private var bearerToken: String? = null
+ private var organizationId: String? = null
+
+ @JvmSynthetic
+ internal fun from(clientOptions: ClientOptions) = apply {
+ httpClient = clientOptions.originalHttpClient
+ checkJacksonVersionCompatibility = clientOptions.checkJacksonVersionCompatibility
+ jsonMapper = clientOptions.jsonMapper
+ sleeper = clientOptions.sleeper
+ clock = clientOptions.clock
+ baseUrl = clientOptions.baseUrl
+ headers = clientOptions.headers.toBuilder()
+ queryParams = clientOptions.queryParams.toBuilder()
+ responseValidation = clientOptions.responseValidation
+ timeout = clientOptions.timeout
+ maxRetries = clientOptions.maxRetries
+ apiKey = clientOptions.apiKey
+ tenantId = clientOptions.tenantId
+ bearerToken = clientOptions.bearerToken
+ organizationId = clientOptions.organizationId
+ }
+
+ /**
+ * The HTTP client to use in the SDK.
+ *
+ * Use the one published in `langsmith-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.langchain.smith.core.jsonMapper]. The default is usually sufficient and
+ * rarely needs to be overridden.
+ */
+ fun jsonMapper(jsonMapper: JsonMapper) = apply { this.jsonMapper = jsonMapper }
+
+ /**
+ * The interface to use for delaying execution, like during retries.
+ *
+ * This is primarily useful for using fake delays in tests.
+ *
+ * Defaults to real execution delays.
+ *
+ * This class takes ownership of the sleeper and closes it when closed.
+ */
+ fun sleeper(sleeper: Sleeper) = apply { this.sleeper = PhantomReachableSleeper(sleeper) }
+
+ /**
+ * 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 }
+
+ /**
+ * The base URL to use for every request.
+ *
+ * Defaults to the production environment: `https://api.example.com`.
+ */
+ 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 }
+
+ /** Alias for calling [Builder.apiKey] with `apiKey.orElse(null)`. */
+ fun apiKey(apiKey: Optional) = apiKey(apiKey.getOrNull())
+
+ fun tenantId(tenantId: String?) = apply { this.tenantId = tenantId }
+
+ /** Alias for calling [Builder.tenantId] with `tenantId.orElse(null)`. */
+ fun tenantId(tenantId: Optional) = tenantId(tenantId.getOrNull())
+
+ /**
+ * Bearer tokens are used to authenticate from the UI. Must also specify x-tenant-id or
+ * x-organization-id (for org scoped apis).
+ */
+ fun bearerToken(bearerToken: String?) = apply { this.bearerToken = bearerToken }
+
+ /** Alias for calling [Builder.bearerToken] with `bearerToken.orElse(null)`. */
+ fun bearerToken(bearerToken: Optional) = bearerToken(bearerToken.getOrNull())
+
+ fun organizationId(organizationId: String?) = apply { this.organizationId = organizationId }
+
+ /** Alias for calling [Builder.organizationId] with `organizationId.orElse(null)`. */
+ fun organizationId(organizationId: Optional) =
+ organizationId(organizationId.getOrNull())
+
+ fun headers(headers: Headers) = apply {
+ this.headers.clear()
+ putAllHeaders(headers)
+ }
+
+ fun headers(headers: Map>) = apply {
+ this.headers.clear()
+ putAllHeaders(headers)
+ }
+
+ fun putHeader(name: String, value: String) = apply { headers.put(name, value) }
+
+ fun putHeaders(name: String, values: Iterable) = apply { headers.put(name, values) }
+
+ fun putAllHeaders(headers: Headers) = apply { this.headers.putAll(headers) }
+
+ fun putAllHeaders(headers: Map>) = apply {
+ this.headers.putAll(headers)
+ }
+
+ fun replaceHeaders(name: String, value: String) = apply { headers.replace(name, value) }
+
+ fun replaceHeaders(name: String, values: Iterable) = apply {
+ headers.replace(name, values)
+ }
+
+ fun replaceAllHeaders(headers: Headers) = apply { this.headers.replaceAll(headers) }
+
+ fun replaceAllHeaders(headers: Map>) = apply {
+ this.headers.replaceAll(headers)
+ }
+
+ fun removeHeaders(name: String) = apply { headers.remove(name) }
+
+ fun removeAllHeaders(names: Set) = apply { headers.removeAll(names) }
+
+ fun queryParams(queryParams: QueryParams) = apply {
+ this.queryParams.clear()
+ putAllQueryParams(queryParams)
+ }
+
+ fun queryParams(queryParams: Map>) = apply {
+ this.queryParams.clear()
+ putAllQueryParams(queryParams)
+ }
+
+ fun putQueryParam(key: String, value: String) = apply { queryParams.put(key, value) }
+
+ fun putQueryParams(key: String, values: Iterable) = apply {
+ queryParams.put(key, values)
+ }
+
+ fun putAllQueryParams(queryParams: QueryParams) = apply {
+ this.queryParams.putAll(queryParams)
+ }
+
+ fun putAllQueryParams(queryParams: Map>) = apply {
+ this.queryParams.putAll(queryParams)
+ }
+
+ fun replaceQueryParams(key: String, value: String) = apply {
+ queryParams.replace(key, value)
+ }
+
+ fun replaceQueryParams(key: String, values: Iterable) = apply {
+ queryParams.replace(key, values)
+ }
+
+ fun replaceAllQueryParams(queryParams: QueryParams) = apply {
+ this.queryParams.replaceAll(queryParams)
+ }
+
+ fun replaceAllQueryParams(queryParams: Map>) = apply {
+ this.queryParams.replaceAll(queryParams)
+ }
+
+ fun removeQueryParams(key: String) = apply { queryParams.remove(key) }
+
+ fun removeAllQueryParams(keys: Set) = apply { queryParams.removeAll(keys) }
+
+ 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` |`langchain.langsmithApiKey` |`LANGSMITH_API_KEY` |false |- |
+ * |`tenantId` |`langchain.langsmithTenantId` |`LANGSMITH_TENANT_ID` |false |- |
+ * |`bearerToken` |`langchain.langsmithBearerToken` |`LANGSMITH_BEARER_TOKEN` |false |- |
+ * |`organizationId`|`langchain.langsmithOrganizationId`|`LANGSMITH_ORGANIZATION_ID`|false |- |
+ * |`baseUrl` |`langchain.baseUrl` |`LANGCHAIN_BASE_URL` |true |`"https://api.example.com"`|
+ *
+ * System properties take precedence over environment variables.
+ */
+ fun fromEnv() = apply {
+ (System.getProperty("langchain.baseUrl") ?: System.getenv("LANGCHAIN_BASE_URL"))?.let {
+ baseUrl(it)
+ }
+ (System.getProperty("langchain.langsmithApiKey") ?: System.getenv("LANGSMITH_API_KEY"))
+ ?.let { apiKey(it) }
+ (System.getProperty("langchain.langsmithTenantId")
+ ?: System.getenv("LANGSMITH_TENANT_ID"))
+ ?.let { tenantId(it) }
+ (System.getProperty("langchain.langsmithBearerToken")
+ ?: System.getenv("LANGSMITH_BEARER_TOKEN"))
+ ?.let { bearerToken(it) }
+ (System.getProperty("langchain.langsmithOrganizationId")
+ ?: System.getenv("LANGSMITH_ORGANIZATION_ID"))
+ ?.let { organizationId(it) }
+ }
+
+ /**
+ * Returns an immutable instance of [ClientOptions].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ *
+ * The following fields are required:
+ * ```java
+ * .httpClient()
+ * ```
+ *
+ * @throws IllegalStateException if any required field is unset.
+ */
+ fun build(): ClientOptions {
+ val httpClient = checkRequired("httpClient", httpClient)
+ val sleeper = sleeper ?: PhantomReachableSleeper(DefaultSleeper())
+
+ val headers = Headers.builder()
+ val queryParams = QueryParams.builder()
+ headers.put("X-Stainless-Lang", "java")
+ headers.put("X-Stainless-Arch", getOsArch())
+ headers.put("X-Stainless-OS", getOsName())
+ headers.put("X-Stainless-OS-Version", getOsVersion())
+ headers.put("X-Stainless-Package-Version", getPackageVersion())
+ headers.put("X-Stainless-Runtime", "JRE")
+ headers.put("X-Stainless-Runtime-Version", getJavaVersion())
+ apiKey?.let {
+ if (!it.isEmpty()) {
+ headers.put("X-API-Key", it)
+ }
+ }
+ tenantId?.let {
+ if (!it.isEmpty()) {
+ headers.put("X-Tenant-Id", it)
+ }
+ }
+ bearerToken?.let {
+ if (!it.isEmpty()) {
+ headers.put("Authorization", "Bearer $it")
+ }
+ }
+ organizationId?.let {
+ if (!it.isEmpty()) {
+ headers.put("X-Organization-Id", it)
+ }
+ }
+ headers.replaceAll(this.headers.build())
+ queryParams.replaceAll(this.queryParams.build())
+
+ return ClientOptions(
+ httpClient,
+ RetryingHttpClient.builder()
+ .httpClient(httpClient)
+ .sleeper(sleeper)
+ .clock(clock)
+ .maxRetries(maxRetries)
+ .build(),
+ checkJacksonVersionCompatibility,
+ jsonMapper,
+ sleeper,
+ clock,
+ baseUrl,
+ headers.build(),
+ queryParams.build(),
+ responseValidation,
+ timeout,
+ maxRetries,
+ apiKey,
+ tenantId,
+ bearerToken,
+ organizationId,
+ )
+ }
+ }
+
+ /**
+ * 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()
+ sleeper.close()
+ }
+}
diff --git a/langsmith-core/src/main/kotlin/com/langchain/smith/core/DefaultSleeper.kt b/langsmith-core/src/main/kotlin/com/langchain/smith/core/DefaultSleeper.kt
new file mode 100644
index 00000000..68333600
--- /dev/null
+++ b/langsmith-core/src/main/kotlin/com/langchain/smith/core/DefaultSleeper.kt
@@ -0,0 +1,28 @@
+package com.langchain.smith.core
+
+import java.time.Duration
+import java.util.Timer
+import java.util.TimerTask
+import java.util.concurrent.CompletableFuture
+
+class DefaultSleeper : Sleeper {
+
+ private val timer = Timer("DefaultSleeper", true)
+
+ override fun sleep(duration: Duration) = Thread.sleep(duration.toMillis())
+
+ override fun sleepAsync(duration: Duration): CompletableFuture {
+ val future = CompletableFuture()
+ timer.schedule(
+ object : TimerTask() {
+ override fun run() {
+ future.complete(null)
+ }
+ },
+ duration.toMillis(),
+ )
+ return future
+ }
+
+ override fun close() = timer.cancel()
+}
diff --git a/langsmith-core/src/main/kotlin/com/langchain/smith/core/ObjectMappers.kt b/langsmith-core/src/main/kotlin/com/langchain/smith/core/ObjectMappers.kt
new file mode 100644
index 00000000..2043c98e
--- /dev/null
+++ b/langsmith-core/src/main/kotlin/com/langchain/smith/core/ObjectMappers.kt
@@ -0,0 +1,167 @@
+@file:JvmName("ObjectMappers")
+
+package com.langchain.smith.core
+
+import com.fasterxml.jackson.annotation.JsonInclude
+import com.fasterxml.jackson.core.JsonGenerator
+import com.fasterxml.jackson.core.JsonParseException
+import com.fasterxml.jackson.core.JsonParser
+import com.fasterxml.jackson.databind.DeserializationContext
+import com.fasterxml.jackson.databind.DeserializationFeature
+import com.fasterxml.jackson.databind.MapperFeature
+import com.fasterxml.jackson.databind.SerializationFeature
+import com.fasterxml.jackson.databind.SerializerProvider
+import com.fasterxml.jackson.databind.cfg.CoercionAction
+import com.fasterxml.jackson.databind.cfg.CoercionInputShape
+import com.fasterxml.jackson.databind.deser.std.StdDeserializer
+import com.fasterxml.jackson.databind.json.JsonMapper
+import com.fasterxml.jackson.databind.module.SimpleModule
+import com.fasterxml.jackson.databind.type.LogicalType
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
+import com.fasterxml.jackson.module.kotlin.kotlinModule
+import java.io.InputStream
+import java.time.DateTimeException
+import java.time.LocalDate
+import java.time.LocalDateTime
+import java.time.ZonedDateTime
+import java.time.format.DateTimeFormatter
+import java.time.temporal.ChronoField
+
+fun jsonMapper(): JsonMapper =
+ JsonMapper.builder()
+ .addModule(kotlinModule())
+ .addModule(Jdk8Module())
+ .addModule(JavaTimeModule())
+ .addModule(
+ SimpleModule()
+ .addSerializer(InputStreamSerializer)
+ .addDeserializer(LocalDateTime::class.java, LenientLocalDateTimeDeserializer())
+ )
+ .withCoercionConfig(LogicalType.Boolean) {
+ it.setCoercion(CoercionInputShape.Integer, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.Float, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.String, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.Array, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.Object, CoercionAction.Fail)
+ }
+ .withCoercionConfig(LogicalType.Integer) {
+ it.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.String, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.Array, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.Object, CoercionAction.Fail)
+ }
+ .withCoercionConfig(LogicalType.Float) {
+ it.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.String, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.Array, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.Object, CoercionAction.Fail)
+ }
+ .withCoercionConfig(LogicalType.Textual) {
+ it.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.Integer, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.Float, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.Array, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.Object, CoercionAction.Fail)
+ }
+ .withCoercionConfig(LogicalType.Array) {
+ it.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.Integer, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.Float, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.String, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.Object, CoercionAction.Fail)
+ }
+ .withCoercionConfig(LogicalType.Collection) {
+ it.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.Integer, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.Float, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.String, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.Object, CoercionAction.Fail)
+ }
+ .withCoercionConfig(LogicalType.Map) {
+ it.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.Integer, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.Float, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.String, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.Object, CoercionAction.Fail)
+ }
+ .withCoercionConfig(LogicalType.POJO) {
+ it.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.Integer, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.Float, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.String, CoercionAction.Fail)
+ .setCoercion(CoercionInputShape.Array, CoercionAction.Fail)
+ }
+ .serializationInclusion(JsonInclude.Include.NON_ABSENT)
+ .disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
+ .disable(SerializationFeature.FLUSH_AFTER_WRITE_VALUE)
+ .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
+ .disable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)
+ .disable(MapperFeature.ALLOW_COERCION_OF_SCALARS)
+ .disable(MapperFeature.AUTO_DETECT_CREATORS)
+ .disable(MapperFeature.AUTO_DETECT_FIELDS)
+ .disable(MapperFeature.AUTO_DETECT_GETTERS)
+ .disable(MapperFeature.AUTO_DETECT_IS_GETTERS)
+ .disable(MapperFeature.AUTO_DETECT_SETTERS)
+ .build()
+
+/** A serializer that serializes [InputStream] to bytes. */
+private object InputStreamSerializer : BaseSerializer(InputStream::class) {
+
+ private fun readResolve(): Any = InputStreamSerializer
+
+ override fun serialize(
+ value: InputStream?,
+ gen: JsonGenerator?,
+ serializers: SerializerProvider?,
+ ) {
+ if (value == null) {
+ gen?.writeNull()
+ } else {
+ value.use { gen?.writeBinary(it.readBytes()) }
+ }
+ }
+}
+
+/**
+ * A deserializer that can deserialize [LocalDateTime] from datetimes, dates, and zoned datetimes.
+ */
+private class LenientLocalDateTimeDeserializer :
+ StdDeserializer(LocalDateTime::class.java) {
+
+ companion object {
+
+ private val DATE_TIME_FORMATTERS =
+ listOf(
+ DateTimeFormatter.ISO_LOCAL_DATE_TIME,
+ DateTimeFormatter.ISO_LOCAL_DATE,
+ DateTimeFormatter.ISO_ZONED_DATE_TIME,
+ )
+ }
+
+ override fun logicalType(): LogicalType = LogicalType.DateTime
+
+ override fun deserialize(p: JsonParser, context: DeserializationContext?): LocalDateTime {
+ val exceptions = mutableListOf()
+
+ for (formatter in DATE_TIME_FORMATTERS) {
+ try {
+ val temporal = formatter.parse(p.text)
+
+ return when {
+ !temporal.isSupported(ChronoField.HOUR_OF_DAY) ->
+ LocalDate.from(temporal).atStartOfDay()
+ !temporal.isSupported(ChronoField.OFFSET_SECONDS) ->
+ LocalDateTime.from(temporal)
+ else -> ZonedDateTime.from(temporal).toLocalDateTime()
+ }
+ } catch (e: DateTimeException) {
+ exceptions.add(e)
+ }
+ }
+
+ throw JsonParseException(p, "Cannot parse `LocalDateTime` from value: ${p.text}").apply {
+ exceptions.forEach { addSuppressed(it) }
+ }
+ }
+}
diff --git a/langsmith-core/src/main/kotlin/com/langchain/smith/core/Params.kt b/langsmith-core/src/main/kotlin/com/langchain/smith/core/Params.kt
new file mode 100644
index 00000000..4d5de87f
--- /dev/null
+++ b/langsmith-core/src/main/kotlin/com/langchain/smith/core/Params.kt
@@ -0,0 +1,16 @@
+package com.langchain.smith.core
+
+import com.langchain.smith.core.http.Headers
+import com.langchain.smith.core.http.QueryParams
+
+/** An interface representing parameters passed to a service method. */
+interface Params {
+ /** The full set of headers in the parameters, including both fixed and additional headers. */
+ fun _headers(): Headers
+
+ /**
+ * The full set of query params in the parameters, including both fixed and additional query
+ * params.
+ */
+ fun _queryParams(): QueryParams
+}
diff --git a/langsmith-core/src/main/kotlin/com/langchain/smith/core/PhantomReachable.kt b/langsmith-core/src/main/kotlin/com/langchain/smith/core/PhantomReachable.kt
new file mode 100644
index 00000000..997d88d6
--- /dev/null
+++ b/langsmith-core/src/main/kotlin/com/langchain/smith/core/PhantomReachable.kt
@@ -0,0 +1,56 @@
+@file:JvmName("PhantomReachable")
+
+package com.langchain.smith.core
+
+import com.langchain.smith.errors.LangChainException
+import java.lang.reflect.InvocationTargetException
+
+/**
+ * Closes [closeable] when [observed] becomes only phantom reachable.
+ *
+ * This is a wrapper around a Java 9+ [java.lang.ref.Cleaner], or a no-op in older Java versions.
+ */
+@JvmSynthetic
+internal fun closeWhenPhantomReachable(observed: Any, closeable: AutoCloseable) {
+ check(observed !== closeable) {
+ "`observed` cannot be the same object as `closeable` because it would never become phantom reachable"
+ }
+ closeWhenPhantomReachable(observed, closeable::close)
+}
+
+/**
+ * Calls [close] when [observed] becomes only phantom reachable.
+ *
+ * This is a wrapper around a Java 9+ [java.lang.ref.Cleaner], or a no-op in older Java versions.
+ */
+@JvmSynthetic
+internal fun closeWhenPhantomReachable(observed: Any, close: () -> Unit) {
+ closeWhenPhantomReachable?.let { it(observed, close) }
+}
+
+private val closeWhenPhantomReachable: ((Any, () -> Unit) -> Unit)? by lazy {
+ try {
+ val cleanerClass = Class.forName("java.lang.ref.Cleaner")
+ val cleanerCreate = cleanerClass.getMethod("create")
+ val cleanerRegister =
+ cleanerClass.getMethod("register", Any::class.java, Runnable::class.java)
+ val cleanerObject = cleanerCreate.invoke(null);
+
+ { observed, close ->
+ try {
+ cleanerRegister.invoke(cleanerObject, observed, Runnable { close() })
+ } catch (e: ReflectiveOperationException) {
+ if (e is InvocationTargetException) {
+ when (val cause = e.cause) {
+ is RuntimeException,
+ is Error -> throw cause
+ }
+ }
+ throw LangChainException("Unexpected reflective invocation failure", e)
+ }
+ }
+ } catch (e: ReflectiveOperationException) {
+ // We're running Java 8, which has no Cleaner.
+ null
+ }
+}
diff --git a/langsmith-core/src/main/kotlin/com/langchain/smith/core/PhantomReachableExecutorService.kt b/langsmith-core/src/main/kotlin/com/langchain/smith/core/PhantomReachableExecutorService.kt
new file mode 100644
index 00000000..8870ac1b
--- /dev/null
+++ b/langsmith-core/src/main/kotlin/com/langchain/smith/core/PhantomReachableExecutorService.kt
@@ -0,0 +1,58 @@
+package com.langchain.smith.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/langsmith-core/src/main/kotlin/com/langchain/smith/core/PhantomReachableSleeper.kt b/langsmith-core/src/main/kotlin/com/langchain/smith/core/PhantomReachableSleeper.kt
new file mode 100644
index 00000000..cb9c3ab3
--- /dev/null
+++ b/langsmith-core/src/main/kotlin/com/langchain/smith/core/PhantomReachableSleeper.kt
@@ -0,0 +1,23 @@
+package com.langchain.smith.core
+
+import java.time.Duration
+import java.util.concurrent.CompletableFuture
+
+/**
+ * A delegating wrapper around a [Sleeper] that closes it once it's only phantom reachable.
+ *
+ * This class ensures the [Sleeper] is closed even if the user forgets to do it.
+ */
+internal class PhantomReachableSleeper(private val sleeper: Sleeper) : Sleeper {
+
+ init {
+ closeWhenPhantomReachable(this, sleeper)
+ }
+
+ override fun sleep(duration: Duration) = sleeper.sleep(duration)
+
+ override fun sleepAsync(duration: Duration): CompletableFuture =
+ sleeper.sleepAsync(duration)
+
+ override fun close() = sleeper.close()
+}
diff --git a/langsmith-core/src/main/kotlin/com/langchain/smith/core/PrepareRequest.kt b/langsmith-core/src/main/kotlin/com/langchain/smith/core/PrepareRequest.kt
new file mode 100644
index 00000000..05f8c1eb
--- /dev/null
+++ b/langsmith-core/src/main/kotlin/com/langchain/smith/core/PrepareRequest.kt
@@ -0,0 +1,24 @@
+@file:JvmName("PrepareRequest")
+
+package com.langchain.smith.core
+
+import com.langchain.smith.core.http.HttpRequest
+import java.util.concurrent.CompletableFuture
+
+@JvmSynthetic
+internal fun HttpRequest.prepare(clientOptions: ClientOptions, params: Params): HttpRequest =
+ toBuilder()
+ .putAllQueryParams(clientOptions.queryParams)
+ .replaceAllQueryParams(params._queryParams())
+ .putAllHeaders(clientOptions.headers)
+ .replaceAllHeaders(params._headers())
+ .build()
+
+@JvmSynthetic
+internal fun HttpRequest.prepareAsync(
+ clientOptions: ClientOptions,
+ params: Params,
+): CompletableFuture =
+ // This async version exists to make it easier to add async specific preparation logic in the
+ // future.
+ CompletableFuture.completedFuture(prepare(clientOptions, params))
diff --git a/langsmith-core/src/main/kotlin/com/langchain/smith/core/Properties.kt b/langsmith-core/src/main/kotlin/com/langchain/smith/core/Properties.kt
new file mode 100644
index 00000000..490782e4
--- /dev/null
+++ b/langsmith-core/src/main/kotlin/com/langchain/smith/core/Properties.kt
@@ -0,0 +1,42 @@
+@file:JvmName("Properties")
+
+package com.langchain.smith.core
+
+import com.langchain.smith.client.LangsmithClient
+
+fun getOsArch(): String {
+ val osArch = System.getProperty("os.arch")
+
+ return when (osArch) {
+ null -> "unknown"
+ "i386",
+ "x32",
+ "x86" -> "x32"
+ "amd64",
+ "x86_64" -> "x64"
+ "arm" -> "arm"
+ "aarch64" -> "arm64"
+ else -> "other:$osArch"
+ }
+}
+
+fun getOsName(): String {
+ val osName = System.getProperty("os.name")
+ val vendorUrl = System.getProperty("java.vendor.url")
+
+ return when {
+ osName == null -> "Unknown"
+ osName.startsWith("Linux") && vendorUrl == "http://www.android.com/" -> "Android"
+ osName.startsWith("Linux") -> "Linux"
+ osName.startsWith("Mac OS") -> "MacOS"
+ osName.startsWith("Windows") -> "Windows"
+ else -> "Other:$osName"
+ }
+}
+
+fun getOsVersion(): String = System.getProperty("os.version", "unknown")
+
+fun getPackageVersion(): String =
+ LangsmithClient::class.java.`package`.implementationVersion ?: "unknown"
+
+fun getJavaVersion(): String = System.getProperty("java.version", "unknown")
diff --git a/langsmith-core/src/main/kotlin/com/langchain/smith/core/RequestOptions.kt b/langsmith-core/src/main/kotlin/com/langchain/smith/core/RequestOptions.kt
new file mode 100644
index 00000000..a0f5875d
--- /dev/null
+++ b/langsmith-core/src/main/kotlin/com/langchain/smith/core/RequestOptions.kt
@@ -0,0 +1,46 @@
+package com.langchain.smith.core
+
+import java.time.Duration
+
+class RequestOptions private constructor(val responseValidation: Boolean?, val timeout: Timeout?) {
+
+ companion object {
+
+ private val NONE = builder().build()
+
+ @JvmStatic fun none() = NONE
+
+ @JvmSynthetic
+ internal fun from(clientOptions: ClientOptions): RequestOptions =
+ builder()
+ .responseValidation(clientOptions.responseValidation)
+ .timeout(clientOptions.timeout)
+ .build()
+
+ @JvmStatic fun builder() = Builder()
+ }
+
+ fun applyDefaults(options: RequestOptions): RequestOptions =
+ RequestOptions(
+ responseValidation = responseValidation ?: options.responseValidation,
+ timeout =
+ if (options.timeout != null && timeout != null) timeout.assign(options.timeout)
+ else timeout ?: options.timeout,
+ )
+
+ class Builder internal constructor() {
+
+ private var responseValidation: Boolean? = null
+ private var timeout: Timeout? = null
+
+ fun responseValidation(responseValidation: Boolean) = apply {
+ this.responseValidation = responseValidation
+ }
+
+ fun timeout(timeout: Timeout) = apply { this.timeout = timeout }
+
+ fun timeout(timeout: Duration) = timeout(Timeout.builder().request(timeout).build())
+
+ fun build(): RequestOptions = RequestOptions(responseValidation, timeout)
+ }
+}
diff --git a/langsmith-core/src/main/kotlin/com/langchain/smith/core/Sleeper.kt b/langsmith-core/src/main/kotlin/com/langchain/smith/core/Sleeper.kt
new file mode 100644
index 00000000..9a300811
--- /dev/null
+++ b/langsmith-core/src/main/kotlin/com/langchain/smith/core/Sleeper.kt
@@ -0,0 +1,21 @@
+package com.langchain.smith.core
+
+import java.time.Duration
+import java.util.concurrent.CompletableFuture
+
+/**
+ * An interface for delaying execution for a specified amount of time.
+ *
+ * Useful for testing and cleaning up resources.
+ */
+interface Sleeper : AutoCloseable {
+
+ /** Synchronously pauses execution for the given [duration]. */
+ fun sleep(duration: Duration)
+
+ /** Asynchronously pauses execution for the given [duration]. */
+ fun sleepAsync(duration: Duration): CompletableFuture
+
+ /** Overridden from [AutoCloseable] to not have a checked exception in its signature. */
+ override fun close()
+}
diff --git a/langsmith-core/src/main/kotlin/com/langchain/smith/core/Timeout.kt b/langsmith-core/src/main/kotlin/com/langchain/smith/core/Timeout.kt
new file mode 100644
index 00000000..44458612
--- /dev/null
+++ b/langsmith-core/src/main/kotlin/com/langchain/smith/core/Timeout.kt
@@ -0,0 +1,171 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.langchain.smith.core
+
+import java.time.Duration
+import java.util.Objects
+import java.util.Optional
+import kotlin.jvm.optionals.getOrNull
+
+/** A class containing timeouts for various processing phases of a request. */
+class Timeout
+private constructor(
+ private val connect: Duration?,
+ private val read: Duration?,
+ private val write: Duration?,
+ private val request: Duration?,
+) {
+
+ /**
+ * The maximum time allowed to establish a connection with a host.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `Duration.ofMinutes(1)`.
+ */
+ fun connect(): Duration = connect ?: Duration.ofMinutes(1)
+
+ /**
+ * The maximum time allowed between two data packets when waiting for the server’s response.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `request()`.
+ */
+ fun read(): Duration = read ?: request()
+
+ /**
+ * The maximum time allowed between two data packets when sending the request to the server.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `request()`.
+ */
+ fun write(): Duration = write ?: request()
+
+ /**
+ * The maximum time allowed for a complete HTTP call, not including retries.
+ *
+ * This includes resolving DNS, connecting, writing the request body, server processing, as well
+ * as reading the response body.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `Duration.ofMinutes(1)`.
+ */
+ fun request(): Duration = request ?: Duration.ofMinutes(1)
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ @JvmStatic fun default() = builder().build()
+
+ /** Returns a mutable builder for constructing an instance of [Timeout]. */
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [Timeout]. */
+ class Builder internal constructor() {
+
+ private var connect: Duration? = null
+ private var read: Duration? = null
+ private var write: Duration? = null
+ private var request: Duration? = null
+
+ @JvmSynthetic
+ internal fun from(timeout: Timeout) = apply {
+ connect = timeout.connect
+ read = timeout.read
+ write = timeout.write
+ request = timeout.request
+ }
+
+ /**
+ * The maximum time allowed to establish a connection with a host.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `Duration.ofMinutes(1)`.
+ */
+ fun connect(connect: Duration?) = apply { this.connect = connect }
+
+ /** Alias for calling [Builder.connect] with `connect.orElse(null)`. */
+ fun connect(connect: Optional) = connect(connect.getOrNull())
+
+ /**
+ * The maximum time allowed between two data packets when waiting for the server’s response.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `request()`.
+ */
+ fun read(read: Duration?) = apply { this.read = read }
+
+ /** Alias for calling [Builder.read] with `read.orElse(null)`. */
+ fun read(read: Optional) = read(read.getOrNull())
+
+ /**
+ * The maximum time allowed between two data packets when sending the request to the server.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `request()`.
+ */
+ fun write(write: Duration?) = apply { this.write = write }
+
+ /** Alias for calling [Builder.write] with `write.orElse(null)`. */
+ fun write(write: Optional) = write(write.getOrNull())
+
+ /**
+ * The maximum time allowed for a complete HTTP call, not including retries.
+ *
+ * This includes resolving DNS, connecting, writing the request body, server processing, as
+ * well as reading the response body.
+ *
+ * A value of [Duration.ZERO] means there's no timeout.
+ *
+ * Defaults to `Duration.ofMinutes(1)`.
+ */
+ fun request(request: Duration?) = apply { this.request = request }
+
+ /** Alias for calling [Builder.request] with `request.orElse(null)`. */
+ fun request(request: Optional) = request(request.getOrNull())
+
+ /**
+ * Returns an immutable instance of [Timeout].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ */
+ fun build(): Timeout = Timeout(connect, read, write, request)
+ }
+
+ @JvmSynthetic
+ internal fun assign(target: Timeout): Timeout =
+ target
+ .toBuilder()
+ .apply {
+ connect?.let(this::connect)
+ read?.let(this::read)
+ write?.let(this::write)
+ request?.let(this::request)
+ }
+ .build()
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return other is Timeout &&
+ connect == other.connect &&
+ read == other.read &&
+ write == other.write &&
+ request == other.request
+ }
+
+ 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/langsmith-core/src/main/kotlin/com/langchain/smith/core/Utils.kt b/langsmith-core/src/main/kotlin/com/langchain/smith/core/Utils.kt
new file mode 100644
index 00000000..188bbceb
--- /dev/null
+++ b/langsmith-core/src/main/kotlin/com/langchain/smith/core/Utils.kt
@@ -0,0 +1,115 @@
+@file:JvmName("Utils")
+
+package com.langchain.smith.core
+
+import com.langchain.smith.errors.LangChainInvalidDataException
+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 =
+ this ?: throw LangChainInvalidDataException("`${name}` is not present")
+
+@JvmSynthetic
+internal fun List.toImmutable(): List =
+ if (isEmpty()) Collections.emptyList() else Collections.unmodifiableList(toList())
+
+@JvmSynthetic
+internal fun Map.toImmutable(): Map =
+ if (isEmpty()) immutableEmptyMap() else Collections.unmodifiableMap(toMap())
+
+@JvmSynthetic internal fun immutableEmptyMap(): Map = Collections.emptyMap()
+
+@JvmSynthetic
+internal fun , V> SortedMap.toImmutable(): SortedMap =
+ if (isEmpty()) Collections.emptySortedMap()
+ else Collections.unmodifiableSortedMap(toSortedMap(comparator()))
+
+/**
+ * Returns all elements that yield the largest value for the given function, or an empty list if
+ * there are zero elements.
+ *
+ * This is similar to [Sequence.maxByOrNull] except it returns _all_ elements that yield the largest
+ * value; not just the first one.
+ */
+@JvmSynthetic
+internal fun > Sequence.allMaxBy(selector: (T) -> R): List {
+ var maxValue: R? = null
+ val maxElements = mutableListOf()
+
+ val iterator = iterator()
+ while (iterator.hasNext()) {
+ val element = iterator.next()
+ val value = selector(element)
+ if (maxValue == null || value > maxValue) {
+ maxValue = value
+ maxElements.clear()
+ maxElements.add(element)
+ } else if (value == maxValue) {
+ maxElements.add(element)
+ }
+ }
+
+ return maxElements
+}
+
+/**
+ * Returns whether [this] is equal to [other].
+ *
+ * This differs from [Object.equals] because it also deeply equates arrays based on their contents,
+ * even when there are arrays directly nested within other arrays.
+ */
+@JvmSynthetic
+internal infix fun Any?.contentEquals(other: Any?): Boolean =
+ arrayOf(this).contentDeepEquals(arrayOf(other))
+
+/**
+ * Returns a hash of the given sequence of [values].
+ *
+ * This differs from [java.util.Objects.hash] because it also deeply hashes arrays based on their
+ * contents, even when there are arrays directly nested within other arrays.
+ */
+@JvmSynthetic internal fun contentHash(vararg values: Any?): Int = values.contentDeepHashCode()
+
+/**
+ * Returns a [String] representation of [this].
+ *
+ * This differs from [Object.toString] because it also deeply stringifies arrays based on their
+ * contents, even when there are arrays directly nested within other arrays.
+ */
+@JvmSynthetic
+internal fun Any?.contentToString(): String {
+ var string = arrayOf(this).contentDeepToString()
+ if (string.startsWith('[')) {
+ string = string.substring(1)
+ }
+ if (string.endsWith(']')) {
+ string = string.substring(0, string.length - 1)
+ }
+ return 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/langsmith-core/src/main/kotlin/com/langchain/smith/core/Values.kt b/langsmith-core/src/main/kotlin/com/langchain/smith/core/Values.kt
new file mode 100644
index 00000000..0d2b1eba
--- /dev/null
+++ b/langsmith-core/src/main/kotlin/com/langchain/smith/core/Values.kt
@@ -0,0 +1,723 @@
+package com.langchain.smith.core
+
+import com.fasterxml.jackson.annotation.JacksonAnnotationsInside
+import com.fasterxml.jackson.annotation.JsonCreator
+import com.fasterxml.jackson.annotation.JsonInclude
+import com.fasterxml.jackson.core.JsonGenerator
+import com.fasterxml.jackson.core.ObjectCodec
+import com.fasterxml.jackson.core.type.TypeReference
+import com.fasterxml.jackson.databind.BeanProperty
+import com.fasterxml.jackson.databind.DeserializationContext
+import com.fasterxml.jackson.databind.JavaType
+import com.fasterxml.jackson.databind.JsonDeserializer
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.SerializerProvider
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize
+import com.fasterxml.jackson.databind.annotation.JsonSerialize
+import com.fasterxml.jackson.databind.node.JsonNodeType.ARRAY
+import com.fasterxml.jackson.databind.node.JsonNodeType.BINARY
+import com.fasterxml.jackson.databind.node.JsonNodeType.BOOLEAN
+import com.fasterxml.jackson.databind.node.JsonNodeType.MISSING
+import com.fasterxml.jackson.databind.node.JsonNodeType.NULL
+import com.fasterxml.jackson.databind.node.JsonNodeType.NUMBER
+import com.fasterxml.jackson.databind.node.JsonNodeType.OBJECT
+import com.fasterxml.jackson.databind.node.JsonNodeType.POJO
+import com.fasterxml.jackson.databind.node.JsonNodeType.STRING
+import com.fasterxml.jackson.databind.ser.std.NullSerializer
+import com.langchain.smith.errors.LangChainInvalidDataException
+import java.io.InputStream
+import java.util.Objects
+import java.util.Optional
+
+/**
+ * A class representing a serializable JSON field.
+ *
+ * It can either be a [KnownValue] value of type [T], matching the type the SDK expects, or an
+ * arbitrary JSON value that bypasses the type system (via [JsonValue]).
+ */
+@JsonDeserialize(using = JsonField.Deserializer::class)
+sealed class JsonField {
+
+ /**
+ * Returns whether this field is missing, which means it will be omitted from the serialized
+ * JSON entirely.
+ */
+ fun isMissing(): Boolean = this is JsonMissing
+
+ /** Whether this field is explicitly set to `null`. */
+ fun isNull(): Boolean = this is JsonNull
+
+ /**
+ * Returns an [Optional] containing this field's "known" value, meaning it matches the type the
+ * SDK expects, or an empty [Optional] if this field contains an arbitrary [JsonValue].
+ *
+ * This is the opposite of [asUnknown].
+ */
+ fun asKnown():
+ Optional<
+ // Safe because `Optional` is effectively covariant, but Kotlin doesn't know that.
+ @UnsafeVariance
+ T
+ > = Optional.ofNullable((this as? KnownValue)?.value)
+
+ /**
+ * Returns an [Optional] containing this field's arbitrary [JsonValue], meaning it mismatches
+ * the type the SDK expects, or an empty [Optional] if this field contains a "known" value.
+ *
+ * This is the opposite of [asKnown].
+ */
+ fun asUnknown(): Optional = Optional.ofNullable(this as? JsonValue)
+
+ /**
+ * Returns an [Optional] containing this field's boolean value, or an empty [Optional] if it
+ * doesn't contain a boolean.
+ *
+ * This method checks for both a [KnownValue] containing a boolean and for [JsonBoolean].
+ */
+ fun asBoolean(): Optional =
+ when (this) {
+ is JsonBoolean -> Optional.of(value)
+ is KnownValue -> Optional.ofNullable(value as? Boolean)
+ else -> Optional.empty()
+ }
+
+ /**
+ * Returns an [Optional] containing this field's numerical value, or an empty [Optional] if it
+ * doesn't contain a number.
+ *
+ * This method checks for both a [KnownValue] containing a number and for [JsonNumber].
+ */
+ fun asNumber(): Optional =
+ when (this) {
+ is JsonNumber -> Optional.of(value)
+ is KnownValue -> Optional.ofNullable(value as? Number)
+ else -> Optional.empty()
+ }
+
+ /**
+ * Returns an [Optional] containing this field's string value, or an empty [Optional] if it
+ * doesn't contain a string.
+ *
+ * This method checks for both a [KnownValue] containing a string and for [JsonString].
+ */
+ fun asString(): Optional =
+ when (this) {
+ is JsonString -> Optional.of(value)
+ is KnownValue -> Optional.ofNullable(value as? String)
+ else -> Optional.empty()
+ }
+
+ fun asStringOrThrow(): String =
+ asString().orElseThrow { LangChainInvalidDataException("Value is not a string") }
+
+ /**
+ * Returns an [Optional] containing this field's list value, or an empty [Optional] if it
+ * doesn't contain a list.
+ *
+ * This method checks for both a [KnownValue] containing a list and for [JsonArray].
+ */
+ fun asArray(): Optional> =
+ when (this) {
+ is JsonArray -> Optional.of(values)
+ is KnownValue ->
+ Optional.ofNullable(
+ (value as? List<*>)?.map {
+ try {
+ JsonValue.from(it)
+ } catch (e: IllegalArgumentException) {
+ // The known value is a list, but not all values are convertible to
+ // `JsonValue`.
+ return Optional.empty()
+ }
+ }
+ )
+ else -> Optional.empty()
+ }
+
+ /**
+ * Returns an [Optional] containing this field's map value, or an empty [Optional] if it doesn't
+ * contain a map.
+ *
+ * This method checks for both a [KnownValue] containing a map and for [JsonObject].
+ */
+ fun asObject(): Optional> =
+ when (this) {
+ is JsonObject -> Optional.of(values)
+ is KnownValue ->
+ Optional.ofNullable(
+ (value as? Map<*, *>)
+ ?.map { (key, value) ->
+ if (key !is String) {
+ return Optional.empty()
+ }
+
+ val jsonValue =
+ try {
+ JsonValue.from(value)
+ } catch (e: IllegalArgumentException) {
+ // The known value is a map, but not all items are convertible
+ // to `JsonValue`.
+ return Optional.empty()
+ }
+
+ key to jsonValue
+ }
+ ?.toMap()
+ )
+ else -> Optional.empty()
+ }
+
+ @JvmSynthetic
+ internal fun getRequired(name: String): T =
+ when (this) {
+ is KnownValue -> value
+ is JsonMissing -> throw LangChainInvalidDataException("`$name` is not set")
+ is JsonNull -> throw LangChainInvalidDataException("`$name` is null")
+ else -> throw LangChainInvalidDataException("`$name` is invalid, received $this")
+ }
+
+ @JvmSynthetic
+ internal fun getOptional(
+ name: String
+ ): Optional<
+ // Safe because `Optional` is effectively covariant, but Kotlin doesn't know that.
+ @UnsafeVariance
+ T
+ > =
+ when (this) {
+ is KnownValue -> Optional.of(value)
+ is JsonMissing,
+ is JsonNull -> Optional.empty()
+ else -> throw LangChainInvalidDataException("`$name` is invalid, received $this")
+ }
+
+ @JvmSynthetic
+ internal fun map(transform: (T) -> R): JsonField =
+ when (this) {
+ is KnownValue -> KnownValue.of(transform(value))
+ is JsonValue -> this
+ }
+
+ @JvmSynthetic internal fun accept(consume: (T) -> Unit) = asKnown().ifPresent(consume)
+
+ /** Returns the result of calling the [visitor] method corresponding to this field's state. */
+ fun accept(visitor: Visitor): R =
+ when (this) {
+ is KnownValue -> visitor.visitKnown(value)
+ is JsonValue -> accept(visitor as JsonValue.Visitor)
+ }
+
+ /**
+ * An interface that defines how to map each possible state of a `JsonField` to a value of
+ * type [R].
+ */
+ interface Visitor : JsonValue.Visitor {
+
+ fun visitKnown(value: T): R = visitDefault()
+ }
+
+ companion object {
+
+ /** Returns a [JsonField] containing the given "known" [value]. */
+ @JvmStatic fun of(value: T): JsonField = KnownValue.of(value)
+
+ /**
+ * Returns a [JsonField] containing the given "known" [value], or [JsonNull] if [value] is
+ * null.
+ */
+ @JvmStatic
+ fun ofNullable(value: T?): JsonField =
+ when (value) {
+ null -> JsonNull.of()
+ else -> KnownValue.of(value)
+ }
+ }
+
+ /**
+ * This class is a Jackson filter that can be used to exclude missing properties from objects.
+ * This filter should not be used directly and should instead use the @ExcludeMissing
+ * annotation.
+ */
+ class IsMissing {
+
+ override fun equals(other: Any?): Boolean = other is JsonMissing
+
+ override fun hashCode(): Int = Objects.hash()
+ }
+
+ class Deserializer(private val type: JavaType? = null) :
+ BaseDeserializer>(JsonField::class) {
+
+ override fun createContextual(
+ context: DeserializationContext,
+ property: BeanProperty?,
+ ): JsonDeserializer> = Deserializer(context.contextualType?.containedType(0))
+
+ override fun ObjectCodec.deserialize(node: JsonNode): JsonField<*> =
+ type?.let { tryDeserialize