Skip to content

Commit 1032cec

Browse files
committed
sync: cherry-pick changes from feature/3.0.x
1 parent cf20c1c commit 1032cec

154 files changed

Lines changed: 4598 additions & 380 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/io/github/easy4j/opencli/OpenCliClient.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,18 @@
2323
import lombok.Getter;
2424

2525
/**
26-
* OpenCLI Java SDK 入口:持有一组运行时配置与共享 {@link OpenCliExecutor}。
27-
*/
28-
public class OpenCliClient {
26+
* Entry point for the OpenCLI Java SDK. Holds a set of runtime configuration properties
27+
and a shared {@link OpenCliExecutor}.
28+
*
29+
* <p>Usage example:</p>
30+
* <pre>{@code
31+
* OpenCliClient client = new OpenCliClient();
32+
* OpenCliResult result = client.chatgpt().ask("hello", null, null);
33+
* }</pre>
34+
*
35+
* @author [@Loong Wan](https://github.com/loong10k)
36+
* @since 3.0.0
37+
*/public class OpenCliClient {
2938

3039
@Getter
3140
private final OpenCliProperties properties;
@@ -34,7 +43,7 @@ public class OpenCliClient {
3443
private final OpenCliExecutor executor;
3544

3645
/**
37-
* 使用默认配置构造(可执行文件假定名为 {@code opencli})。
46+
* Constructs with default configuration (executable assumed to be {@code opencli} on PATH).
3847
*/
3948
public OpenCliClient() {
4049
this(new OpenCliProperties());

src/main/java/io/github/easy4j/opencli/OpenCliExecutionTarget.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package io.github.easy4j.opencli;
22

33
/**
4-
* OpenCLI 命令实际执行位置:本机子进程或与 opencli-admin 兼容的远端 Agent HTTP API。
5-
*/
6-
public enum OpenCliExecutionTarget {
4+
* Determines where an OpenCLI command is executed: as a local subprocess or via a remote
5+
Agent HTTP API compatible with opencli-admin.
6+
*
7+
* @author [@Loong Wan](https://github.com/loong10k)
8+
* @since 3.0.0
9+
*/public enum OpenCliExecutionTarget {
710

811
/**
9-
* 在本机通过 {@link OpenCliProperties} 的 {@code executable} 配置启动子进程(默认)。
12+
* Launch a subprocess on the local machine using the {@code executable} configured in {@link OpenCliProperties} (default).
1013
*/
1114
LOCAL_PROCESS,
1215

src/main/java/io/github/easy4j/opencli/OpenCliProperties.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import lombok.Data;
88

99
/**
10-
* OpenCLI 运行时配置(纯 POJO,无 Spring 耦合)。
10+
* OpenCLI runtime configuration POJO with no Spring dependency.
1111
* <p>
1212
* 描述可执行文件、工作目录、超时、全局 argv 前缀、远端 Agent 以及需要注入子进程的环境变量
1313
*(例如 {@code OPENCLI_CDP_ENDPOINT})。Spring Boot 可由上层以
@@ -18,7 +18,26 @@
1818
* {@link OpenCliExecutionTarget#REMOTE_AGENT_HTTP} 模式下用作 HTTP 客户端超时上限。
1919
* </p>
2020
*/
21-
@Data
21+
@Data/**
22+
23+
* OpenCLI runtime configuration POJO with no Spring dependency.
24+
*
25+
* <p>Describes the executable path, working directory, timeout, global argv prefix,
26+
* remote Agent settings, and environment variables injected into the subprocess
27+
* (e.g.&nbsp;{@code OPENCLI_CDP_ENDPOINT}). Spring Boot applications can bind these
28+
* fields via {@code @ConfigurationProperties(prefix = "opencli")}.</p>
29+
*
30+
* <p>{@link #commandTimeoutMillis} is used as the subprocess watchdog timeout in local
31+
* mode and as the HTTP client timeout in {@link OpenCliExecutionTarget#REMOTE_AGENT_HTTP} mode.</p>
32+
33+
*
34+
35+
* @author [@Loong Wan](https://github.com/loong10k)
36+
37+
* @since 3.0.0
38+
39+
*/
40+
2241
public class OpenCliProperties {
2342

2443
/**

src/main/java/io/github/easy4j/opencli/adapter/browser/chatgpt/ChatgptOpenCliClient.java

Lines changed: 103 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,21 @@
1818
/**
1919
* OpenCLI {@code chatgpt}(ChatGPT Web)浏览器适配器。
2020
*/
21-
@RequiredArgsConstructor
21+
@RequiredArgsConstructor/**
22+
23+
* OpenCLI {@code chatgpt} (ChatGPT Web) browser adapter client.
24+
*
25+
* <p>Provides typed methods for ChatGPT Web interactions such as {@code ask}, {@code send},
26+
* {@code history}, {@code image}, and session management.</p>
27+
28+
*
29+
30+
* @author [@Loong Wan](https://github.com/loong10k)
31+
32+
* @since 3.0.0
33+
34+
*/
35+
2236
public final class ChatgptOpenCliClient {
2337

2438
private final OpenCliExecutor executor;
@@ -35,11 +49,22 @@ public static class ChatgptCommonOptions {
3549

3650
private Integer historyLimit;
3751

52+
private Integer stableSeconds;
53+
3854
private Boolean readAsMarkdown;
3955

40-
/** 文档:{@code --new} 开启新会话。 */
4156
private Boolean newConversation;
4257

58+
private String conversation;
59+
60+
private String project;
61+
62+
private Boolean waitForResponse;
63+
64+
private Boolean deepResearch;
65+
66+
private Boolean webSearch;
67+
4368
private Boolean jsonOutput;
4469

4570
public void appendTo(List<String> target) {
@@ -52,9 +77,27 @@ public void appendTo(List<String> target) {
5277
if (historyLimit != null) {
5378
OpenCliArgSupport.addOptionPair(target, "--limit", String.valueOf(historyLimit));
5479
}
80+
if (stableSeconds != null) {
81+
OpenCliArgSupport.addOptionPair(target, "--stable", String.valueOf(stableSeconds));
82+
}
5583
if (readAsMarkdown != null) {
5684
OpenCliArgSupport.addOptionPair(target, "--markdown", String.valueOf(readAsMarkdown));
5785
}
86+
if (conversation != null) {
87+
OpenCliArgSupport.addOptionPair(target, "--conversation", conversation);
88+
}
89+
if (project != null) {
90+
OpenCliArgSupport.addOptionPair(target, "--project", project);
91+
}
92+
if (waitForResponse != null) {
93+
OpenCliArgSupport.addOptionPair(target, "--wait", String.valueOf(waitForResponse));
94+
}
95+
if (Boolean.TRUE.equals(deepResearch)) {
96+
target.add("--deep-research");
97+
}
98+
if (Boolean.TRUE.equals(webSearch)) {
99+
target.add("--web-search");
100+
}
58101
if (Boolean.TRUE.equals(jsonOutput)) {
59102
target.add("-f");
60103
target.add("json");
@@ -118,6 +161,63 @@ public OpenCliResult status(List<String> more) {
118161
return ch().invoke(OpenCliArgSupport.merge(OpenCliLists.of("status"), more));
119162
}
120163

164+
public OpenCliResult deepResearchResult(String id, Boolean wait, Integer timeoutSeconds,
165+
Integer stableSeconds, List<String> more) {
166+
List<String> args = new ArrayList<>();
167+
args.add("deep-research-result");
168+
args.add(id);
169+
if (wait != null) {
170+
OpenCliArgSupport.addOptionPair(args, "--wait", String.valueOf(wait));
171+
}
172+
if (timeoutSeconds != null) {
173+
OpenCliArgSupport.addOptionPair(args, "--timeout", String.valueOf(timeoutSeconds));
174+
}
175+
if (stableSeconds != null) {
176+
OpenCliArgSupport.addOptionPair(args, "--stable", String.valueOf(stableSeconds));
177+
}
178+
return ch().invoke(OpenCliArgSupport.merge(args, more));
179+
}
180+
181+
public OpenCliResult login(Integer timeoutSeconds, List<String> more) {
182+
List<String> args = new ArrayList<>();
183+
args.add("login");
184+
if (timeoutSeconds != null) {
185+
OpenCliArgSupport.addOptionPair(args, "--timeout", String.valueOf(timeoutSeconds));
186+
}
187+
return ch().invoke(OpenCliArgSupport.merge(args, more));
188+
}
189+
190+
public OpenCliResult model(String model, String project, List<String> more) {
191+
List<String> args = new ArrayList<>();
192+
args.add("model");
193+
args.add(model);
194+
if (project != null) {
195+
OpenCliArgSupport.addOptionPair(args, "--project", project);
196+
}
197+
return ch().invoke(OpenCliArgSupport.merge(args, more));
198+
}
199+
200+
public OpenCliResult projectFileAdd(String file, String id, List<String> more) {
201+
List<String> args = new ArrayList<>();
202+
args.add("project-file-add");
203+
args.add(file);
204+
OpenCliArgSupport.addOptionPair(args, "--id", id);
205+
return ch().invoke(OpenCliArgSupport.merge(args, more));
206+
}
207+
208+
public OpenCliResult projectList(Integer limit, List<String> more) {
209+
List<String> args = new ArrayList<>();
210+
args.add("project-list");
211+
if (limit != null) {
212+
OpenCliArgSupport.addOptionPair(args, "--limit", String.valueOf(limit));
213+
}
214+
return ch().invoke(OpenCliArgSupport.merge(args, more));
215+
}
216+
217+
public OpenCliResult whoami(List<String> more) {
218+
return ch().invoke(OpenCliArgSupport.merge(OpenCliLists.of("whoami"), more));
219+
}
220+
121221
/**
122222
* {@code chatgpt image} 文生图参数。
123223
*/
@@ -144,7 +244,7 @@ public void appendTo(List<String> target) {
144244
OpenCliArgSupport.addOptionPair(target, "--op", outputDir);
145245
}
146246
if (Boolean.TRUE.equals(skipDownload)) {
147-
OpenCliArgSupport.addOptionPair(target, "--sd", "true");
247+
target.add("--sd");
148248
}
149249
if (timeoutSeconds != null) {
150250
OpenCliArgSupport.addOptionPair(target, "--timeout", String.valueOf(timeoutSeconds));

src/main/java/io/github/easy4j/opencli/adapter/browser/claude/ClaudeOpenCliClient.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,21 @@
1919
/**
2020
* OpenCLI {@code claude} 浏览器适配器。
2121
*/
22-
@RequiredArgsConstructor
22+
@RequiredArgsConstructor/**
23+
24+
* OpenCLI {@code claude} browser adapter client.
25+
*
26+
* <p>Provides typed methods for Claude Web interactions such as {@code ask}, {@code send},
27+
* {@code history}, {@code detail}, and session management.</p>
28+
29+
*
30+
31+
* @author [@Loong Wan](https://github.com/loong10k)
32+
33+
* @since 3.0.0
34+
35+
*/
36+
2337
public final class ClaudeOpenCliClient {
2438

2539
private final OpenCliExecutor executor;
@@ -98,6 +112,18 @@ public OpenCliResult send(String prompt, ClaudeAskOptions options, List<String>
98112
return ch().invoke(OpenCliArgSupport.merge(args, more));
99113
}
100114

115+
public OpenCliResult login(Integer timeoutSeconds, List<String> more) {
116+
List<String> args = new ArrayList<>();
117+
args.add("login");
118+
if (timeoutSeconds != null) {
119+
OpenCliArgSupport.addOptionPair(args, "--timeout", String.valueOf(timeoutSeconds));
120+
}
121+
return ch().invoke(OpenCliArgSupport.merge(args, more));
122+
}
123+
124+
public OpenCliResult whoami(List<String> more) {
125+
return ch().invoke(OpenCliArgSupport.merge(OpenCliLists.of("whoami"), more));
126+
}
101127
public OpenCliResult newChat(List<String> more) {
102128
return ch().invoke(OpenCliArgSupport.merge(OpenCliLists.of("new"), more));
103129
}

src/main/java/io/github/easy4j/opencli/adapter/browser/deepseek/DeepseekOpenCliClient.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,21 @@
1818
/**
1919
* OpenCLI {@code deepseek} 浏览器适配器。
2020
*/
21-
@RequiredArgsConstructor
21+
@RequiredArgsConstructor/**
22+
23+
* OpenCLI {@code deepseek} browser adapter client.
24+
*
25+
* <p>Provides typed methods for DeepSeek Web interactions such as {@code ask}, {@code send},
26+
* {@code history}, {@code detail}, and session management.</p>
27+
28+
*
29+
30+
* @author [@Loong Wan](https://github.com/loong10k)
31+
32+
* @since 3.0.0
33+
34+
*/
35+
2236
public final class DeepseekOpenCliClient {
2337

2438
private final OpenCliExecutor executor;
@@ -103,7 +117,20 @@ public OpenCliResult send(String conversationId, String prompt, DeepseekAskOptio
103117
return ch().invoke(OpenCliArgSupport.merge(args, more));
104118
}
105119

106-
/** {@code deepseek new}。 */
120+
public OpenCliResult login(Integer timeoutSeconds, List<String> more) {
121+
List<String> args = new ArrayList<>();
122+
args.add("login");
123+
if (timeoutSeconds != null) {
124+
OpenCliArgSupport.addOptionPair(args, "--timeout", String.valueOf(timeoutSeconds));
125+
}
126+
return ch().invoke(OpenCliArgSupport.merge(args, more));
127+
}
128+
129+
public OpenCliResult whoami(List<String> more) {
130+
return ch().invoke(OpenCliArgSupport.merge(OpenCliLists.of("whoami"), more));
131+
}
132+
133+
107134
public OpenCliResult newChat(List<String> more) {
108135
return ch().invoke(OpenCliArgSupport.merge(OpenCliLists.of("new"), more));
109136
}

0 commit comments

Comments
 (0)