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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;
import javax.annotation.Nullable;

/**
* Represents the current state of the computer environment.
Expand All @@ -31,11 +32,11 @@
*/
public final class ComputerState {
private final byte[] screenshot;
private final Optional<String> url;
private final @Nullable String url;

@JsonCreator
private ComputerState(
@JsonProperty("screenshot") byte[] screenshot, @JsonProperty("url") Optional<String> url) {
@JsonProperty("screenshot") byte[] screenshot, @JsonProperty("url") @Nullable String url) {
this.screenshot = screenshot.clone();
this.url = url;
}
Expand All @@ -47,7 +48,7 @@ public byte[] screenshot() {

@JsonProperty("url")
public Optional<String> url() {
return url;
return Optional.ofNullable(url);
}

public static Builder builder() {
Expand All @@ -57,7 +58,7 @@ public static Builder builder() {
/** Builder for {@link ComputerState}. */
public static final class Builder {
private byte[] screenshot;
private Optional<String> url = Optional.empty();
private @Nullable String url;

@CanIgnoreReturnValue
public Builder screenshot(byte[] screenshot) {
Expand All @@ -66,17 +67,11 @@ public Builder screenshot(byte[] screenshot) {
}

@CanIgnoreReturnValue
public Builder url(Optional<String> url) {
public Builder url(@Nullable String url) {
this.url = url;
return this;
}

@CanIgnoreReturnValue
public Builder url(String url) {
this.url = Optional.ofNullable(url);
return this;
}

public ComputerState build() {
return new ComputerState(screenshot, url);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.lang.reflect.Method;
import java.util.Base64;
import java.util.Map;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -128,10 +127,7 @@ public void testNormalizeDragAndDrop() throws NoSuchMethodException {
public void testResultFormatting() throws NoSuchMethodException {
byte[] screenshot = new byte[] {1, 2, 3};
computerMock.nextState =
ComputerState.builder()
.screenshot(screenshot)
.url(Optional.of("https://example.com"))
.build();
ComputerState.builder().screenshot(screenshot).url("https://example.com").build();

Method method = ComputerMock.class.getMethod("clickAt", int.class, int.class);
ComputerUseTool tool =
Expand Down Expand Up @@ -226,8 +222,7 @@ public static class ComputerMock {
public int lastY;
public int lastDestX;
public int lastDestY;
public ComputerState nextState =
ComputerState.builder().screenshot(new byte[0]).url(Optional.empty()).build();
public ComputerState nextState = ComputerState.builder().screenshot(new byte[0]).build();

public Single<ComputerState> clickAt(@Schema(name = "x") int x, @Schema(name = "y") int y) {
this.lastX = x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,87 +173,73 @@ public Single<ComputerEnvironment> environment() {

@Override
public Single<ComputerState> openWebBrowser() {
return Single.just(
ComputerState.builder().screenshot(new byte[0]).url(Optional.empty()).build());
return Single.just(ComputerState.builder().screenshot(new byte[0]).build());
}

@Override
public Single<ComputerState> clickAt(int x, int y) {
return Single.just(
ComputerState.builder().screenshot(new byte[0]).url(Optional.empty()).build());
return Single.just(ComputerState.builder().screenshot(new byte[0]).build());
}

@Override
public Single<ComputerState> hoverAt(int x, int y) {
return Single.just(
ComputerState.builder().screenshot(new byte[0]).url(Optional.empty()).build());
return Single.just(ComputerState.builder().screenshot(new byte[0]).build());
}

@Override
public Single<ComputerState> typeTextAt(
int x, int y, String text, Boolean pressEnter, Boolean clearBeforeTyping) {
return Single.just(
ComputerState.builder().screenshot(new byte[0]).url(Optional.empty()).build());
return Single.just(ComputerState.builder().screenshot(new byte[0]).build());
}

@Override
public Single<ComputerState> scrollDocument(String direction) {
return Single.just(
ComputerState.builder().screenshot(new byte[0]).url(Optional.empty()).build());
return Single.just(ComputerState.builder().screenshot(new byte[0]).build());
}

@Override
public Single<ComputerState> scrollAt(int x, int y, String direction, int magnitude) {
return Single.just(
ComputerState.builder().screenshot(new byte[0]).url(Optional.empty()).build());
return Single.just(ComputerState.builder().screenshot(new byte[0]).build());
}

@Override
public Single<ComputerState> wait(Duration duration) {
return Single.just(
ComputerState.builder().screenshot(new byte[0]).url(Optional.empty()).build());
return Single.just(ComputerState.builder().screenshot(new byte[0]).build());
}

@Override
public Single<ComputerState> goBack() {
return Single.just(
ComputerState.builder().screenshot(new byte[0]).url(Optional.empty()).build());
return Single.just(ComputerState.builder().screenshot(new byte[0]).build());
}

@Override
public Single<ComputerState> goForward() {
return Single.just(
ComputerState.builder().screenshot(new byte[0]).url(Optional.empty()).build());
return Single.just(ComputerState.builder().screenshot(new byte[0]).build());
}

@Override
public Single<ComputerState> search() {
return Single.just(
ComputerState.builder().screenshot(new byte[0]).url(Optional.empty()).build());
return Single.just(ComputerState.builder().screenshot(new byte[0]).build());
}

@Override
public Single<ComputerState> navigate(String url) {
return Single.just(
ComputerState.builder().screenshot(new byte[0]).url(Optional.of(url)).build());
return Single.just(ComputerState.builder().screenshot(new byte[0]).url(url).build());
}

@Override
public Single<ComputerState> keyCombination(List<String> keys) {
return Single.just(
ComputerState.builder().screenshot(new byte[0]).url(Optional.empty()).build());
return Single.just(ComputerState.builder().screenshot(new byte[0]).build());
}

@Override
public Single<ComputerState> dragAndDrop(int x, int y, int destinationX, int destinationY) {
return Single.just(
ComputerState.builder().screenshot(new byte[0]).url(Optional.empty()).build());
return Single.just(ComputerState.builder().screenshot(new byte[0]).build());
}

@Override
public Single<ComputerState> currentState() {
return Single.just(
ComputerState.builder().screenshot(new byte[0]).url(Optional.empty()).build());
return Single.just(ComputerState.builder().screenshot(new byte[0]).build());
}

@Override
Expand Down