Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
111 changes: 111 additions & 0 deletions .claude/scripts/fix_clientoptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/usr/bin/env python3

import json
import re
import sys
from pathlib import Path


CLIENT_OPTIONS_PATH = Path("src/main/java/com/deepgram/core/ClientOptions.java")
CLIENT_OPTIONS_BAK_PATH = Path("src/main/java/com/deepgram/core/ClientOptions.java.bak")
BUILD_GRADLE_PATH = Path("build.gradle")
METADATA_PATH = Path(".fern/metadata.json")
SDK_NAME = "com.deepgram:deepgram-java-sdk"


def load_sdk_version(text: str) -> str:
if CLIENT_OPTIONS_BAK_PATH.exists():
bak_text = CLIENT_OPTIONS_BAK_PATH.read_text()
match = re.search(r'put\("X-Fern-SDK-Version",\s*"([^"]+)"\)', bak_text)
if match:
return match.group(1)

match = re.search(r'put\("User-Agent",\s*"[^"]*/([^"]+)"\)', bak_text)
if match:
return match.group(1)

if BUILD_GRADLE_PATH.exists():
build_gradle = BUILD_GRADLE_PATH.read_text()
match = re.search(r"^version\s*=\s*'([^']+)'", build_gradle, re.MULTILINE)
if match:
return match.group(1)

match = re.search(r'put\("X-Fern-SDK-Version",\s*"([^"]+)"\)', text)
if match:
return match.group(1)

match = re.search(r'put\("User-Agent",\s*"[^"]*/([^"]+)"\)', text)
if match:
return match.group(1)

if METADATA_PATH.exists():
metadata = json.loads(METADATA_PATH.read_text())
sdk_version = metadata.get("sdkVersion")
if sdk_version:
return sdk_version

raise RuntimeError("Unable to determine SDK version for ClientOptions.java")


def replace_header_line(
text: str, key: str, value: str, add_release_please: bool
) -> str:
pattern = re.compile(
rf'^(?P<indent>\s*)put\("{re.escape(key)}",\s*"[^"]*"\);(?:\s*// x-release-please-version)?\s*$',
re.MULTILINE,
)

def repl(match: re.Match[str]) -> str:
suffix = " // x-release-please-version" if add_release_please else ""
return f'{match.group("indent")}put("{key}", "{value}");{suffix}'

updated_text, count = pattern.subn(repl, text, count=1)
if count != 1:
raise RuntimeError(f"Unable to locate header line for {key}")
return updated_text


def main() -> int:
if not CLIENT_OPTIONS_PATH.exists():
raise RuntimeError(f"File not found: {CLIENT_OPTIONS_PATH}")

original_text = CLIENT_OPTIONS_PATH.read_text()
sdk_version = load_sdk_version(original_text)

updated_text = original_text
updated_text = replace_header_line(
updated_text,
"User-Agent",
f"{SDK_NAME}/{sdk_version}",
add_release_please=True,
)
updated_text = replace_header_line(
updated_text,
"X-Fern-SDK-Name",
SDK_NAME,
add_release_please=False,
)
updated_text = replace_header_line(
updated_text,
"X-Fern-SDK-Version",
sdk_version,
add_release_please=True,
)

if updated_text != original_text:
CLIENT_OPTIONS_PATH.write_text(updated_text)
print(f"Updated {CLIENT_OPTIONS_PATH} to {SDK_NAME}/{sdk_version}")
else:
print(
f"{CLIENT_OPTIONS_PATH} already has the expected Deepgram header constants"
)

return 0


if __name__ == "__main__":
try:
raise SystemExit(main())
except Exception as exc:
print(f"Error: {exc}", file=sys.stderr)
raise SystemExit(1)
2 changes: 1 addition & 1 deletion .claude/skills/review-regen.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Read AGENTS.md for full context on the regeneration workflow and freeze classifi
- Patches still needed (must be re-applied)
- New changes from the generator worth noting
5. Wait for user direction on which patches to re-apply.
6. Re-apply confirmed patches to the generated files.
6. Re-apply confirmed patches to the generated files. If `src/main/java/com/deepgram/core/ClientOptions.java` was regenerated, run `python3 .claude/scripts/fix_clientoptions.py` to restore the Deepgram SDK header constants and `// x-release-please-version` markers.
7. In `.fernignore`, replace each `.bak` path back to the original path for files that still need patches.
8. Remove `.fernignore` entries entirely for files where patches are no longer needed.
9. Delete all `.bak` files.
Expand Down
12 changes: 8 additions & 4 deletions .fern/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"cliVersion": "4.46.0",
"cliVersion": "4.87.0",
"generatorName": "fernapi/fern-java-sdk",
"generatorVersion": "4.0.4",
"generatorVersion": "4.4.0",
"generatorConfig": {
"package-prefix": "com.deepgram",
"base-api-exception-class-name": "DeepgramHttpException",
Expand All @@ -11,6 +11,10 @@
},
"enable-wire-tests": true
},
"originGitCommit": "e994b5ab79ae6fe3560daff055acdf80d315b48e",
"sdkVersion": "0.2.1"
"originGitCommit": "4730eb7243c9cfe73f3fceb335f2369ea17c8d45",
"originGitCommitIsDirty": true,
"invokedBy": "manual",
"requestedVersion": null,
"ciProvider": null,
"sdkVersion": "0.2.2"
}
7 changes: 6 additions & 1 deletion .fernignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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/
Expand Down Expand Up @@ -46,5 +46,10 @@ examples/
.github/
.gitignore

# Agent files
AGENTS.md
CLAUDE.md
.claude/

