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 @@ -102,6 +102,13 @@ JsonNode getSandbox(String sandboxId) throws IOException {
return AgentRunRetry.withRetries(opt.getMaxRetries(), () -> getJson(url));
}

private JsonNode unwrapData(JsonNode node) {
if (node != null && node.hasNonNull("data")) {
return node.get("data");
}
return node;
}

/**
* Deletes the sandbox. Returns silently on HTTP 404 (already gone). All other non-2xx
* responses raise.
Expand Down Expand Up @@ -195,7 +202,7 @@ private JsonNode postJson(String url, ObjectNode body) throws IOException {
if (text.isBlank()) {
return json.createObjectNode();
}
return json.readTree(text);
return unwrapData(json.readTree(text));
}
}

Expand All @@ -208,7 +215,7 @@ private JsonNode getJson(String url) throws IOException {
SandboxErrorCode.WORKSPACE_START_ERROR,
"AgentRun HTTP " + res.code() + " " + res.message() + ": " + text);
}
return json.readTree(text);
return unwrapData(json.readTree(text));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ void usesSandboxPathsWithoutVersionPrefix() throws Exception {

AgentRunDataPlaneHttp http = new AgentRunDataPlaneHttp(opt);

mockServer.enqueue(new MockResponse().setResponseCode(200).setBody("{\"id\":\"sb-1\"}"));
mockServer.enqueue(
new MockResponse().setResponseCode(200).setBody("{\"data\":{\"id\":\"sb-1\"}}"));
JsonNode created = http.createSandbox("sb-1");
assertNotNull(created);
assertEquals("sb-1", created.get("id").asText());
Expand All @@ -76,7 +77,9 @@ void usesSandboxPathsWithoutVersionPrefix() throws Exception {
assertTrue(createReq.getBody().readUtf8().contains("\"sandboxId\":\"sb-1\""));

mockServer.enqueue(
new MockResponse().setResponseCode(200).setBody("{\"status\":\"READY\"}"));
new MockResponse()
.setResponseCode(200)
.setBody("{\"data\":{\"status\":\"READY\"}}"));
JsonNode fetched = http.getSandbox("sb-1");
assertNotNull(fetched);
assertEquals("READY", fetched.get("status").asText());
Expand All @@ -92,4 +95,33 @@ void usesSandboxPathsWithoutVersionPrefix() throws Exception {
assertEquals("DELETE", deleteReq.getMethod());
assertEquals("/sandboxes/sb-1", deleteReq.getPath());
}

@Test
void acceptsResponsesWithoutDataEnvelope() throws Exception {
String baseUrl = mockServer.url("/").toString();
if (baseUrl.endsWith("/")) {
baseUrl = baseUrl.substring(0, baseUrl.length() - 1);
}

AgentRunSandboxClientOptions opt =
new AgentRunSandboxClientOptions()
.setApiKey("test-key")
.setTemplateName("agentscope-default")
.setMcpServerUrl("https://example.com/mcp")
.setDataPlaneBaseUrl(baseUrl)
.setHttpClient(new OkHttpClient());

AgentRunDataPlaneHttp http = new AgentRunDataPlaneHttp(opt);

mockServer.enqueue(new MockResponse().setResponseCode(200).setBody("{\"id\":\"sb-2\"}"));
JsonNode created = http.createSandbox("sb-2");
assertNotNull(created);
assertEquals("sb-2", created.get("id").asText());

mockServer.enqueue(
new MockResponse().setResponseCode(200).setBody("{\"status\":\"RUNNING\"}"));
JsonNode fetched = http.getSandbox("sb-2");
assertNotNull(fetched);
assertEquals("RUNNING", fetched.get("status").asText());
}
}
Loading