diff --git a/.fern/metadata.json b/.fern/metadata.json index b0471248..fca7c97e 100644 --- a/.fern/metadata.json +++ b/.fern/metadata.json @@ -1,7 +1,7 @@ { "cliVersion": "5.95.1", "generatorName": "fernapi/fern-java-sdk", - "generatorVersion": "4.21.0", + "generatorVersion": "4.23.1", "generatorConfig": { "package-prefix": "com.deepgram", "base-api-exception-class-name": "DeepgramHttpException", @@ -12,8 +12,8 @@ "enable-wire-tests": true, "runtime-version": true }, - "originGitCommit": "f6f5d3876c8996e2a6b6e59136bb222183a8e317", + "originGitCommit": "6c10a16dcc3b061e3030440e339f405af1ad29a9", "originGitCommitIsDirty": true, "invokedBy": "manual", - "sdkVersion": "0.10.2" -} + "sdkVersion": "0.10.3" +} \ No newline at end of file diff --git a/.fernignore b/.fernignore index ee108186..918d8714 100644 --- a/.fernignore +++ b/.fernignore @@ -51,11 +51,6 @@ src/main/java/com/deepgram/resources/listen/v2/websocket/V2WebSocketClient.java src/main/java/com/deepgram/resources/listen/v1/websocket/V1WebSocketClient.java src/main/java/com/deepgram/resources/speak/v1/websocket/V1WebSocketClient.java -# Close is safe before connect in every generated WebSocket client. The listener is created only -# during connect(), so disconnect() must tolerate a null listener for try-with-resources clients. -# Remove these patches once Fern emits the null guard. -src/main/java/com/deepgram/resources/agent/v1/websocket/V1WebSocketClient.java - # Restores the FLUX_RENEE_EN constant that generator 4.18.0 dropped. The voice is live: # POST /v2/speak?model=flux-renee-en returns 200 with valid audio, and the name resolves in the # server's model registry (an invented flux-* name is rejected with INVALID_QUERY_PARAMETER), so the diff --git a/src/main/java/com/deepgram/AsyncDeepgramApiClient.java b/src/main/java/com/deepgram/AsyncDeepgramApiClient.java index c2aa87ee..0ae6c114 100644 --- a/src/main/java/com/deepgram/AsyncDeepgramApiClient.java +++ b/src/main/java/com/deepgram/AsyncDeepgramApiClient.java @@ -79,8 +79,9 @@ public AsyncVoiceAgentClient voiceAgent() { } /** - * Releases resources owned by this client. See {@code ClientOptions.close()} for what is - * and is not released. + * Releases resources owned by this client: any WebSocket clients still connected through + * it are disconnected first, then the SDK-owned HTTP client is shut down. See + * {@code ClientOptions.close()} for what is and is not released. */ @Override public void close() { diff --git a/src/main/java/com/deepgram/DeepgramApiClient.java b/src/main/java/com/deepgram/DeepgramApiClient.java index ccb0d4a7..a67528ff 100644 --- a/src/main/java/com/deepgram/DeepgramApiClient.java +++ b/src/main/java/com/deepgram/DeepgramApiClient.java @@ -79,8 +79,9 @@ public VoiceAgentClient voiceAgent() { } /** - * Releases resources owned by this client. See {@code ClientOptions.close()} for what is - * and is not released. + * Releases resources owned by this client: any WebSocket clients still connected through + * it are disconnected first, then the SDK-owned HTTP client is shut down. See + * {@code ClientOptions.close()} for what is and is not released. */ @Override public void close() { diff --git a/src/main/java/com/deepgram/core/ClientOptions.java b/src/main/java/com/deepgram/core/ClientOptions.java index 5329810c..bfb382fa 100644 --- a/src/main/java/com/deepgram/core/ClientOptions.java +++ b/src/main/java/com/deepgram/core/ClientOptions.java @@ -3,10 +3,14 @@ */ package com.deepgram.core; +import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.Optional; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Supplier; import okhttp3.OkHttpClient; @@ -21,6 +25,10 @@ public final class ClientOptions { private final boolean ownsHttpClient; + private final AtomicBoolean closed; + + private final Set openWebSockets; + private final int timeout; private final int maxRetries; @@ -41,6 +49,8 @@ private ClientOptions( Map> headerSuppliers, OkHttpClient httpClient, boolean ownsHttpClient, + AtomicBoolean closed, + Set openWebSockets, int timeout, int maxRetries, Optional initialRetryDelayMillis, @@ -62,6 +72,8 @@ private ClientOptions( this.headerSuppliers = headerSuppliers; this.httpClient = httpClient; this.ownsHttpClient = ownsHttpClient; + this.closed = closed; + this.openWebSockets = openWebSockets; this.timeout = timeout; this.maxRetries = maxRetries; this.initialRetryDelayMillis = initialRetryDelayMillis; @@ -132,12 +144,28 @@ public Optional retryJitterFactor() { * OkHttpClient itself; an OkHttpClient supplied via httpClient is left running, since the * caller owns its lifecycle. *

- * In-flight calls are not cancelled or awaited. Later asynchronous requests fail when the - * dispatcher rejects work, while synchronous requests may still run. Options derived from this - * one via {@code Builder.from(...)} share the same dispatcher and connection pool, so closing - * either releases them for both. Calling this method more than once has no further effect. + * In-flight calls are not cancelled or awaited, and any request issued after this method + * returns fails with a {@code RejectedExecutionException}. Options derived from this one via + * {@code Builder.from(...)} share the same dispatcher and connection pool, so closing either + * releases them for both. Calling this method more than once has no further effect. + *