# Build output
target/
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ How to identify:

Current temporarily frozen files:

- `src/main/java/com/deepgram/core/ClientOptions.java` - preserves release-please version markers and correct SDK header constants that Fern currently overwrites
- `src/main/java/com/deepgram/core/ClientOptions.java` - preserves release-please version markers and correct SDK header constants that Fern currently overwrites; re-apply with `python3 .claude/scripts/fix_clientoptions.py` during review regen

### Prepare repo for regeneration

Expand All @@ -66,7 +66,7 @@ Current temporarily frozen files:
The `.bak` files are our manually patched versions protected by `.fernignore`. The original paths now contain the freshly generated versions. By comparing the two, we can see what the generator now produces versus what we had patched.

1. Diff each `.bak` file against the new generated version to understand what changed and whether our patches are still needed.
2. Re-apply any patches that are still necessary to the newly generated files.
2. Re-apply any patches that are still necessary to the newly generated files. For `src/main/java/com/deepgram/core/ClientOptions.java`, run `python3 .claude/scripts/fix_clientoptions.py` to restore the Deepgram SDK header constants and `// x-release-please-version` markers.
3. In `.fernignore`, replace each `.bak` path back to the original path for files that still need patches.
4. Remove `.fernignore` entries entirely for any files where the generator now produces correct output.
5. Delete all `.bak` files once review is complete.
Expand Down
4 changes: 0 additions & 4 deletions context7.json

This file was deleted.

8 changes: 8 additions & 0 deletions src/main/java/com/deepgram/AsyncDeepgramApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.deepgram.resources.read.AsyncReadClient;
import com.deepgram.resources.selfhosted.AsyncSelfHostedClient;
import com.deepgram.resources.speak.AsyncSpeakClient;
import com.deepgram.resources.voiceagent.AsyncVoiceAgentClient;
import java.util.function.Supplier;

public class AsyncDeepgramApiClient {
Expand All @@ -31,6 +32,8 @@ public class AsyncDeepgramApiClient {

protected final Supplier<AsyncSpeakClient> speakClient;

protected final Supplier<AsyncVoiceAgentClient> voiceAgentClient;

public AsyncDeepgramApiClient(ClientOptions clientOptions) {
this.clientOptions = clientOptions;
this.agentClient = Suppliers.memoize(() -> new AsyncAgentClient(clientOptions));
Expand All @@ -40,6 +43,7 @@ public AsyncDeepgramApiClient(ClientOptions clientOptions) {
this.readClient = Suppliers.memoize(() -> new AsyncReadClient(clientOptions));
this.selfHostedClient = Suppliers.memoize(() -> new AsyncSelfHostedClient(clientOptions));
this.speakClient = Suppliers.memoize(() -> new AsyncSpeakClient(clientOptions));
this.voiceAgentClient = Suppliers.memoize(() -> new AsyncVoiceAgentClient(clientOptions));
}

public AsyncAgentClient agent() {
Expand Down Expand Up @@ -70,6 +74,10 @@ public AsyncSpeakClient speak() {
return this.speakClient.get();
}

public AsyncVoiceAgentClient voiceAgent() {
return this.voiceAgentClient.get();
}

public static AsyncDeepgramApiClientBuilder builder() {
return new AsyncDeepgramApiClientBuilder();
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/deepgram/DeepgramApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.deepgram.resources.read.ReadClient;
import com.deepgram.resources.selfhosted.SelfHostedClient;
import com.deepgram.resources.speak.SpeakClient;
import com.deepgram.resources.voiceagent.VoiceAgentClient;
import java.util.function.Supplier;

public class DeepgramApiClient {
Expand All @@ -31,6 +32,8 @@ public class DeepgramApiClient {

protected final Supplier<SpeakClient> speakClient;

protected final Supplier<VoiceAgentClient> voiceAgentClient;

public DeepgramApiClient(ClientOptions clientOptions) {
this.clientOptions = clientOptions;
this.agentClient = Suppliers.memoize(() -> new AgentClient(clientOptions));
Expand All @@ -40,6 +43,7 @@ public DeepgramApiClient(ClientOptions clientOptions) {
this.readClient = Suppliers.memoize(() -> new ReadClient(clientOptions));
this.selfHostedClient = Suppliers.memoize(() -> new SelfHostedClient(clientOptions));
this.speakClient = Suppliers.memoize(() -> new SpeakClient(clientOptions));
this.voiceAgentClient = Suppliers.memoize(() -> new VoiceAgentClient(clientOptions));
}

public AgentClient agent() {
Expand Down Expand Up @@ -70,6 +74,10 @@ public SpeakClient speak() {
return this.speakClient.get();
}

public VoiceAgentClient voiceAgent() {
return this.voiceAgentClient.get();
}

public static DeepgramApiClientBuilder builder() {
return new DeepgramApiClientBuilder();
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/deepgram/core/ClientOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ private ClientOptions(
this.headers.putAll(headers);
this.headers.putAll(new HashMap<String, String>() {
{
put("User-Agent", "com.deepgram:deepgram-java-sdk/0.2.1"); // x-release-please-version
put("User-Agent", "com.deepgram:deepgram-sdk/0.2.2");
put("X-Fern-Language", "JAVA");
put("X-Fern-SDK-Name", "com.deepgram:deepgram-java-sdk");
put("X-Fern-SDK-Version", "0.2.1"); // x-release-please-version
put("X-Fern-SDK-Name", "com.deepgram.fern:api-sdk");
put("X-Fern-SDK-Version", "0.2.2");
}
});
this.headerSuppliers = headerSuppliers;
Expand Down
Loading
Loading