Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions .fernignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ src/main/java/com/deepgram/AsyncDeepgramClientBuilder.java
# Contains User-Agent, X-Fern-SDK-Name, and X-Fern-SDK-Version headers
# with // x-release-please-version comments for automated version bumps.
# Fern regen overwrites these with incorrect SDK names and strips the markers.
src/main/java/com/deepgram/core/ClientOptions.java
src/main/java/com/deepgram/core/ClientOptions.java.bak

# Transport abstraction (pluggable transport for SageMaker, etc.)
src/main/java/com/deepgram/core/transport/

# Bug fixes for maxRetries(0) semantics ("connect once, don't retry") and a
# configurable connectionTimeoutMs on ReconnectOptions (was hardcoded 4000ms).
# Pull this back out once the fixes are upstreamed into the Fern generator.
src/main/java/com/deepgram/core/ReconnectingWebSocketListener.java
src/main/java/com/deepgram/core/ReconnectingWebSocketListener.java.bak

# Forward-compat patch: Fern's generated dispatcher routes any unrecognized message
# type to the error handler ("Update your SDK version..."), which makes benign new
Expand All @@ -32,8 +32,8 @@ src/main/java/com/deepgram/core/ReconnectingWebSocketListener.java
# NOTE: the listen v2 and speak v2 clients below also carry the streaming query-param patches
# (multi-value serialization + the additionalProperties escape hatch) documented lower down —
# keep them frozen until those fixes are upstreamed too.
src/main/java/com/deepgram/resources/speak/v2/websocket/V2WebSocketClient.java
src/main/java/com/deepgram/resources/listen/v2/websocket/V2WebSocketClient.java
src/main/java/com/deepgram/resources/speak/v2/websocket/V2WebSocketClient.java.bak
src/main/java/com/deepgram/resources/listen/v2/websocket/V2WebSocketClient.java.bak

# Streaming query-param patches on the generated WS connect() builders. Two fixes:
# (1) Multi-value serialization: array-valued params (listen: keyterm, keywords, replace, search,
Expand All @@ -47,24 +47,24 @@ src/main/java/com/deepgram/resources/listen/v2/websocket/V2WebSocketClient.java
# listen v2 and speak v2 clients are frozen above; freeze the listen v1 and speak v1 clients here too
# so the fixes survive regen. Re-apply after regen; unfreeze once the generator emits array params as
# repeats and serializes additionalProperties on the WS connect path (tracked as an upstream Fern request).
src/main/java/com/deepgram/resources/listen/v1/websocket/V1WebSocketClient.java
src/main/java/com/deepgram/resources/speak/v1/websocket/V1WebSocketClient.java
src/main/java/com/deepgram/resources/listen/v1/websocket/V1WebSocketClient.java.bak
src/main/java/com/deepgram/resources/speak/v1/websocket/V1WebSocketClient.java.bak

