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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ vendor/
.idea/

# Python
.ruff_cache/
.ruff_cache/

.vscode/
12 changes: 6 additions & 6 deletions docs/java-sdk-publish-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ gpg --keyserver hkps://keyserver.ubuntu.com --send-keys <KEY-ID>
## 注意事项

- **Namespace 与 GroupId 一致**:Sonatype Central 账号拥有的 Namespace 必须与 `pom.xml` 中的 `groupId` 一致(如
`io.github.openkruise`),否则发布会被拒绝
`io.openkruise`),否则发布会被拒绝
- **GPG Email 与 Developer Email 一致**:GPG 密钥的 Email 必须与 `pom.xml` 中 `<developers>` 的 `<email>` 一致,否则签名验证会失败
- **私钥安全**:`GPG_PRIVATE_KEY` 是敏感信息,务必仅存储在 GitHub Secrets 中,不要提交到代码仓库
- **Passphrase 保管**:`GPG_PASSPHRASE` 丢失后无法恢复,建议妥善保存
Expand All @@ -122,14 +122,14 @@ gpg --keyserver hkps://keyserver.ubuntu.com --send-keys <KEY-ID>
```xml

<dependency>
<groupId>io.github.zhaoqing7892</groupId>
<groupId>io.openkruise</groupId>
<artifactId>agents-client-java</artifactId>
<version>最新版本</version>
</dependency>
```

