Skip to content
Open
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
28 changes: 28 additions & 0 deletions genkit/src/main/java/com/google/genkit/Genkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class Genkit {
private final Map<String, DotPrompt<?>> promptCache;
private final Map<String, Agent> agentRegistry;
private ReflectionServer reflectionServer;
private ReflectionServerV2 reflectionServerV2;
private EvaluationManager evaluationManager;

/** Creates a new Genkit instance with default options. */
Expand Down Expand Up @@ -1540,6 +1541,15 @@ public List<Plugin> getPlugins() {

/** Starts the reflection server for dev tools integration. */
private void startReflectionServer() {
String v2ServerUrl = System.getenv("GENKIT_REFLECTION_V2_SERVER");
if (v2ServerUrl != null && !v2ServerUrl.isEmpty()) {
startReflectionServerV2(v2ServerUrl);
} else {
startReflectionServerV1();
}
}

private void startReflectionServerV1() {
try {
int port = options.getReflectionPort();
reflectionServer = new ReflectionServer(registry, port);
Expand All @@ -1554,8 +1564,26 @@ private void startReflectionServer() {
}
}

private void startReflectionServerV2(String serverUrl) {
try {
reflectionServerV2 = new ReflectionServerV2(registry, serverUrl);
reflectionServerV2.start();
logger.info("Reflection V2 client connecting to {}", serverUrl);
} catch (Exception e) {
logger.error("Failed to start reflection V2 client", e);
throw new GenkitException("Failed to start reflection V2 client", e);
}
}

/** Stops the Genkit instance and cleans up resources. */
public void stop() {
if (reflectionServerV2 != null) {
try {
reflectionServerV2.stop();
} catch (Exception e) {
logger.warn("Error stopping reflection V2 client", e);
}
}
if (reflectionServer != null) {
try {
reflectionServer.stop();
Expand Down
Loading
Loading