# Manual equals/hashCode contract fix: Fern generates equals() (all instances equal) but no
# hashCode() for fields-less message types, violating the Object contract. We add a consistent
# hashCode() to each. Unfreeze and drop these patches once the generator emits a matching
# equals/hashCode pair for fields-less types (tracked as an upstream Fern request).
src/main/java/com/deepgram/resources/listen/v2/types/ListenV2CloseStream.java
src/main/java/com/deepgram/resources/speak/v2/types/SpeakV2Close.java
src/main/java/com/deepgram/resources/speak/v2/types/SpeakV2Flush.java
src/main/java/com/deepgram/resources/agent/v1/types/AgentV1ListenUpdated.java
src/main/java/com/deepgram/resources/agent/v1/types/AgentV1SpeakUpdated.java
src/main/java/com/deepgram/resources/agent/v1/types/AgentV1AgentAudioDone.java
src/main/java/com/deepgram/resources/agent/v1/types/AgentV1SettingsApplied.java
src/main/java/com/deepgram/resources/agent/v1/types/AgentV1UserStartedSpeaking.java
src/main/java/com/deepgram/resources/agent/v1/types/AgentV1KeepAlive.java
src/main/java/com/deepgram/resources/agent/v1/types/AgentV1ThinkUpdated.java
src/main/java/com/deepgram/resources/agent/v1/types/AgentV1PromptUpdated.java
src/main/java/com/deepgram/resources/listen/v2/types/ListenV2CloseStream.java.bak
src/main/java/com/deepgram/resources/speak/v2/types/SpeakV2Close.java.bak
src/main/java/com/deepgram/resources/speak/v2/types/SpeakV2Flush.java.bak
src/main/java/com/deepgram/resources/agent/v1/types/AgentV1ListenUpdated.java.bak
src/main/java/com/deepgram/resources/agent/v1/types/AgentV1SpeakUpdated.java.bak
src/main/java/com/deepgram/resources/agent/v1/types/AgentV1AgentAudioDone.java.bak
src/main/java/com/deepgram/resources/agent/v1/types/AgentV1SettingsApplied.java.bak
src/main/java/com/deepgram/resources/agent/v1/types/AgentV1UserStartedSpeaking.java.bak
src/main/java/com/deepgram/resources/agent/v1/types/AgentV1KeepAlive.java.bak
src/main/java/com/deepgram/resources/agent/v1/types/AgentV1ThinkUpdated.java.bak
src/main/java/com/deepgram/resources/agent/v1/types/AgentV1PromptUpdated.java.bak

# Build and project configuration
build.gradle
Expand Down
241 changes: 241 additions & 0 deletions src/main/java/com/deepgram/core/ClientOptions.java.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/
package com.deepgram.core;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import okhttp3.OkHttpClient;

public final class ClientOptions {
private final Environment environment;

private final Map<String, String> headers;

private final Map<String, Supplier<String>> headerSuppliers;

private final OkHttpClient httpClient;

private final int timeout;

private final int maxRetries;

private final Optional<WebSocketFactory> webSocketFactory;

private final Optional<LogConfig> logging;

private ClientOptions(
Environment environment,
Map<String, String> headers,
Map<String, Supplier<String>> headerSuppliers,
OkHttpClient httpClient,
int timeout,
int maxRetries,
Optional<WebSocketFactory> webSocketFactory,
Optional<LogConfig> logging) {
this.environment = environment;
this.headers = new HashMap<>();
this.headers.putAll(headers);
this.headers.putAll(new HashMap<String, String>() {
{
put("User-Agent", "com.deepgram:deepgram-java-sdk/0.7.1"); // x-release-please-version
put("X-Fern-Language", "JAVA");
put("X-Fern-SDK-Name", "com.deepgram:deepgram-java-sdk");
put("X-Fern-SDK-Version", "0.7.1"); // x-release-please-version
}
});
this.headerSuppliers = headerSuppliers;
this.httpClient = httpClient;
this.timeout = timeout;
this.maxRetries = maxRetries;
this.webSocketFactory = webSocketFactory;
this.logging = logging;
}

public Environment environment() {
return this.environment;
}

public Map<String, String> headers(RequestOptions requestOptions) {
Map<String, String> values = new HashMap<>(this.headers);
headerSuppliers.forEach((key, supplier) -> {
values.put(key, supplier.get());
});
if (requestOptions != null) {
values.putAll(requestOptions.getHeaders());
}
return values;
}

public int timeout(RequestOptions requestOptions) {
if (requestOptions == null) {
return this.timeout;
}
return requestOptions.getTimeout().orElse(this.timeout);
}

public OkHttpClient httpClient() {
return this.httpClient;
}

public OkHttpClient httpClientWithTimeout(RequestOptions requestOptions) {
if (requestOptions == null) {
return this.httpClient;
}
return this.httpClient
.newBuilder()
.callTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit())
.connectTimeout(0, TimeUnit.SECONDS)
.writeTimeout(0, TimeUnit.SECONDS)
.readTimeout(0, TimeUnit.SECONDS)
.build();
}