+ * WebSocket clients created from this client that are still connected are disconnected + * first (whether or not the OkHttpClient is owned), so they stop reconnecting before the + * dispatcher goes away. Any WebSocket connect or reconnect attempted afterwards fails with + * an {@code IllegalStateException} explaining that the client has been closed. */ public void close() { + if (!this.closed.compareAndSet(false, true)) { + return; + } + for (AutoCloseable webSocket : new ArrayList<>(this.openWebSockets)) { + try { + webSocket.close(); + } catch (Exception e) { + // best effort; keep closing the remaining sockets and the HTTP client + } + } + this.openWebSockets.clear(); if (!this.ownsHttpClient) { return; } @@ -145,6 +173,33 @@ public void close() { this.httpClient.connectionPool().evictAll(); } + /** + * Returns whether {@link #close()} has been called on this client. + */ + public boolean isClosed() { + return this.closed.get(); + } + + /** + * Tracks a connected WebSocket client so that {@link #close()} disconnects it. + * + * @throws IllegalStateException if this client has already been closed + */ + public void registerWebSocket(AutoCloseable webSocket) { + this.openWebSockets.add(webSocket); + if (this.closed.get()) { + this.openWebSockets.remove(webSocket); + throw new IllegalStateException("root client has been closed"); + } + } + + /** + * Stops tracking a WebSocket client that has been disconnected. + */ + public void unregisterWebSocket(AutoCloseable webSocket) { + this.openWebSockets.remove(webSocket); + } + public Optional webSocketFactory() { return this.webSocketFactory; } @@ -178,6 +233,10 @@ public static class Builder { private boolean ownsHttpClient = true; + private AtomicBoolean closed; + + private Set openWebSockets; + private Optional logging = Optional.empty(); private Optional webSocketFactory = Optional.empty(); @@ -303,12 +362,18 @@ public ClientOptions build() { this.httpClient = httpClientBuilder.build(); this.timeout = Optional.of(httpClient.callTimeoutMillis() / 1000); + AtomicBoolean closedToUse = this.closed != null ? this.closed : new AtomicBoolean(false); + Set openWebSocketsToUse = + this.openWebSockets != null ? this.openWebSockets : ConcurrentHashMap.newKeySet(); + return new ClientOptions( environment, headers, headerSuppliers, httpClient, this.ownsHttpClient, + closedToUse, + openWebSocketsToUse, this.timeout.get(), this.maxRetries, this.initialRetryDelayMillis, @@ -327,6 +392,8 @@ public static Builder from(ClientOptions clientOptions) { builder.timeout = Optional.of(clientOptions.timeout(null)); builder.httpClient = clientOptions.httpClient(); builder.ownsHttpClient = clientOptions.ownsHttpClient; + builder.closed = clientOptions.closed; + builder.openWebSockets = clientOptions.openWebSockets; builder.headers.putAll(clientOptions.headers); builder.headerSuppliers.putAll(clientOptions.headerSuppliers); builder.maxRetries = clientOptions.maxRetries(); diff --git a/src/main/java/com/deepgram/core/OkHttpWebSocketFactory.java b/src/main/java/com/deepgram/core/OkHttpWebSocketFactory.java index 70e6c868..30653bcf 100644 --- a/src/main/java/com/deepgram/core/OkHttpWebSocketFactory.java +++ b/src/main/java/com/deepgram/core/OkHttpWebSocketFactory.java @@ -3,6 +3,7 @@ */ package com.deepgram.core; +import java.util.function.BooleanSupplier; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.WebSocket; @@ -15,17 +16,38 @@ public final class OkHttpWebSocketFactory implements WebSocketFactory { private final OkHttpClient okHttpClient; + private final BooleanSupplier closedCheck; + /** * Creates a new OkHttpWebSocketFactory with the specified OkHttpClient. * * @param okHttpClient The OkHttpClient instance to use for creating WebSockets */ public OkHttpWebSocketFactory(OkHttpClient okHttpClient) { + this(okHttpClient, () -> false); + } + + /** + * Creates a new OkHttpWebSocketFactory that refuses to open WebSockets once the owning + * client has been closed. + * + * @param okHttpClient The OkHttpClient instance to use for creating WebSockets + * @param closedCheck Returns true once the owning client has been closed (e.g. + * {@code clientOptions::isClosed}) + */ + public OkHttpWebSocketFactory(OkHttpClient okHttpClient, BooleanSupplier closedCheck) { this.okHttpClient = okHttpClient; + this.closedCheck = closedCheck; } + /** + * @throws IllegalStateException if the owning client has been closed + */ @Override public WebSocket create(Request request, WebSocketListener listener) { + if (closedCheck.getAsBoolean()) { + throw new IllegalStateException("root client has been closed"); + } return okHttpClient.newWebSocket(request, listener); } } diff --git a/src/main/java/com/deepgram/core/ReconnectingWebSocketListener.java b/src/main/java/com/deepgram/core/ReconnectingWebSocketListener.java index 7f6d9df6..d3aabeed 100644 --- a/src/main/java/com/deepgram/core/ReconnectingWebSocketListener.java +++ b/src/main/java/com/deepgram/core/ReconnectingWebSocketListener.java @@ -14,6 +14,7 @@ import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.BooleanSupplier; import java.util.function.Consumer; import java.util.function.Supplier; import okhttp3.Response; @@ -49,6 +50,8 @@ public abstract class ReconnectingWebSocketListener extends WebSocketListener { private final Supplier connectionSupplier; + private final BooleanSupplier closedCheck; + /** * Creates a new reconnecting WebSocket listener. * @@ -57,9 +60,26 @@ public abstract class ReconnectingWebSocketListener extends WebSocketListener { */ public ReconnectingWebSocketListener( ReconnectingWebSocketListener.ReconnectOptions options, Supplier connectionSupplier) { + this(options, connectionSupplier, () -> false); + } + + /** + * Creates a new reconnecting WebSocket listener. + * + * @param options Reconnection configuration options + * @param connectionSupplier Supplier that creates new WebSocket connections + * @param closedCheck Returns true once the owning client has been closed; connect and + * reconnect attempts made after that point fail with an {@link IllegalStateException} + * instead of being retried + */ + public ReconnectingWebSocketListener( + ReconnectingWebSocketListener.ReconnectOptions options, + Supplier connectionSupplier, + BooleanSupplier closedCheck) { this.activeOptions = options; this.maxEnqueuedMessages = options.maxEnqueuedMessages; this.connectionSupplier = connectionSupplier; + this.closedCheck = closedCheck; } /** @@ -85,11 +105,18 @@ public void applyOptionsOverride(ReconnectOptions options) { * - TimeoutException: Includes retry attempt context * - InterruptedException: Preserves thread interruption status * - ExecutionException: Extracts actual cause and adds context + * - Owning client closed: reports an IllegalStateException once and stops reconnecting */ public void connect() { if (!connectLock.compareAndSet(false, true)) { return; } + if (closedCheck.getAsBoolean()) { + shouldReconnect.set(false); + connectLock.set(false); + onWebSocketFailure(null, new IllegalStateException("root client has been closed"), null); + return; + } ReconnectOptions options = this.activeOptions; if (retryCount.get() > options.maxRetries) { connectLock.set(false); @@ -403,8 +430,13 @@ private long getNextDelay() { /** * Schedules a reconnection attempt with appropriate delay. * Increments retry count and uses exponential backoff. + * Does nothing once the owning client has been closed. */ private void scheduleReconnect() { + if (closedCheck.getAsBoolean()) { + shouldReconnect.set(false); + return; + } retryCount.incrementAndGet(); long delay = getNextDelay(); reconnectExecutor.schedule(this::connect, delay, MILLISECONDS); diff --git a/src/main/java/com/deepgram/core/RetryInterceptor.java b/src/main/java/com/deepgram/core/RetryInterceptor.java index a0959bbc..aad032cd 100644 --- a/src/main/java/com/deepgram/core/RetryInterceptor.java +++ b/src/main/java/com/deepgram/core/RetryInterceptor.java @@ -10,9 +10,13 @@ import java.time.format.DateTimeParseException; import java.util.Optional; import java.util.Random; +import okhttp3.Call; import okhttp3.Interceptor; import okhttp3.Request; import okhttp3.Response; +import okhttp3.ResponseBody; +import okio.AsyncTimeout; +import okio.Timeout; public class RetryInterceptor implements Interceptor { @@ -78,13 +82,28 @@ private Response retryChain(Response response, Chain chain, int maxRetries) thro ExponentialBackoff backoff = new ExponentialBackoff(maxRetries); Optional nextBackoff = backoff.nextBackoff(response); while (nextBackoff.isPresent()) { + response = bufferResponse(response); + Optional callTimeout = suspendCallTimeout(chain); try { Thread.sleep(nextBackoff.get().toMillis()); } catch (InterruptedException e) { + response.close(); throw new IOException("Interrupted while trying request", e); + } finally { + callTimeout.ifPresent(AsyncTimeout::enter); + } + Response nextResponse; + try { + nextResponse = chain.proceed(chain.request()); + } catch (IOException e) { + // A retry attempt failed with a transport error (connection reset, unreachable host, ...). The + // error is intentionally dropped: the response already received from the API is more actionable. + // Note that a call-timeout expiry or an explicit cancel() also ends up here, but OkHttp then + // discards whatever the interceptor chain returns and reports the cancellation itself. + return response; } response.close(); - response = chain.proceed(chain.request()); + response = nextResponse; if (shouldRetry(response.code())) { nextBackoff = backoff.nextBackoff(response); } else { @@ -95,6 +114,51 @@ private Response retryChain(Response response, Chain chain, int maxRetries) thro return response; } + /** + * Pauses the OkHttp call timeout so that it applies to each attempt individually rather than to the whole + * retry loop: the backoff wait (e.g. a {@code Retry-After} the size of the call timeout) does not consume the + * budget of the next attempt, and each attempt starts with a fresh budget once {@link AsyncTimeout#enter()} + * is called again. + * + *

{@link AsyncTimeout#exit()} and {@link AsyncTimeout#enter()} must stay strictly paired: {@code exit()} on + * a timeout that is not armed is a no-op, but {@code enter()} on one that is already armed throws + * {@code IllegalStateException}. Every caller must re-enter the returned timeout exactly once, on all paths. + */ + private static Optional suspendCallTimeout(Chain chain) { + Call call = chain.call(); + if (call == null) { + return Optional.empty(); + } + Timeout timeout = call.timeout(); + if (!(timeout instanceof AsyncTimeout)) { + return Optional.empty(); + } + AsyncTimeout callTimeout = (AsyncTimeout) timeout; + callTimeout.exit(); + return Optional.of(callTimeout); + } + + /** + * Reads the body into memory so the response stays usable after the underlying connection + * is released or cancelled by a later attempt. + */ + private static Response bufferResponse(Response response) { + ResponseBody body = response.body(); + if (body == null) { + return response; + } + try { + byte[] bytes = body.bytes(); + Response buffered = response.newBuilder() + .body(ResponseBody.create(bytes, body.contentType())) + .build(); + response.close(); + return buffered; + } catch (IOException e) { + return response; + } + } + /** * Calculates the retry delay from response headers, with fallback to exponential backoff. * Priority: Retry-After > X-RateLimit-Reset > Exponential Backoff diff --git a/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1AgentAudioDone.java b/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1AgentAudioDone.java index b6ee9000..5962f4bf 100644 --- a/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1AgentAudioDone.java +++ b/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1AgentAudioDone.java @@ -3,8 +3,6 @@ */ package com.deepgram.resources.agent.v1.types; -// Manual patch - see .fernignore. - import com.deepgram.core.ObjectMappers; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; diff --git a/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1ForceEndTurn.java b/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1ForceEndTurn.java index 11d0d8d0..9bd5f769 100644 --- a/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1ForceEndTurn.java +++ b/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1ForceEndTurn.java @@ -3,8 +3,6 @@ */ package com.deepgram.resources.agent.v1.types; -// Manual patch - see .fernignore. - import com.deepgram.core.ObjectMappers; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; diff --git a/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1KeepAlive.java b/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1KeepAlive.java index 588aad18..f82f59ee 100644 --- a/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1KeepAlive.java +++ b/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1KeepAlive.java @@ -3,8 +3,6 @@ */ package com.deepgram.resources.agent.v1.types; -// Manual patch - see .fernignore. - import com.deepgram.core.ObjectMappers; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; diff --git a/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1ListenUpdated.java b/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1ListenUpdated.java index 3de75ec5..43b8628b 100644 --- a/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1ListenUpdated.java +++ b/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1ListenUpdated.java @@ -3,8 +3,6 @@ */ package com.deepgram.resources.agent.v1.types; -// Manual patch - see .fernignore. - import com.deepgram.core.ObjectMappers; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; diff --git a/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1PromptUpdated.java b/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1PromptUpdated.java index 2b2f7946..e6efced0 100644 --- a/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1PromptUpdated.java +++ b/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1PromptUpdated.java @@ -3,8 +3,6 @@ */ package com.deepgram.resources.agent.v1.types; -// Manual patch - see .fernignore. - import com.deepgram.core.ObjectMappers; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; diff --git a/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1SettingsAgentContextListenProvider.java b/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1SettingsAgentContextListenProvider.java index 1c21ce70..393f1f91 100644 --- a/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1SettingsAgentContextListenProvider.java +++ b/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1SettingsAgentContextListenProvider.java @@ -3,8 +3,6 @@ */ package com.deepgram.resources.agent.v1.types; -// Manual patch - see .fernignore. - import com.deepgram.types.DeepgramListenProviderV1; import com.deepgram.types.DeepgramListenProviderV2; import com.fasterxml.jackson.annotation.JsonCreator; diff --git a/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1SettingsAgentListenProvider.java b/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1SettingsAgentListenProvider.java index 06e47e60..345ba2f3 100644 --- a/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1SettingsAgentListenProvider.java +++ b/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1SettingsAgentListenProvider.java @@ -3,8 +3,6 @@ */ package com.deepgram.resources.agent.v1.types; -// Manual patch - see .fernignore. - import com.deepgram.types.DeepgramListenProviderV1; import com.deepgram.types.DeepgramListenProviderV2; import com.fasterxml.jackson.annotation.JsonCreator; diff --git a/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1SettingsApplied.java b/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1SettingsApplied.java index 443c2148..ad1fdb2f 100644 --- a/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1SettingsApplied.java +++ b/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1SettingsApplied.java @@ -3,8 +3,6 @@ */ package com.deepgram.resources.agent.v1.types; -// Manual patch - see .fernignore. - import com.deepgram.core.ObjectMappers; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; diff --git a/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1SpeakUpdated.java b/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1SpeakUpdated.java index 87c8d7d1..8b134b54 100644 --- a/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1SpeakUpdated.java +++ b/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1SpeakUpdated.java @@ -3,8 +3,6 @@ */ package com.deepgram.resources.agent.v1.types; -// Manual patch - see .fernignore. - import com.deepgram.core.ObjectMappers; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; diff --git a/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1ThinkUpdated.java b/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1ThinkUpdated.java index 4b6f6230..2d67cad1 100644 --- a/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1ThinkUpdated.java +++ b/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1ThinkUpdated.java @@ -3,8 +3,6 @@ */ package com.deepgram.resources.agent.v1.types; -// Manual patch - see .fernignore. - import com.deepgram.core.ObjectMappers; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; diff --git a/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1UpdateListenListenProvider.java b/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1UpdateListenListenProvider.java index d0390e2d..e739aec6 100644 --- a/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1UpdateListenListenProvider.java +++ b/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1UpdateListenListenProvider.java @@ -3,8 +3,6 @@ */ package com.deepgram.resources.agent.v1.types; -// Manual patch - see .fernignore. - import com.deepgram.types.DeepgramListenProviderV1; import com.deepgram.types.DeepgramListenProviderV2; import com.fasterxml.jackson.annotation.JsonCreator; diff --git a/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1UserStartedSpeaking.java b/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1UserStartedSpeaking.java index 36e8a9d7..3556d319 100644 --- a/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1UserStartedSpeaking.java +++ b/src/main/java/com/deepgram/resources/agent/v1/types/AgentV1UserStartedSpeaking.java @@ -3,8 +3,6 @@ */ package com.deepgram.resources.agent.v1.types; -// Manual patch - see .fernignore. - import com.deepgram.core.ObjectMappers; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; diff --git a/src/main/java/com/deepgram/resources/agent/v1/websocket/V1WebSocketClient.java b/src/main/java/com/deepgram/resources/agent/v1/websocket/V1WebSocketClient.java index d8305b17..5bf4d734 100644 --- a/src/main/java/com/deepgram/resources/agent/v1/websocket/V1WebSocketClient.java +++ b/src/main/java/com/deepgram/resources/agent/v1/websocket/V1WebSocketClient.java @@ -3,8 +3,6 @@ */ package com.deepgram.resources.agent.v1.websocket; -// Manual patch - see .fernignore. - import com.deepgram.core.ClientOptions; import com.deepgram.core.DisconnectReason; import com.deepgram.core.ObjectMappers; @@ -162,13 +160,22 @@ public CompletableFuture connect() { ? this.reconnectOptions : ReconnectingWebSocketListener.ReconnectOptions.builder().build(); this.reconnectingListener = - new ReconnectingWebSocketListener(reconnectOpts, () -> { - if (clientOptions.webSocketFactory().isPresent()) { - return clientOptions.webSocketFactory().get().create(request, this.reconnectingListener); - } else { - return okHttpClient.newWebSocket(request, this.reconnectingListener); - } - }) { + new ReconnectingWebSocketListener( + reconnectOpts, + () -> { + if (clientOptions.isClosed()) { + throw new IllegalStateException("root client has been closed"); + } + if (clientOptions.webSocketFactory().isPresent()) { + return clientOptions + .webSocketFactory() + .get() + .create(request, this.reconnectingListener); + } else { + return okHttpClient.newWebSocket(request, this.reconnectingListener); + } + }, + clientOptions::isClosed) { @Override protected void onWebSocketOpen(WebSocket webSocket, Response response) { readyState = WebSocketReadyState.OPEN; @@ -207,6 +214,7 @@ protected void onWebSocketClosed(WebSocket webSocket, int code, String reason) { } } }; + clientOptions.registerWebSocket(this); reconnectingListener.connect(); return connectionFuture; } @@ -215,6 +223,7 @@ protected void onWebSocketClosed(WebSocket webSocket, int code, String reason) { * Disconnects the WebSocket connection and releases resources. */ public void disconnect() { + clientOptions.unregisterWebSocket(this); if (reconnectingListener != null) { reconnectingListener.disconnect(); } diff --git a/src/main/java/com/deepgram/resources/listen/v1/websocket/V1WebSocketClient.java b/src/main/java/com/deepgram/resources/listen/v1/websocket/V1WebSocketClient.java index ffaa903e..278a2c9b 100644 --- a/src/main/java/com/deepgram/resources/listen/v1/websocket/V1WebSocketClient.java +++ b/src/main/java/com/deepgram/resources/listen/v1/websocket/V1WebSocketClient.java @@ -3,8 +3,6 @@ */ package com.deepgram.resources.listen.v1.websocket; -// Manual patch - see .fernignore. - import com.deepgram.core.ClientOptions; import com.deepgram.core.DisconnectReason; import com.deepgram.core.ObjectMappers; @@ -229,13 +227,22 @@ public CompletableFuture connect(V1ConnectOptions options) { ? this.reconnectOptions : ReconnectingWebSocketListener.ReconnectOptions.builder().build(); this.reconnectingListener = - new ReconnectingWebSocketListener(reconnectOpts, () -> { - if (clientOptions.webSocketFactory().isPresent()) { - return clientOptions.webSocketFactory().get().create(request, this.reconnectingListener); - } else { - return okHttpClient.newWebSocket(request, this.reconnectingListener); - } - }) { + new ReconnectingWebSocketListener( + reconnectOpts, + () -> { + if (clientOptions.isClosed()) { + throw new IllegalStateException("root client has been closed"); + } + if (clientOptions.webSocketFactory().isPresent()) { + return clientOptions + .webSocketFactory() + .get() + .create(request, this.reconnectingListener); + } else { + return okHttpClient.newWebSocket(request, this.reconnectingListener); + } + }, + clientOptions::isClosed) { @Override protected void onWebSocketOpen(WebSocket webSocket, Response response) { readyState = WebSocketReadyState.OPEN; @@ -270,6 +277,7 @@ protected void onWebSocketClosed(WebSocket webSocket, int code, String reason) { } } }; + clientOptions.registerWebSocket(this); reconnectingListener.connect(); return connectionFuture; } @@ -278,6 +286,7 @@ protected void onWebSocketClosed(WebSocket webSocket, int code, String reason) { * Disconnects the WebSocket connection and releases resources. */ public void disconnect() { + clientOptions.unregisterWebSocket(this); if (reconnectingListener != null) { reconnectingListener.disconnect(); } diff --git a/src/main/java/com/deepgram/resources/listen/v2/types/ListenV2CloseStream.java b/src/main/java/com/deepgram/resources/listen/v2/types/ListenV2CloseStream.java index 8f7496d5..c9f2f357 100644 --- a/src/main/java/com/deepgram/resources/listen/v2/types/ListenV2CloseStream.java +++ b/src/main/java/com/deepgram/resources/listen/v2/types/ListenV2CloseStream.java @@ -3,8 +3,6 @@ */ package com.deepgram.resources.listen.v2.types; -// Manual patch - see .fernignore. - import com.deepgram.core.ObjectMappers; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; diff --git a/src/main/java/com/deepgram/resources/listen/v2/types/ListenV2ConfigureFailure.java b/src/main/java/com/deepgram/resources/listen/v2/types/ListenV2ConfigureFailure.java index 478307b8..a48faaca 100644 --- a/src/main/java/com/deepgram/resources/listen/v2/types/ListenV2ConfigureFailure.java +++ b/src/main/java/com/deepgram/resources/listen/v2/types/ListenV2ConfigureFailure.java @@ -10,10 +10,12 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.Nulls; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import java.util.HashMap; import java.util.Map; import java.util.Objects; +import java.util.Optional; import org.jetbrains.annotations.NotNull; @JsonInclude(JsonInclude.Include.NON_ABSENT) @@ -23,11 +25,22 @@ public final class ListenV2ConfigureFailure { private final int sequenceId; + private final Optional code; + + private final Optional description; + private final Map additionalProperties; - private ListenV2ConfigureFailure(String requestId, int sequenceId, Map additionalProperties) { + private ListenV2ConfigureFailure( + String requestId, + int sequenceId, + Optional code, + Optional description, + Map additionalProperties) { this.requestId = requestId; this.sequenceId = sequenceId; + this.code = code; + this.description = description; this.additionalProperties = additionalProperties; } @@ -57,6 +70,22 @@ public int getSequenceId() { return sequenceId; } + /** + * @return Failure code identifying the rejected configuration + */ + @JsonProperty("code") + public Optional getCode() { + return code; + } + + /** + * @return A human-readable description of the configuration failure + */ + @JsonProperty("description") + public Optional getDescription() { + return description; + } + @java.lang.Override public boolean equals(Object other) { if (this == other) return true; @@ -69,12 +98,15 @@ public Map getAdditionalProperties() { } private boolean equalTo(ListenV2ConfigureFailure other) { - return requestId.equals(other.requestId) && sequenceId == other.sequenceId; + return requestId.equals(other.requestId) + && sequenceId == other.sequenceId + && code.equals(other.code) + && description.equals(other.description); } @java.lang.Override public int hashCode() { - return Objects.hash(this.requestId, this.sequenceId); + return Objects.hash(this.requestId, this.sequenceId, this.code, this.description); } @java.lang.Override @@ -110,6 +142,20 @@ public interface _FinalStage { _FinalStage additionalProperty(String key, Object value); _FinalStage additionalProperties(Map additionalProperties); + + /** + *

Failure code identifying the rejected configuration

+ */ + _FinalStage code(Optional code); + + _FinalStage code(String code); + + /** + *

A human-readable description of the configuration failure

+ */ + _FinalStage description(Optional description); + + _FinalStage description(String description); } @JsonIgnoreProperties(ignoreUnknown = true) @@ -118,6 +164,10 @@ public static final class Builder implements RequestIdStage, SequenceIdStage, _F private int sequenceId; + private Optional description = Optional.empty(); + + private Optional code = Optional.empty(); + @JsonAnySetter private Map additionalProperties = new HashMap<>(); @@ -127,6 +177,8 @@ private Builder() {} public Builder from(ListenV2ConfigureFailure other) { requestId(other.getRequestId()); sequenceId(other.getSequenceId()); + code(other.getCode()); + description(other.getDescription()); return this; } @@ -154,9 +206,49 @@ public _FinalStage sequenceId(int sequenceId) { return this; } + /** + *

A human-readable description of the configuration failure

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage description(String description) { + this.description = Optional.ofNullable(description); + return this; + } + + /** + *

A human-readable description of the configuration failure

+ */ + @java.lang.Override + @JsonSetter(value = "description", nulls = Nulls.SKIP) + public _FinalStage description(Optional description) { + this.description = description; + return this; + } + + /** + *

Failure code identifying the rejected configuration

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage code(String code) { + this.code = Optional.ofNullable(code); + return this; + } + + /** + *

Failure code identifying the rejected configuration

+ */ + @java.lang.Override + @JsonSetter(value = "code", nulls = Nulls.SKIP) + public _FinalStage code(Optional code) { + this.code = code; + return this; + } + @java.lang.Override public ListenV2ConfigureFailure build() { - return new ListenV2ConfigureFailure(requestId, sequenceId, additionalProperties); + return new ListenV2ConfigureFailure(requestId, sequenceId, code, description, additionalProperties); } @java.lang.Override diff --git a/src/main/java/com/deepgram/resources/listen/v2/types/ListenV2ConfigureSuccess.java b/src/main/java/com/deepgram/resources/listen/v2/types/ListenV2ConfigureSuccess.java index ca93f2b2..a714b954 100644 --- a/src/main/java/com/deepgram/resources/listen/v2/types/ListenV2ConfigureSuccess.java +++ b/src/main/java/com/deepgram/resources/listen/v2/types/ListenV2ConfigureSuccess.java @@ -31,6 +31,8 @@ public final class ListenV2ConfigureSuccess { private final Optional> languageHints; + private final Optional numerals; + private final int sequenceId; private final Map additionalProperties; @@ -40,12 +42,14 @@ private ListenV2ConfigureSuccess( ListenV2ConfigureSuccessThresholds thresholds, ListenV2Keyterm keyterms, Optional> languageHints, + Optional numerals, int sequenceId, Map additionalProperties) { this.requestId = requestId; this.thresholds = thresholds; this.keyterms = keyterms; this.languageHints = languageHints; + this.numerals = numerals; this.sequenceId = sequenceId; this.additionalProperties = additionalProperties; } @@ -88,6 +92,14 @@ public Optional> getLanguageHints() { return languageHints; } + /** + * @return Whether numeral formatting is enabled for transcripts Flux STT sends after it processes the update. + */ + @JsonProperty("numerals") + public Optional getNumerals() { + return numerals; + } + /** * @return Starts at 0 and increments for each message the server sends * to the client. This includes messages of other types, like @@ -114,12 +126,14 @@ private boolean equalTo(ListenV2ConfigureSuccess other) { && thresholds.equals(other.thresholds) && keyterms.equals(other.keyterms) && languageHints.equals(other.languageHints) + && numerals.equals(other.numerals) && sequenceId == other.sequenceId; } @java.lang.Override public int hashCode() { - return Objects.hash(this.requestId, this.thresholds, this.keyterms, this.languageHints, this.sequenceId); + return Objects.hash( + this.requestId, this.thresholds, this.keyterms, this.languageHints, this.numerals, this.sequenceId); } @java.lang.Override @@ -174,6 +188,13 @@ public interface _FinalStage { _FinalStage languageHints(Optional> languageHints); _FinalStage languageHints(List languageHints); + + /** + *

Whether numeral formatting is enabled for transcripts Flux STT sends after it processes the update.

+ */ + _FinalStage numerals(Optional numerals); + + _FinalStage numerals(Boolean numerals); } @JsonIgnoreProperties(ignoreUnknown = true) @@ -187,6 +208,8 @@ public static final class Builder private int sequenceId; + private Optional numerals = Optional.empty(); + private Optional> languageHints = Optional.empty(); @JsonAnySetter @@ -200,6 +223,7 @@ public Builder from(ListenV2ConfigureSuccess other) { thresholds(other.getThresholds()); keyterms(other.getKeyterms()); languageHints(other.getLanguageHints()); + numerals(other.getNumerals()); sequenceId(other.getSequenceId()); return this; } @@ -247,6 +271,26 @@ public _FinalStage sequenceId(int sequenceId) { return this; } + /** + *

Whether numeral formatting is enabled for transcripts Flux STT sends after it processes the update.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage numerals(Boolean numerals) { + this.numerals = Optional.ofNullable(numerals); + return this; + } + + /** + *

Whether numeral formatting is enabled for transcripts Flux STT sends after it processes the update.

+ */ + @java.lang.Override + @JsonSetter(value = "numerals", nulls = Nulls.SKIP) + public _FinalStage numerals(Optional numerals) { + this.numerals = numerals; + return this; + } + /** *

The currently active language hints. Only applicable to the flux-general-multi model.

* @return Reference to {@code this} so that method calls can be chained together. @@ -270,7 +314,7 @@ public _FinalStage languageHints(Optional> languageHints) { @java.lang.Override public ListenV2ConfigureSuccess build() { return new ListenV2ConfigureSuccess( - requestId, thresholds, keyterms, languageHints, sequenceId, additionalProperties); + requestId, thresholds, keyterms, languageHints, numerals, sequenceId, additionalProperties); } @java.lang.Override diff --git a/src/main/java/com/deepgram/resources/listen/v2/types/ListenV2ForceEndTurn.java b/src/main/java/com/deepgram/resources/listen/v2/types/ListenV2ForceEndTurn.java index 99471a55..894bd3c8 100644 --- a/src/main/java/com/deepgram/resources/listen/v2/types/ListenV2ForceEndTurn.java +++ b/src/main/java/com/deepgram/resources/listen/v2/types/ListenV2ForceEndTurn.java @@ -3,8 +3,6 @@ */ package com.deepgram.resources.listen.v2.types; -// Manual patch - see .fernignore. - import com.deepgram.core.ObjectMappers; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; diff --git a/src/main/java/com/deepgram/resources/listen/v2/types/ListenV2Warning.java b/src/main/java/com/deepgram/resources/listen/v2/types/ListenV2Warning.java new file mode 100644 index 00000000..4eed2fb7 --- /dev/null +++ b/src/main/java/com/deepgram/resources/listen/v2/types/ListenV2Warning.java @@ -0,0 +1,247 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.deepgram.resources.listen.v2.types; + +import com.deepgram.core.ObjectMappers; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import org.jetbrains.annotations.NotNull; + +@JsonInclude(JsonInclude.Include.NON_ABSENT) +@JsonDeserialize(builder = ListenV2Warning.Builder.class) +public final class ListenV2Warning { + private final String requestId; + + private final int sequenceId; + + private final String code; + + private final String description; + + private final Map additionalProperties; + + private ListenV2Warning( + String requestId, + int sequenceId, + String code, + String description, + Map additionalProperties) { + this.requestId = requestId; + this.sequenceId = sequenceId; + this.code = code; + this.description = description; + this.additionalProperties = additionalProperties; + } + + /** + * @return Message type identifier + */ + @JsonProperty("type") + public String getType() { + return "Warning"; + } + + /** + * @return The unique identifier of the request + */ + @JsonProperty("request_id") + public String getRequestId() { + return requestId; + } + + /** + * @return Starts at 0 and increments for each message the server sends + * to the client. This includes messages of other types, like + * TurnInfo messages. + */ + @JsonProperty("sequence_id") + public int getSequenceId() { + return sequenceId; + } + + /** + * @return Warning code identifying the condition, in SCREAMING_SNAKE_CASE + */ + @JsonProperty("code") + public String getCode() { + return code; + } + + /** + * @return A human-readable description of the warning + */ + @JsonProperty("description") + public String getDescription() { + return description; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ListenV2Warning && equalTo((ListenV2Warning) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ListenV2Warning other) { + return requestId.equals(other.requestId) + && sequenceId == other.sequenceId + && code.equals(other.code) + && description.equals(other.description); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.requestId, this.sequenceId, this.code, this.description); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static RequestIdStage builder() { + return new Builder(); + } + + public interface RequestIdStage { + /** + *

The unique identifier of the request

+ */ + SequenceIdStage requestId(@NotNull String requestId); + + Builder from(ListenV2Warning other); + } + + public interface SequenceIdStage { + /** + *

Starts at 0 and increments for each message the server sends + * to the client. This includes messages of other types, like + * TurnInfo messages.

+ */ + CodeStage sequenceId(int sequenceId); + } + + public interface CodeStage { + /** + *

Warning code identifying the condition, in SCREAMING_SNAKE_CASE

+ */ + DescriptionStage code(@NotNull String code); + } + + public interface DescriptionStage { + /** + *

A human-readable description of the warning

+ */ + _FinalStage description(@NotNull String description); + } + + public interface _FinalStage { + ListenV2Warning build(); + + _FinalStage additionalProperty(String key, Object value); + + _FinalStage additionalProperties(Map additionalProperties); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class Builder + implements RequestIdStage, SequenceIdStage, CodeStage, DescriptionStage, _FinalStage { + private String requestId; + + private int sequenceId; + + private String code; + + private String description; + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + @java.lang.Override + public Builder from(ListenV2Warning other) { + requestId(other.getRequestId()); + sequenceId(other.getSequenceId()); + code(other.getCode()); + description(other.getDescription()); + return this; + } + + /** + *

The unique identifier of the request

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + @JsonSetter("request_id") + public SequenceIdStage requestId(@NotNull String requestId) { + this.requestId = Objects.requireNonNull(requestId, "requestId must not be null"); + return this; + } + + /** + *

Starts at 0 and increments for each message the server sends + * to the client. This includes messages of other types, like + * TurnInfo messages.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + @JsonSetter("sequence_id") + public CodeStage sequenceId(int sequenceId) { + this.sequenceId = sequenceId; + return this; + } + + /** + *

Warning code identifying the condition, in SCREAMING_SNAKE_CASE

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + @JsonSetter("code") + public DescriptionStage code(@NotNull String code) { + this.code = Objects.requireNonNull(code, "code must not be null"); + return this; + } + + /** + *

A human-readable description of the warning

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + @JsonSetter("description") + public _FinalStage description(@NotNull String description) { + this.description = Objects.requireNonNull(description, "description must not be null"); + return this; + } + + @java.lang.Override + public ListenV2Warning build() { + return new ListenV2Warning(requestId, sequenceId, code, description, additionalProperties); + } + + @java.lang.Override + public Builder additionalProperty(String key, Object value) { + this.additionalProperties.put(key, value); + return this; + } + + @java.lang.Override + public Builder additionalProperties(Map additionalProperties) { + this.additionalProperties.putAll(additionalProperties); + return this; + } + } +} diff --git a/src/main/java/com/deepgram/resources/listen/v2/websocket/V2WebSocketClient.java b/src/main/java/com/deepgram/resources/listen/v2/websocket/V2WebSocketClient.java index b2dee9b4..2db1fe9b 100644 --- a/src/main/java/com/deepgram/resources/listen/v2/websocket/V2WebSocketClient.java +++ b/src/main/java/com/deepgram/resources/listen/v2/websocket/V2WebSocketClient.java @@ -3,8 +3,6 @@ */ package com.deepgram.resources.listen.v2.websocket; -// Manual patch - see .fernignore. - import com.deepgram.core.ClientOptions; import com.deepgram.core.DisconnectReason; import com.deepgram.core.ObjectMappers; @@ -20,6 +18,7 @@ import com.deepgram.resources.listen.v2.types.ListenV2FatalError; import com.deepgram.resources.listen.v2.types.ListenV2ForceEndTurn; import com.deepgram.resources.listen.v2.types.ListenV2TurnInfo; +import com.deepgram.resources.listen.v2.types.ListenV2Warning; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.concurrent.CompletableFuture; @@ -72,6 +71,8 @@ public class V2WebSocketClient implements AutoCloseable { private volatile Consumer configureFailureHandler; + private volatile Consumer warningHandler; + private volatile Consumer errorHandler; /** @@ -133,8 +134,7 @@ public CompletableFuture connect(V2ConnectOptions options) { "eot_timeout_ms", String.valueOf(options.getEotTimeoutMs().get())); } if (options.getKeyterm() != null && options.getKeyterm().isPresent()) { - QueryStringMapper.addQueryParameter( - urlBuilder, "keyterm", options.getKeyterm().get().get(), true); + QueryStringMapper.addQueryParameter(urlBuilder, "keyterm", options.getKeyterm().get().get(), true); } if (options.getLanguageHint() != null && options.getLanguageHint().isPresent()) { QueryStringMapper.addQueryParameter( @@ -175,13 +175,22 @@ public CompletableFuture connect(V2ConnectOptions options) { ? this.reconnectOptions : ReconnectingWebSocketListener.ReconnectOptions.builder().build(); this.reconnectingListener = - new ReconnectingWebSocketListener(reconnectOpts, () -> { - if (clientOptions.webSocketFactory().isPresent()) { - return clientOptions.webSocketFactory().get().create(request, this.reconnectingListener); - } else { - return okHttpClient.newWebSocket(request, this.reconnectingListener); - } - }) { + new ReconnectingWebSocketListener( + reconnectOpts, + () -> { + if (clientOptions.isClosed()) { + throw new IllegalStateException("root client has been closed"); + } + if (clientOptions.webSocketFactory().isPresent()) { + return clientOptions + .webSocketFactory() + .get() + .create(request, this.reconnectingListener); + } else { + return okHttpClient.newWebSocket(request, this.reconnectingListener); + } + }, + clientOptions::isClosed) { @Override protected void onWebSocketOpen(WebSocket webSocket, Response response) { closeStreamSocket.set(null); @@ -223,6 +232,7 @@ protected boolean shouldReconnectAfterClose(WebSocket webSocket, int code, Strin && (code != 1005 || closeStreamSocket.get() != webSocket); } }; + clientOptions.registerWebSocket(this); reconnectingListener.connect(); return connectionFuture; } @@ -231,6 +241,7 @@ protected boolean shouldReconnectAfterClose(WebSocket webSocket, int code, Strin * Disconnects the WebSocket connection and releases resources. */ public void disconnect() { + clientOptions.unregisterWebSocket(this); if (reconnectingListener != null) { reconnectingListener.disconnect(); } @@ -281,11 +292,6 @@ public CompletableFuture sendCloseStream(ListenV2CloseStream message) { /** * Sends a ListenV2ForceEndTurn message to the server asynchronously. - * - *

Sending this with no turn in progress is not an error. The server answers with a - * {@code Warning} frame carrying code {@code FORCE_END_TURN_NO_ACTIVE_TURN} and ignores the - * request. Listen V2 has no typed warning event yet, so that frame is delivered as raw JSON - * to {@link #onMessage(java.util.function.Consumer)}. * @param message the message to send * @return a CompletableFuture that completes when the message is sent */ @@ -334,6 +340,14 @@ public void onConfigureFailure(Consumer handler) { this.configureFailureHandler = handler; } + /** + * Registers a handler for ListenV2Warning messages from the server. + * @param handler the handler to invoke when a message is received + */ + public void onWarning(Consumer handler) { + this.warningHandler = handler; + } + /** * Registers a handler for ListenV2FatalError messages from the server. * @param handler the handler to invoke when a message is received @@ -351,8 +365,7 @@ public void onConnected(Runnable handler) { } /** - * Registers a handler called when the connection is closed. An empty peer close frame is - * reported with code 1005, even though the SDK acknowledges it with code 1000. + * Registers a handler called when the connection is closed. * @param handler the handler to invoke when disconnected */ public void onDisconnected(Consumer handler) { @@ -475,6 +488,23 @@ private void handleIncomingMessage(String json) { return; } } + if (node.has("request_id") + && node.has("sequence_id") + && node.has("code") + && node.has("description") + && "Warning".equals(node.path("type").asText())) { + ListenV2Warning warningHandlerEvent = null; + try { + warningHandlerEvent = objectMapper.treeToValue(node, ListenV2Warning.class); + } catch (Exception e) { + } + if (warningHandlerEvent != null) { + if (warningHandler != null) { + warningHandler.accept(warningHandlerEvent); + } + return; + } + } if (node.has("sequence_id") && node.has("code") && node.has("description") diff --git a/src/main/java/com/deepgram/resources/speak/v1/websocket/V1WebSocketClient.java b/src/main/java/com/deepgram/resources/speak/v1/websocket/V1WebSocketClient.java index ae271f2a..e6824a38 100644 --- a/src/main/java/com/deepgram/resources/speak/v1/websocket/V1WebSocketClient.java +++ b/src/main/java/com/deepgram/resources/speak/v1/websocket/V1WebSocketClient.java @@ -3,8 +3,6 @@ */ package com.deepgram.resources.speak.v1.websocket; -// Manual patch - see .fernignore. - import com.deepgram.core.ClientOptions; import com.deepgram.core.DisconnectReason; import com.deepgram.core.ObjectMappers; @@ -140,13 +138,22 @@ public CompletableFuture connect(V1ConnectOptions options) { ? this.reconnectOptions : ReconnectingWebSocketListener.ReconnectOptions.builder().build(); this.reconnectingListener = - new ReconnectingWebSocketListener(reconnectOpts, () -> { - if (clientOptions.webSocketFactory().isPresent()) { - return clientOptions.webSocketFactory().get().create(request, this.reconnectingListener); - } else { - return okHttpClient.newWebSocket(request, this.reconnectingListener); - } - }) { + new ReconnectingWebSocketListener( + reconnectOpts, + () -> { + if (clientOptions.isClosed()) { + throw new IllegalStateException("root client has been closed"); + } + if (clientOptions.webSocketFactory().isPresent()) { + return clientOptions + .webSocketFactory() + .get() + .create(request, this.reconnectingListener); + } else { + return okHttpClient.newWebSocket(request, this.reconnectingListener); + } + }, + clientOptions::isClosed) { @Override protected void onWebSocketOpen(WebSocket webSocket, Response response) { readyState = WebSocketReadyState.OPEN; @@ -185,6 +192,7 @@ protected void onWebSocketClosed(WebSocket webSocket, int code, String reason) { } } }; + clientOptions.registerWebSocket(this); reconnectingListener.connect(); return connectionFuture; } @@ -201,6 +209,7 @@ public CompletableFuture connect() { * Disconnects the WebSocket connection and releases resources. */ public void disconnect() { + clientOptions.unregisterWebSocket(this); if (reconnectingListener != null) { reconnectingListener.disconnect(); } diff --git a/src/main/java/com/deepgram/resources/speak/v2/types/SpeakV2Close.java b/src/main/java/com/deepgram/resources/speak/v2/types/SpeakV2Close.java index 0479ff66..7fecd79f 100644 --- a/src/main/java/com/deepgram/resources/speak/v2/types/SpeakV2Close.java +++ b/src/main/java/com/deepgram/resources/speak/v2/types/SpeakV2Close.java @@ -3,8 +3,6 @@ */ package com.deepgram.resources.speak.v2.types; -// Manual patch - see .fernignore. - import com.deepgram.core.ObjectMappers; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; diff --git a/src/main/java/com/deepgram/resources/speak/v2/types/SpeakV2Flush.java b/src/main/java/com/deepgram/resources/speak/v2/types/SpeakV2Flush.java index db0b1ec5..130da0d9 100644 --- a/src/main/java/com/deepgram/resources/speak/v2/types/SpeakV2Flush.java +++ b/src/main/java/com/deepgram/resources/speak/v2/types/SpeakV2Flush.java @@ -3,8 +3,6 @@ */ package com.deepgram.resources.speak.v2.types; -// Manual patch - see .fernignore. - import com.deepgram.core.ObjectMappers; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; diff --git a/src/main/java/com/deepgram/resources/speak/v2/websocket/V2WebSocketClient.java b/src/main/java/com/deepgram/resources/speak/v2/websocket/V2WebSocketClient.java index a94145db..b4e01f7a 100644 --- a/src/main/java/com/deepgram/resources/speak/v2/websocket/V2WebSocketClient.java +++ b/src/main/java/com/deepgram/resources/speak/v2/websocket/V2WebSocketClient.java @@ -3,8 +3,6 @@ */ package com.deepgram.resources.speak.v2.websocket; -// Manual patch - see .fernignore. - import com.deepgram.core.ClientOptions; import com.deepgram.core.DisconnectReason; import com.deepgram.core.ObjectMappers; @@ -163,13 +161,22 @@ public CompletableFuture connect(V2ConnectOptions options) { ? this.reconnectOptions : ReconnectingWebSocketListener.ReconnectOptions.builder().build(); this.reconnectingListener = - new ReconnectingWebSocketListener(reconnectOpts, () -> { - if (clientOptions.webSocketFactory().isPresent()) { - return clientOptions.webSocketFactory().get().create(request, this.reconnectingListener); - } else { - return okHttpClient.newWebSocket(request, this.reconnectingListener); - } - }) { + new ReconnectingWebSocketListener( + reconnectOpts, + () -> { + if (clientOptions.isClosed()) { + throw new IllegalStateException("root client has been closed"); + } + if (clientOptions.webSocketFactory().isPresent()) { + return clientOptions + .webSocketFactory() + .get() + .create(request, this.reconnectingListener); + } else { + return okHttpClient.newWebSocket(request, this.reconnectingListener); + } + }, + clientOptions::isClosed) { @Override protected void onWebSocketOpen(WebSocket webSocket, Response response) { readyState = WebSocketReadyState.OPEN; @@ -208,6 +215,7 @@ protected void onWebSocketClosed(WebSocket webSocket, int code, String reason) { } } }; + clientOptions.registerWebSocket(this); reconnectingListener.connect(); return connectionFuture; } @@ -216,6 +224,7 @@ protected void onWebSocketClosed(WebSocket webSocket, int code, String reason) { * Disconnects the WebSocket connection and releases resources. */ public void disconnect() { + clientOptions.unregisterWebSocket(this); if (reconnectingListener != null) { reconnectingListener.disconnect(); } diff --git a/src/main/java/com/deepgram/types/DeepgramModel.java b/src/main/java/com/deepgram/types/DeepgramModel.java index 14a797cc..6444d7f7 100644 --- a/src/main/java/com/deepgram/types/DeepgramModel.java +++ b/src/main/java/com/deepgram/types/DeepgramModel.java @@ -3,8 +3,6 @@ */ package com.deepgram.types; -// Manual patch - see .fernignore. - import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; diff --git a/src/main/java/com/deepgram/types/SharedIntents.java b/src/main/java/com/deepgram/types/SharedIntents.java index c689861c..05799c25 100644 --- a/src/main/java/com/deepgram/types/SharedIntents.java +++ b/src/main/java/com/deepgram/types/SharedIntents.java @@ -13,6 +13,7 @@ import com.fasterxml.jackson.annotation.Nulls; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -20,18 +21,19 @@ @JsonInclude(JsonInclude.Include.NON_ABSENT) @JsonDeserialize(builder = SharedIntents.Builder.class) public final class SharedIntents { - private final Optional results; + private final Optional> segments; private final Map additionalProperties; - private SharedIntents(Optional results, Map additionalProperties) { - this.results = results; + private SharedIntents( + Optional> segments, Map additionalProperties) { + this.segments = segments; this.additionalProperties = additionalProperties; } - @JsonProperty("results") - public Optional getResults() { - return results; + @JsonProperty("segments") + public Optional> getSegments() { + return segments; } @java.lang.Override @@ -46,12 +48,12 @@ public Map getAdditionalProperties() { } private boolean equalTo(SharedIntents other) { - return results.equals(other.results); + return segments.equals(other.segments); } @java.lang.Override public int hashCode() { - return Objects.hash(this.results); + return Objects.hash(this.segments); } @java.lang.Override @@ -65,7 +67,7 @@ public static Builder builder() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder { - private Optional results = Optional.empty(); + private Optional> segments = Optional.empty(); @JsonAnySetter private Map additionalProperties = new HashMap<>(); @@ -73,23 +75,23 @@ public static final class Builder { private Builder() {} public Builder from(SharedIntents other) { - results(other.getResults()); + segments(other.getSegments()); return this; } - @JsonSetter(value = "results", nulls = Nulls.SKIP) - public Builder results(Optional results) { - this.results = results; + @JsonSetter(value = "segments", nulls = Nulls.SKIP) + public Builder segments(Optional> segments) { + this.segments = segments; return this; } - public Builder results(SharedIntentsResults results) { - this.results = Optional.ofNullable(results); + public Builder segments(List segments) { + this.segments = Optional.ofNullable(segments); return this; } public SharedIntents build() { - return new SharedIntents(results, additionalProperties); + return new SharedIntents(segments, additionalProperties); } public Builder additionalProperty(String key, Object value) { diff --git a/src/main/java/com/deepgram/types/SharedIntentsResults.java b/src/main/java/com/deepgram/types/SharedIntentsResults.java deleted file mode 100644 index 44bfe377..00000000 --- a/src/main/java/com/deepgram/types/SharedIntentsResults.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.deepgram.types; - -import com.deepgram.core.ObjectMappers; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = SharedIntentsResults.Builder.class) -public final class SharedIntentsResults { - private final Optional intents; - - private final Map additionalProperties; - - private SharedIntentsResults( - Optional intents, Map additionalProperties) { - this.intents = intents; - this.additionalProperties = additionalProperties; - } - - @JsonProperty("intents") - public Optional getIntents() { - return intents; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof SharedIntentsResults && equalTo((SharedIntentsResults) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(SharedIntentsResults other) { - return intents.equals(other.intents); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.intents); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional intents = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(SharedIntentsResults other) { - intents(other.getIntents()); - return this; - } - - @JsonSetter(value = "intents", nulls = Nulls.SKIP) - public Builder intents(Optional intents) { - this.intents = intents; - return this; - } - - public Builder intents(SharedIntentsResultsIntents intents) { - this.intents = Optional.ofNullable(intents); - return this; - } - - public SharedIntentsResults build() { - return new SharedIntentsResults(intents, additionalProperties); - } - - public Builder additionalProperty(String key, Object value) { - this.additionalProperties.put(key, value); - return this; - } - - public Builder additionalProperties(Map additionalProperties) { - this.additionalProperties.putAll(additionalProperties); - return this; - } - } -} diff --git a/src/main/java/com/deepgram/types/SharedIntentsResultsIntents.java b/src/main/java/com/deepgram/types/SharedIntentsResultsIntents.java deleted file mode 100644 index a5fe89b0..00000000 --- a/src/main/java/com/deepgram/types/SharedIntentsResultsIntents.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.deepgram.types; - -import com.deepgram.core.ObjectMappers; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = SharedIntentsResultsIntents.Builder.class) -public final class SharedIntentsResultsIntents { - private final Optional> segments; - - private final Map additionalProperties; - - private SharedIntentsResultsIntents( - Optional> segments, - Map additionalProperties) { - this.segments = segments; - this.additionalProperties = additionalProperties; - } - - @JsonProperty("segments") - public Optional> getSegments() { - return segments; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof SharedIntentsResultsIntents && equalTo((SharedIntentsResultsIntents) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(SharedIntentsResultsIntents other) { - return segments.equals(other.segments); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.segments); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional> segments = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(SharedIntentsResultsIntents other) { - segments(other.getSegments()); - return this; - } - - @JsonSetter(value = "segments", nulls = Nulls.SKIP) - public Builder segments(Optional> segments) { - this.segments = segments; - return this; - } - - public Builder segments(List segments) { - this.segments = Optional.ofNullable(segments); - return this; - } - - public SharedIntentsResultsIntents build() { - return new SharedIntentsResultsIntents(segments, additionalProperties); - } - - public Builder additionalProperty(String key, Object value) { - this.additionalProperties.put(key, value); - return this; - } - - public Builder additionalProperties(Map additionalProperties) { - this.additionalProperties.putAll(additionalProperties); - return this; - } - } -} diff --git a/src/main/java/com/deepgram/types/SharedIntentsResultsIntentsSegmentsItem.java b/src/main/java/com/deepgram/types/SharedIntentsSegmentsItem.java similarity index 78% rename from src/main/java/com/deepgram/types/SharedIntentsResultsIntentsSegmentsItem.java rename to src/main/java/com/deepgram/types/SharedIntentsSegmentsItem.java index 694be4f6..431b68f0 100644 --- a/src/main/java/com/deepgram/types/SharedIntentsResultsIntentsSegmentsItem.java +++ b/src/main/java/com/deepgram/types/SharedIntentsSegmentsItem.java @@ -19,23 +19,23 @@ import java.util.Optional; @JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = SharedIntentsResultsIntentsSegmentsItem.Builder.class) -public final class SharedIntentsResultsIntentsSegmentsItem { +@JsonDeserialize(builder = SharedIntentsSegmentsItem.Builder.class) +public final class SharedIntentsSegmentsItem { private final Optional text; private final Optional startWord; private final Optional endWord; - private final Optional> intents; + private final Optional> intents; private final Map additionalProperties; - private SharedIntentsResultsIntentsSegmentsItem( + private SharedIntentsSegmentsItem( Optional text, Optional startWord, Optional endWord, - Optional> intents, + Optional> intents, Map additionalProperties) { this.text = text; this.startWord = startWord; @@ -60,15 +60,14 @@ public Optional getEndWord() { } @JsonProperty("intents") - public Optional> getIntents() { + public Optional> getIntents() { return intents; } @java.lang.Override public boolean equals(Object other) { if (this == other) return true; - return other instanceof SharedIntentsResultsIntentsSegmentsItem - && equalTo((SharedIntentsResultsIntentsSegmentsItem) other); + return other instanceof SharedIntentsSegmentsItem && equalTo((SharedIntentsSegmentsItem) other); } @JsonAnyGetter @@ -76,7 +75,7 @@ public Map getAdditionalProperties() { return this.additionalProperties; } - private boolean equalTo(SharedIntentsResultsIntentsSegmentsItem other) { + private boolean equalTo(SharedIntentsSegmentsItem other) { return text.equals(other.text) && startWord.equals(other.startWord) && endWord.equals(other.endWord) @@ -105,14 +104,14 @@ public static final class Builder { private Optional endWord = Optional.empty(); - private Optional> intents = Optional.empty(); + private Optional> intents = Optional.empty(); @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} - public Builder from(SharedIntentsResultsIntentsSegmentsItem other) { + public Builder from(SharedIntentsSegmentsItem other) { text(other.getText()); startWord(other.getStartWord()); endWord(other.getEndWord()); @@ -154,18 +153,18 @@ public Builder endWord(Double endWord) { } @JsonSetter(value = "intents", nulls = Nulls.SKIP) - public Builder intents(Optional> intents) { + public Builder intents(Optional> intents) { this.intents = intents; return this; } - public Builder intents(List intents) { + public Builder intents(List intents) { this.intents = Optional.ofNullable(intents); return this; } - public SharedIntentsResultsIntentsSegmentsItem build() { - return new SharedIntentsResultsIntentsSegmentsItem(text, startWord, endWord, intents, additionalProperties); + public SharedIntentsSegmentsItem build() { + return new SharedIntentsSegmentsItem(text, startWord, endWord, intents, additionalProperties); } public Builder additionalProperty(String key, Object value) { diff --git a/src/main/java/com/deepgram/types/SharedIntentsResultsIntentsSegmentsItemIntentsItem.java b/src/main/java/com/deepgram/types/SharedIntentsSegmentsItemIntentsItem.java similarity index 81% rename from src/main/java/com/deepgram/types/SharedIntentsResultsIntentsSegmentsItemIntentsItem.java rename to src/main/java/com/deepgram/types/SharedIntentsSegmentsItemIntentsItem.java index d6554e2b..9f97c919 100644 --- a/src/main/java/com/deepgram/types/SharedIntentsResultsIntentsSegmentsItemIntentsItem.java +++ b/src/main/java/com/deepgram/types/SharedIntentsSegmentsItemIntentsItem.java @@ -18,15 +18,15 @@ import java.util.Optional; @JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = SharedIntentsResultsIntentsSegmentsItemIntentsItem.Builder.class) -public final class SharedIntentsResultsIntentsSegmentsItemIntentsItem { +@JsonDeserialize(builder = SharedIntentsSegmentsItemIntentsItem.Builder.class) +public final class SharedIntentsSegmentsItemIntentsItem { private final Optional intent; private final Optional confidenceScore; private final Map additionalProperties; - private SharedIntentsResultsIntentsSegmentsItemIntentsItem( + private SharedIntentsSegmentsItemIntentsItem( Optional intent, Optional confidenceScore, Map additionalProperties) { this.intent = intent; this.confidenceScore = confidenceScore; @@ -46,8 +46,8 @@ public Optional getConfidenceScore() { @java.lang.Override public boolean equals(Object other) { if (this == other) return true; - return other instanceof SharedIntentsResultsIntentsSegmentsItemIntentsItem - && equalTo((SharedIntentsResultsIntentsSegmentsItemIntentsItem) other); + return other instanceof SharedIntentsSegmentsItemIntentsItem + && equalTo((SharedIntentsSegmentsItemIntentsItem) other); } @JsonAnyGetter @@ -55,7 +55,7 @@ public Map getAdditionalProperties() { return this.additionalProperties; } - private boolean equalTo(SharedIntentsResultsIntentsSegmentsItemIntentsItem other) { + private boolean equalTo(SharedIntentsSegmentsItemIntentsItem other) { return intent.equals(other.intent) && confidenceScore.equals(other.confidenceScore); } @@ -84,7 +84,7 @@ public static final class Builder { private Builder() {} - public Builder from(SharedIntentsResultsIntentsSegmentsItemIntentsItem other) { + public Builder from(SharedIntentsSegmentsItemIntentsItem other) { intent(other.getIntent()); confidenceScore(other.getConfidenceScore()); return this; @@ -112,9 +112,8 @@ public Builder confidenceScore(Float confidenceScore) { return this; } - public SharedIntentsResultsIntentsSegmentsItemIntentsItem build() { - return new SharedIntentsResultsIntentsSegmentsItemIntentsItem( - intent, confidenceScore, additionalProperties); + public SharedIntentsSegmentsItemIntentsItem build() { + return new SharedIntentsSegmentsItemIntentsItem(intent, confidenceScore, additionalProperties); } public Builder additionalProperty(String key, Object value) { diff --git a/src/main/java/com/deepgram/types/SharedTopics.java b/src/main/java/com/deepgram/types/SharedTopics.java index 463e84ca..25a75ea4 100644 --- a/src/main/java/com/deepgram/types/SharedTopics.java +++ b/src/main/java/com/deepgram/types/SharedTopics.java @@ -13,6 +13,7 @@ import com.fasterxml.jackson.annotation.Nulls; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -20,18 +21,18 @@ @JsonInclude(JsonInclude.Include.NON_ABSENT) @JsonDeserialize(builder = SharedTopics.Builder.class) public final class SharedTopics { - private final Optional results; + private final Optional> segments; private final Map additionalProperties; - private SharedTopics(Optional results, Map additionalProperties) { - this.results = results; + private SharedTopics(Optional> segments, Map additionalProperties) { + this.segments = segments; this.additionalProperties = additionalProperties; } - @JsonProperty("results") - public Optional getResults() { - return results; + @JsonProperty("segments") + public Optional> getSegments() { + return segments; } @java.lang.Override @@ -46,12 +47,12 @@ public Map getAdditionalProperties() { } private boolean equalTo(SharedTopics other) { - return results.equals(other.results); + return segments.equals(other.segments); } @java.lang.Override public int hashCode() { - return Objects.hash(this.results); + return Objects.hash(this.segments); } @java.lang.Override @@ -65,7 +66,7 @@ public static Builder builder() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder { - private Optional results = Optional.empty(); + private Optional> segments = Optional.empty(); @JsonAnySetter private Map additionalProperties = new HashMap<>(); @@ -73,23 +74,23 @@ public static final class Builder { private Builder() {} public Builder from(SharedTopics other) { - results(other.getResults()); + segments(other.getSegments()); return this; } - @JsonSetter(value = "results", nulls = Nulls.SKIP) - public Builder results(Optional results) { - this.results = results; + @JsonSetter(value = "segments", nulls = Nulls.SKIP) + public Builder segments(Optional> segments) { + this.segments = segments; return this; } - public Builder results(SharedTopicsResults results) { - this.results = Optional.ofNullable(results); + public Builder segments(List segments) { + this.segments = Optional.ofNullable(segments); return this; } public SharedTopics build() { - return new SharedTopics(results, additionalProperties); + return new SharedTopics(segments, additionalProperties); } public Builder additionalProperty(String key, Object value) { diff --git a/src/main/java/com/deepgram/types/SharedTopicsResults.java b/src/main/java/com/deepgram/types/SharedTopicsResults.java deleted file mode 100644 index d25c8cc9..00000000 --- a/src/main/java/com/deepgram/types/SharedTopicsResults.java +++ /dev/null @@ -1,105 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.deepgram.types; - -import com.deepgram.core.ObjectMappers; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = SharedTopicsResults.Builder.class) -public final class SharedTopicsResults { - private final Optional topics; - - private final Map additionalProperties; - - private SharedTopicsResults(Optional topics, Map additionalProperties) { - this.topics = topics; - this.additionalProperties = additionalProperties; - } - - @JsonProperty("topics") - public Optional getTopics() { - return topics; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof SharedTopicsResults && equalTo((SharedTopicsResults) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(SharedTopicsResults other) { - return topics.equals(other.topics); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.topics); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional topics = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(SharedTopicsResults other) { - topics(other.getTopics()); - return this; - } - - @JsonSetter(value = "topics", nulls = Nulls.SKIP) - public Builder topics(Optional topics) { - this.topics = topics; - return this; - } - - public Builder topics(SharedTopicsResultsTopics topics) { - this.topics = Optional.ofNullable(topics); - return this; - } - - public SharedTopicsResults build() { - return new SharedTopicsResults(topics, additionalProperties); - } - - public Builder additionalProperty(String key, Object value) { - this.additionalProperties.put(key, value); - return this; - } - - public Builder additionalProperties(Map additionalProperties) { - this.additionalProperties.putAll(additionalProperties); - return this; - } - } -} diff --git a/src/main/java/com/deepgram/types/SharedTopicsResultsTopics.java b/src/main/java/com/deepgram/types/SharedTopicsResultsTopics.java deleted file mode 100644 index e3a1cbba..00000000 --- a/src/main/java/com/deepgram/types/SharedTopicsResultsTopics.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * This file was auto-generated by Fern from our API Definition. - */ -package com.deepgram.types; - -import com.deepgram.core.ObjectMappers; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.Nulls; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -@JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = SharedTopicsResultsTopics.Builder.class) -public final class SharedTopicsResultsTopics { - private final Optional> segments; - - private final Map additionalProperties; - - private SharedTopicsResultsTopics( - Optional> segments, Map additionalProperties) { - this.segments = segments; - this.additionalProperties = additionalProperties; - } - - @JsonProperty("segments") - public Optional> getSegments() { - return segments; - } - - @java.lang.Override - public boolean equals(Object other) { - if (this == other) return true; - return other instanceof SharedTopicsResultsTopics && equalTo((SharedTopicsResultsTopics) other); - } - - @JsonAnyGetter - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - private boolean equalTo(SharedTopicsResultsTopics other) { - return segments.equals(other.segments); - } - - @java.lang.Override - public int hashCode() { - return Objects.hash(this.segments); - } - - @java.lang.Override - public String toString() { - return ObjectMappers.stringify(this); - } - - public static Builder builder() { - return new Builder(); - } - - @JsonIgnoreProperties(ignoreUnknown = true) - public static final class Builder { - private Optional> segments = Optional.empty(); - - @JsonAnySetter - private Map additionalProperties = new HashMap<>(); - - private Builder() {} - - public Builder from(SharedTopicsResultsTopics other) { - segments(other.getSegments()); - return this; - } - - @JsonSetter(value = "segments", nulls = Nulls.SKIP) - public Builder segments(Optional> segments) { - this.segments = segments; - return this; - } - - public Builder segments(List segments) { - this.segments = Optional.ofNullable(segments); - return this; - } - - public SharedTopicsResultsTopics build() { - return new SharedTopicsResultsTopics(segments, additionalProperties); - } - - public Builder additionalProperty(String key, Object value) { - this.additionalProperties.put(key, value); - return this; - } - - public Builder additionalProperties(Map additionalProperties) { - this.additionalProperties.putAll(additionalProperties); - return this; - } - } -} diff --git a/src/main/java/com/deepgram/types/SharedTopicsResultsTopicsSegmentsItem.java b/src/main/java/com/deepgram/types/SharedTopicsSegmentsItem.java similarity index 78% rename from src/main/java/com/deepgram/types/SharedTopicsResultsTopicsSegmentsItem.java rename to src/main/java/com/deepgram/types/SharedTopicsSegmentsItem.java index 19cd942e..b479076e 100644 --- a/src/main/java/com/deepgram/types/SharedTopicsResultsTopicsSegmentsItem.java +++ b/src/main/java/com/deepgram/types/SharedTopicsSegmentsItem.java @@ -19,23 +19,23 @@ import java.util.Optional; @JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = SharedTopicsResultsTopicsSegmentsItem.Builder.class) -public final class SharedTopicsResultsTopicsSegmentsItem { +@JsonDeserialize(builder = SharedTopicsSegmentsItem.Builder.class) +public final class SharedTopicsSegmentsItem { private final Optional text; private final Optional startWord; private final Optional endWord; - private final Optional> topics; + private final Optional> topics; private final Map additionalProperties; - private SharedTopicsResultsTopicsSegmentsItem( + private SharedTopicsSegmentsItem( Optional text, Optional startWord, Optional endWord, - Optional> topics, + Optional> topics, Map additionalProperties) { this.text = text; this.startWord = startWord; @@ -60,15 +60,14 @@ public Optional getEndWord() { } @JsonProperty("topics") - public Optional> getTopics() { + public Optional> getTopics() { return topics; } @java.lang.Override public boolean equals(Object other) { if (this == other) return true; - return other instanceof SharedTopicsResultsTopicsSegmentsItem - && equalTo((SharedTopicsResultsTopicsSegmentsItem) other); + return other instanceof SharedTopicsSegmentsItem && equalTo((SharedTopicsSegmentsItem) other); } @JsonAnyGetter @@ -76,7 +75,7 @@ public Map getAdditionalProperties() { return this.additionalProperties; } - private boolean equalTo(SharedTopicsResultsTopicsSegmentsItem other) { + private boolean equalTo(SharedTopicsSegmentsItem other) { return text.equals(other.text) && startWord.equals(other.startWord) && endWord.equals(other.endWord) @@ -105,14 +104,14 @@ public static final class Builder { private Optional endWord = Optional.empty(); - private Optional> topics = Optional.empty(); + private Optional> topics = Optional.empty(); @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} - public Builder from(SharedTopicsResultsTopicsSegmentsItem other) { + public Builder from(SharedTopicsSegmentsItem other) { text(other.getText()); startWord(other.getStartWord()); endWord(other.getEndWord()); @@ -154,18 +153,18 @@ public Builder endWord(Double endWord) { } @JsonSetter(value = "topics", nulls = Nulls.SKIP) - public Builder topics(Optional> topics) { + public Builder topics(Optional> topics) { this.topics = topics; return this; } - public Builder topics(List topics) { + public Builder topics(List topics) { this.topics = Optional.ofNullable(topics); return this; } - public SharedTopicsResultsTopicsSegmentsItem build() { - return new SharedTopicsResultsTopicsSegmentsItem(text, startWord, endWord, topics, additionalProperties); + public SharedTopicsSegmentsItem build() { + return new SharedTopicsSegmentsItem(text, startWord, endWord, topics, additionalProperties); } public Builder additionalProperty(String key, Object value) { diff --git a/src/main/java/com/deepgram/types/SharedTopicsResultsTopicsSegmentsItemTopicsItem.java b/src/main/java/com/deepgram/types/SharedTopicsSegmentsItemTopicsItem.java similarity index 82% rename from src/main/java/com/deepgram/types/SharedTopicsResultsTopicsSegmentsItemTopicsItem.java rename to src/main/java/com/deepgram/types/SharedTopicsSegmentsItemTopicsItem.java index 3721cd8b..03464d24 100644 --- a/src/main/java/com/deepgram/types/SharedTopicsResultsTopicsSegmentsItemTopicsItem.java +++ b/src/main/java/com/deepgram/types/SharedTopicsSegmentsItemTopicsItem.java @@ -18,15 +18,15 @@ import java.util.Optional; @JsonInclude(JsonInclude.Include.NON_ABSENT) -@JsonDeserialize(builder = SharedTopicsResultsTopicsSegmentsItemTopicsItem.Builder.class) -public final class SharedTopicsResultsTopicsSegmentsItemTopicsItem { +@JsonDeserialize(builder = SharedTopicsSegmentsItemTopicsItem.Builder.class) +public final class SharedTopicsSegmentsItemTopicsItem { private final Optional topic; private final Optional confidenceScore; private final Map additionalProperties; - private SharedTopicsResultsTopicsSegmentsItemTopicsItem( + private SharedTopicsSegmentsItemTopicsItem( Optional topic, Optional confidenceScore, Map additionalProperties) { this.topic = topic; this.confidenceScore = confidenceScore; @@ -46,8 +46,8 @@ public Optional getConfidenceScore() { @java.lang.Override public boolean equals(Object other) { if (this == other) return true; - return other instanceof SharedTopicsResultsTopicsSegmentsItemTopicsItem - && equalTo((SharedTopicsResultsTopicsSegmentsItemTopicsItem) other); + return other instanceof SharedTopicsSegmentsItemTopicsItem + && equalTo((SharedTopicsSegmentsItemTopicsItem) other); } @JsonAnyGetter @@ -55,7 +55,7 @@ public Map getAdditionalProperties() { return this.additionalProperties; } - private boolean equalTo(SharedTopicsResultsTopicsSegmentsItemTopicsItem other) { + private boolean equalTo(SharedTopicsSegmentsItemTopicsItem other) { return topic.equals(other.topic) && confidenceScore.equals(other.confidenceScore); } @@ -84,7 +84,7 @@ public static final class Builder { private Builder() {} - public Builder from(SharedTopicsResultsTopicsSegmentsItemTopicsItem other) { + public Builder from(SharedTopicsSegmentsItemTopicsItem other) { topic(other.getTopic()); confidenceScore(other.getConfidenceScore()); return this; @@ -112,8 +112,8 @@ public Builder confidenceScore(Float confidenceScore) { return this; } - public SharedTopicsResultsTopicsSegmentsItemTopicsItem build() { - return new SharedTopicsResultsTopicsSegmentsItemTopicsItem(topic, confidenceScore, additionalProperties); + public SharedTopicsSegmentsItemTopicsItem build() { + return new SharedTopicsSegmentsItemTopicsItem(topic, confidenceScore, additionalProperties); } public Builder additionalProperty(String key, Object value) {