**Maven Central
**: [https://central.sonatype.com/artifact/io.github.zhaoqing7892/agents-client-java](https://central.sonatype.com/artifact/io.github.zhaoqing7892/agents-client-java)
**: [https://central.sonatype.com/artifact/io.openkruise/agents-client-java](https://central.sonatype.com/artifact/io.openkruise/agents-client-java)

### 最新版本

Expand All @@ -142,8 +142,8 @@ gpg --keyserver hkps://keyserver.ubuntu.com --send-keys <KEY-ID>
### Maven Central 链接

- **agents-client-e2b
**: [https://central.sonatype.com/artifact/io.github.zhaoqing7892/agents-client-e2b](https://central.sonatype.com/artifact/io.github.zhaoqing7892/agents-client-e2b)
**: [https://central.sonatype.com/artifact/io.openkruise/agents-client-e2b](https://central.sonatype.com/artifact/io.openkruise/agents-client-e2b)
- **agents-client-runtime
**: [https://central.sonatype.com/artifact/io.github.zhaoqing7892/agents-client-runtime](https://central.sonatype.com/artifact/io.github.zhaoqing7892/agents-client-runtime)
**: [https://central.sonatype.com/artifact/io.openkruise/agents-client-runtime](https://central.sonatype.com/artifact/io.openkruise/agents-client-runtime)
- **agents-client-k8s
**: [https://central.sonatype.com/artifact/io.github.zhaoqing7892/agents-client-k8s](https://central.sonatype.com/artifact/io.github.zhaoqing7892/agents-client-k8s)
**: [https://central.sonatype.com/artifact/io.openkruise/agents-client-k8s](https://central.sonatype.com/artifact/io.openkruise/agents-client-k8s)
12 changes: 6 additions & 6 deletions docs/java-sdk-publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ status (may take a few minutes to several hours to sync).
## Important Notes

- **Namespace must match GroupId**: The Namespace owned by your Sonatype Central account must match the `groupId` in
`pom.xml` (e.g., `io.github.openkruise`), otherwise publishing will be rejected
`pom.xml` (e.g., `io.openkruise`), otherwise publishing will be rejected
- **GPG Email must match Developer Email**: The Email in the GPG key must match the `<email>` in `<developers>` section
of `pom.xml`, otherwise signature verification will fail
- **Private Key Security**: `GPG_PRIVATE_KEY` is sensitive information — store it only in GitHub Secrets, never commit
Expand All @@ -131,14 +131,14 @@ status (may take a few minutes to several hours to sync).
```xml

<dependency>
<groupId>io.github.zhaoqing7892</groupId>
<groupId>io.openkruise</groupId>
<artifactId>agents-client-java</artifactId>
<version>latest-version</version>
</dependency>
```

**Maven Central
**: [https://central.sonatype.com/artifact/io.github.zhaoqing7892/agents-client-java](https://central.sonatype.com/artifact/io.github.zhaoqing7892/agents-client-java)
**: [https://central.sonatype.com/artifact/io.openkruise/agents-client-java](https://central.sonatype.com/artifact/io.openkruise/agents-client-java)

### Latest Version

Expand All @@ -151,8 +151,8 @@ status (may take a few minutes to several hours to sync).
### Maven Central Links

- **agents-client-e2b
**: [https://central.sonatype.com/artifact/io.github.zhaoqing7892/agents-client-e2b](https://central.sonatype.com/artifact/io.github.zhaoqing7892/agents-client-e2b)
**: [https://central.sonatype.com/artifact/io.openkruise/agents-client-e2b](https://central.sonatype.com/artifact/io.openkruise/agents-client-e2b)
- **agents-client-runtime
**: [https://central.sonatype.com/artifact/io.github.zhaoqing7892/agents-client-runtime](https://central.sonatype.com/artifact/io.github.zhaoqing7892/agents-client-runtime)
**: [https://central.sonatype.com/artifact/io.openkruise/agents-client-runtime](https://central.sonatype.com/artifact/io.openkruise/agents-client-runtime)
- **agents-client-k8s
**: [https://central.sonatype.com/artifact/io.github.zhaoqing7892/agents-client-k8s](https://central.sonatype.com/artifact/io.github.zhaoqing7892/agents-client-k8s)
**: [https://central.sonatype.com/artifact/io.openkruise/agents-client-k8s](https://central.sonatype.com/artifact/io.openkruise/agents-client-k8s)
6 changes: 6 additions & 0 deletions e2b/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ the HTTP `/files` endpoint.
| `Remove(ctx, path) error` | Delete file or directory |
| `Read(ctx, path, user...) ([]byte, error)` | Read file content (binary); `user` defaults to `"node"` |
| `ReadText(ctx, path, user...) (string, error)` | Read file content (text) |
| `ReadStream(ctx, path, user...) (io.ReadCloser, error)` | Stream file content; caller must Close |
| `Write(ctx, path, data []byte, user...) (*WriteInfo, error)` | Write file content (binary); auto-creates parent dirs |
| `WriteText(ctx, path, content string, user...) (*WriteInfo, error)` | Write file content (text) |

Expand All @@ -377,4 +378,9 @@ sb.Files.Remove(ctx, "/tmp/done")
sb.Files.WriteText(ctx, "/tmp/hello.txt", "Hello, World!")
content, _ := sb.Files.ReadText(ctx, "/tmp/hello.txt")
fmt.Println(content) // Hello, World!

// Stream large files (caller must Close)
rc, _ := sb.Files.ReadStream(ctx, "/tmp/large.log")
defer rc.Close()
io.Copy(os.Stdout, rc)
```
6 changes: 6 additions & 0 deletions e2b/README_zh-CH.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ h.Kill()
| `Remove(ctx, path) error` | 删除文件或目录 |
| `Read(ctx, path, user...) ([]byte, error)` | 读取文件内容(二进制);`user` 默认 `"node"` |
| `ReadText(ctx, path, user...) (string, error)` | 读取文件内容(文本) |
| `ReadStream(ctx, path, user...) (io.ReadCloser, error)` | 流式读取文件;调用方需关闭 |
| `Write(ctx, path, data []byte, user...) (*WriteInfo, error)` | 写入文件内容(二进制);自动创建父目录 |
| `WriteText(ctx, path, content string, user...) (*WriteInfo, error)` | 写入文件内容(文本) |

Expand All @@ -371,4 +372,9 @@ sb.Files.Remove(ctx, "/tmp/done")
sb.Files.WriteText(ctx, "/tmp/hello.txt", "Hello, World!")
content, _ := sb.Files.ReadText(ctx, "/tmp/hello.txt")
fmt.Println(content) // Hello, World!

// 流式读取大文件(需关闭)
rc, _ := sb.Files.ReadStream(ctx, "/tmp/large.log")
defer rc.Close()
io.Copy(os.Stdout, rc)
```
4 changes: 3 additions & 1 deletion e2b/java/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ target
build

.idea/
*.iml
*.iml

build-e2b.ps1
2 changes: 1 addition & 1 deletion e2b/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ operations) APIs.
```xml

<dependency>
<groupId>io.github.openkruise</groupId>
<groupId>io.openkruise</groupId>
<artifactId>agents-client-e2b</artifactId>
<version>0.1.0</version>
</dependency>
Expand Down
4 changes: 2 additions & 2 deletions e2b/java/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.openkruise</groupId>
<groupId>io.openkruise</groupId>
<artifactId>agents-client-e2b</artifactId>
<packaging>jar</packaging>
<version>0.1.0</version>
Expand Down Expand Up @@ -30,7 +30,7 @@
<developers>
<developer>
<name>zmberg</name>
<email>13611129507@163.com</email>
<email>furykerry@gmail.com</email>
<organization>agents-api</organization>
<organizationUrl>https://github.com/openkruise/agents-api</organizationUrl>
</developer>
Expand Down
14 changes: 14 additions & 0 deletions e2b/java/src/main/java/io/openkruise/agents/client/e2b/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ read/write uses the HTTP `/files` endpoint.
| `read(String path, String user)` | Read file content (as specified user) |
| `readText(String path)` | Read file content (`String`, UTF-8) |
| `readText(String path, String user)` | Read file content (as specified user, UTF-8) |
| `readStream(String path)` | Stream file content (`InputStream`, must close) |
| `readStream(String path, String user)` | Stream file content (as specified user, must close) |
| `readTextStream(String path)` | Stream file text (`BufferedReader`, UTF-8, must close) |
| `readTextStream(String path, String user)` | Stream file text (as specified user, must close) |
| `write(String path, byte[] data)` | Write file (binary), returns `WriteInfo` |
| `write(String path, byte[] data, String user)` | Write file (as specified user), returns `WriteInfo` |
| `writeText(String path, String content)` | Write file (text, UTF-8), returns `WriteInfo` |
Expand Down Expand Up @@ -259,6 +263,16 @@ sandbox.files.makeDir("/tmp/work");
WriteInfo info=sandbox.files.write("/tmp/data.bin",new byte[]{0x01,0x02});
byte[]data=sandbox.files.read("/tmp/data.bin");

// Stream large files (remember to close)
try (InputStream in = sandbox.files.readStream("/tmp/large.log")) {
byte[] buffer = new byte[4096];
while (in.read(buffer) != -1) { /* process */ }
}
try (BufferedReader reader = sandbox.files.readTextStream("/tmp/large.log")) {
String line;
while ((line = reader.readLine()) != null) { /* process */ }
}

// Directory watch
WatchHandle wh=sandbox.files.watchDir("/tmp",true,event->
System.out.printf("Event: %s %s%n",event.getType(),event.getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ CommandResult res=sandbox.commands.run("pwd");
| `read(String path, String user)` | 读取文件内容(指定用户) |
| `readText(String path)` | 读取文件内容(`String`,UTF-8) |
| `readText(String path, String user)` | 读取文件内容(指定用户,UTF-8) |
| `readStream(String path)` | 流式读取文件(`InputStream`,需关闭) |
| `readStream(String path, String user)` | 流式读取文件(指定用户,需关闭) |
| `readTextStream(String path)` | 流式读取文本(`BufferedReader`,UTF-8,需关闭) |
| `readTextStream(String path, String user)` | 流式读取文本(指定用户,需关闭) |
| `write(String path, byte[] data)` | 写入文件(二进制),返回 `WriteInfo` |
| `write(String path, byte[] data, String user)` | 写入文件(指定用户),返回 `WriteInfo` |
| `writeText(String path, String content)` | 写入文件(文本,UTF-8),返回 `WriteInfo` |
Expand Down Expand Up @@ -255,6 +259,16 @@ sandbox.files.makeDir("/tmp/work");
WriteInfo info=sandbox.files.write("/tmp/data.bin",new byte[]{0x01,0x02});
byte[]data=sandbox.files.read("/tmp/data.bin");

// 流式读取大文件(记得关闭)
try (InputStream in = sandbox.files.readStream("/tmp/large.log")) {
byte[] buffer = new byte[4096];
while (in.read(buffer) != -1) { /* 处理 */ }
}
try (BufferedReader reader = sandbox.files.readTextStream("/tmp/large.log")) {
String line;
while ((line = reader.readLine()) != null) { /* 处理 */ }
}

// 目录监听
WatchHandle wh=sandbox.files.watchDir("/tmp",true,event->
System.out.printf("Event: %s %s%n",event.getType(),event.getName()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package io.openkruise.agents.client.examples;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;

import io.openkruise.agents.client.e2b.ConnectionConfig;
Expand Down Expand Up @@ -148,8 +152,61 @@ private static void demonstrateFileOperations(Filesystem files) {
System.err.println(" Read failed: " + e.getMessage());
}

// [10] Overwrite existing file
System.out.printf("%n[10] Overwrite: %s%n", testFile);
// [10] Write large text file for streaming read test
String largeFile = testDir + "/large.log";
System.out.printf("%n[10] Write large text file: %s%n", largeFile);
int expectedLines = 100;
try {
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= expectedLines; i++) {
sb.append(String.format("Line %04d: This is a test line for streaming read verification.%n", i));
}
WriteInfo writeInfo = files.writeText(largeFile, sb.toString());
System.out.printf(" Write succeeded, path: %s, lines: %d, size: %d bytes%n",
writeInfo.getPath(), expectedLines, sb.length());
} catch (Exception e) {
System.err.println(" Write failed: " + e.getMessage());
}

// [11] Read large file via stream, line by line (readTextStream)
System.out.printf("%n[11] Read large file via stream: %s%n", largeFile);
try (BufferedReader reader = files.readTextStream(largeFile)) {
StringBuilder sb = new StringBuilder();
String line;
int lineNum = 0;
while ((line = reader.readLine()) != null) {
lineNum++;
if (sb.length() > 0) {
sb.append("\n");
}
sb.append(line);
}
System.out.printf(" Total lines: %d%n", lineNum);
System.out.printf(" File content:%n%s%n", sb);
} catch (Exception e) {
System.err.println(" Text stream read failed: " + e.getMessage());
}

// [12] Read large file via stream, chunk by chunk (readStream)
System.out.printf("%n[12] Read large file via stream: %s%n", largeFile);
try (InputStream stream = files.readStream(largeFile)) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
int chunks = 0;
int n;
while ((n = stream.read(buffer)) != -1) {
baos.write(buffer, 0, n);
chunks++;
}
String content = new String(baos.toByteArray(), StandardCharsets.UTF_8);
System.out.printf(" Streamed %d bytes in %d chunks (buffer=4096)%n", baos.size(), chunks);
System.out.printf(" File content:%n%s%n", content);
} catch (Exception e) {
System.err.println(" Stream read failed: " + e.getMessage());
}

// [13] Overwrite existing file
System.out.printf("%n[13] Overwrite: %s%n", testFile);
try {
files.writeText(testFile, "Overwritten content\n");
String newContent = files.readText(testFile);
Expand All @@ -158,21 +215,21 @@ private static void demonstrateFileOperations(Filesystem files) {
System.err.println(" Overwrite failed: " + e.getMessage());
}

// [11] List directory (verify files created)
System.out.printf("%n[11] List directory contents: %s%n", testDir);
// [14] List directory (verify files created)
System.out.printf("%n[14] List directory contents: %s%n", testDir);
listEntries(files, testDir);

// [12] Delete directory
System.out.printf("%n[12] Delete directory: %s%n", testDir);
// [15] Delete directory
System.out.printf("%n[15] Delete directory: %s%n", testDir);
try {
files.remove(testDir);
System.out.println(" Directory deleted");
} catch (Exception e) {
System.err.println(" Delete failed: " + e.getMessage());
}

// [13] Verify deletion
System.out.printf("%n[13] Verify deletion: %s%n", testDir);
// [16] Verify deletion
System.out.printf("%n[16] Verify deletion: %s%n", testDir);
try {
boolean exists = files.exists(testDir);
System.out.printf(" Exists after deletion: %s%n", exists);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ read/write uses the HTTP `/files` endpoint.
| `read(String path, String user)` | Read file content (as specified user) |
| `readText(String path)` | Read file content (`String`, UTF-8) |
| `readText(String path, String user)` | Read file content (as specified user, UTF-8) |
| `readStream(String path)` | Stream file content (`InputStream`, must close) |
| `readStream(String path, String user)` | Stream file content (as specified user, must close) |
| `readTextStream(String path)` | Stream file text (`BufferedReader`, UTF-8, must close) |
| `readTextStream(String path, String user)` | Stream file text (as specified user, must close) |
| `write(String path, byte[] data)` | Write file (binary), returns `WriteInfo` |
| `write(String path, byte[] data, String user)` | Write file (as specified user), returns `WriteInfo` |
| `writeText(String path, String content)` | Write file (text, UTF-8), returns `WriteInfo` |
Expand Down Expand Up @@ -324,6 +328,16 @@ String content = client.files.readText("/tmp/hello.txt");
WriteInfo info = client.files.write("/tmp/data.bin", new byte[]{0x01, 0x02});
byte[] data = client.files.read("/tmp/data.bin");

// Stream large files (remember to close)
try (InputStream in = client.files.readStream("/tmp/large.log")) {
byte[] buffer = new byte[4096];
while (in.read(buffer) != -1) { /* process */ }
}
try (BufferedReader reader = client.files.readTextStream("/tmp/large.log")) {
String line;
while ((line = reader.readLine()) != null) { /* process */ }
}

// Directory watch
WatchHandle wh = client.files.watchDir("/tmp", true, event ->
System.out.printf("Event: %s %s%n", event.getType(), event.getName()));
Expand Down
Loading
Loading