public int maxRetries() {
return this.maxRetries;
}

public Optional<WebSocketFactory> webSocketFactory() {
return this.webSocketFactory;
}

public Optional<LogConfig> logging() {
return this.logging;
}

public static Builder builder() {
return new Builder();
}

public static class Builder {
private Environment environment;

private final Map<String, String> headers = new HashMap<>();

private final Map<String, Supplier<String>> headerSuppliers = new HashMap<>();

private int maxRetries = 2;

private Optional<Integer> timeout = Optional.empty();

private OkHttpClient httpClient = null;

private Optional<LogConfig> logging = Optional.empty();

private Optional<WebSocketFactory> webSocketFactory = Optional.empty();

public Builder environment(Environment environment) {
this.environment = environment;
return this;
}

public Builder addHeader(String key, String value) {
this.headers.put(key, value);
return this;
}

public Builder addHeader(String key, Supplier<String> value) {
this.headerSuppliers.put(key, value);
return this;
}

/**
* Override the timeout in seconds. Defaults to 60 seconds.
*/
public Builder timeout(int timeout) {
this.timeout = Optional.of(timeout);
return this;
}

/**
* Override the timeout in seconds. Defaults to 60 seconds.
*/
public Builder timeout(Optional<Integer> timeout) {
this.timeout = timeout;
return this;
}

/**
* Override the maximum number of retries. Defaults to 2 retries.
*/
public Builder maxRetries(int maxRetries) {
this.maxRetries = maxRetries;
return this;
}

public Builder httpClient(OkHttpClient httpClient) {
this.httpClient = httpClient;
return this;
}

/**
* Set a custom WebSocketFactory for creating WebSocket connections.
*/
public Builder webSocketFactory(WebSocketFactory webSocketFactory) {
this.webSocketFactory = Optional.of(webSocketFactory);
return this;
}

/**
* Configure logging for the SDK. Silent by default — no log output unless explicitly configured.
*/
public Builder logging(LogConfig logging) {
this.logging = Optional.of(logging);
return this;
}

public ClientOptions build() {
OkHttpClient.Builder httpClientBuilder =
this.httpClient != null ? this.httpClient.newBuilder() : new OkHttpClient.Builder();

if (this.httpClient != null) {
timeout.ifPresent(timeout -> httpClientBuilder
.callTimeout(timeout, TimeUnit.SECONDS)
.connectTimeout(0, TimeUnit.SECONDS)
.writeTimeout(0, TimeUnit.SECONDS)
.readTimeout(0, TimeUnit.SECONDS));
} else {
httpClientBuilder
.callTimeout(this.timeout.orElse(60), TimeUnit.SECONDS)
.connectTimeout(0, TimeUnit.SECONDS)
.writeTimeout(0, TimeUnit.SECONDS)
.readTimeout(0, TimeUnit.SECONDS)
.addInterceptor(new RetryInterceptor(this.maxRetries));
}

Logger logger = Logger.from(this.logging);
httpClientBuilder.addInterceptor(new LoggingInterceptor(logger));

this.httpClient = httpClientBuilder.build();
this.timeout = Optional.of(httpClient.callTimeoutMillis() / 1000);

return new ClientOptions(
environment,
headers,
headerSuppliers,
httpClient,
this.timeout.get(),
this.maxRetries,
this.webSocketFactory,
this.logging);
}

/**
* Create a new Builder initialized with values from an existing ClientOptions
*/
public static Builder from(ClientOptions clientOptions) {
Builder builder = new Builder();
builder.environment = clientOptions.environment();
builder.timeout = Optional.of(clientOptions.timeout(null));
builder.httpClient = clientOptions.httpClient();
builder.headers.putAll(clientOptions.headers);
builder.headerSuppliers.putAll(clientOptions.headerSuppliers);
builder.maxRetries = clientOptions.maxRetries();
builder.logging = clientOptions.logging();
return builder;
}
}
}
Loading
Loading