Skip to content

Commit 5b36ceb

Browse files
committed
docs(java): explain supported workflows and planned Managed APIs
1 parent 1404bd1 commit 5b36ceb

3 files changed

Lines changed: 209 additions & 24 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ First stable release of the Java SDK for the Forward API, using `com.qoder.sdk:q
1212
- Shared PAT, static SAT and custom credentials, plus `ServiceAccountCredential` for automatic SA Key exchange, SAT caching and refresh. Forward administrator/Identity SAT issuance and revocation use explicit per-call SA Keys.
1313
- Typed Forward resource APIs for Models, Templates, Identities and configuration, Sessions and Threads, Memory Stores, Environments, Files, Skills, Vaults and Credentials, Schedules, Batches, Channels and Pairing, Usage and Drive.
1414
- Session/Thread SSE subscriptions with cancellation and explicit resumption; Realtime conversations with text/PCM audio, typed events, acknowledged close and History.
15-
- Shared request options, timeouts, retries, pagination, response metadata and typed errors, with resource-lifecycle examples and API guides. Managed APIs are outside this release's scope.
15+
- Shared request options, timeouts, retries, pagination, response metadata and typed errors, with resource-lifecycle examples and API guides. Managed API support is planned for a future release and is not included in 0.1.0.
1616

1717
### Changed
1818

‎README.md‎

Lines changed: 205 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,34 @@
11
# Qoder Cloud Agents Java SDK
22

3-
Java 8+ SDK for the **Forward API**, with typed synchronous and asynchronous clients. Supports PAT/SA authentication, pagination, retries, Session/Thread SSE and Realtime text/audio. Managed APIs are outside this SDK's scope.
4-
53
[Changelog](CHANGELOG.md) · [Releases](https://github.com/QoderAI/qoder-cloud-agents-sdk-java/releases) · [Maven Central](https://central.sonatype.com/artifact/com.qoder.sdk/qoder-cloud-agents-sdk)
64

5+
The Qoder Cloud Agents Java SDK provides typed synchronous and asynchronous clients, with shared authentication, timeouts, retries, pagination, streaming and error handling.
6+
7+
Version **0.1.0** supports the **Forward API**. **Managed API support is planned for a future release** and is not available in this version.
8+
9+
| Capability | Resources |
10+
| --- | --- |
11+
| Agent configuration | Template, Identity and per-Identity configuration |
12+
| Conversations | Session, Thread, event history and SSE subscriptions |
13+
| Execution | Schedule, Schedule Run, Batch and Batch Task |
14+
| Resources | Environment, File, Skill, Vault, Memory Store and Drive |
15+
| Channels | Channel configuration, Pairing creation/deletion and QR authorization |
16+
| Authentication and usage | PAT, Service Account credentials, Forward SAT issuance/revocation, Model and Usage |
17+
| Realtime (Beta) | Text/audio WebSocket conversations and persisted History |
18+
19+
See [API coverage and resource guides](docs/forward-api-coverage.md) for the supported operations.
20+
21+
- [Installation](#installation)
22+
- [Quick start](#quick-start)
23+
- [PAT and Service Account authentication](#pat-and-service-account-authentication)
24+
- [Conversations and streaming](#conversations-and-streaming)
25+
- [Asynchronous calls and cancellation](#asynchronous-calls-and-cancellation)
26+
- [Pagination](#pagination)
27+
- [Timeouts, retries and errors](#timeouts-retries-and-errors)
28+
- [Realtime](#realtime)
29+
- [Examples and documentation](#examples-and-documentation)
30+
- [Development](#development)
31+
732
## Installation
833

934
Add the Maven dependency; published versions require no local SDK build or additional repository configuration.
@@ -16,27 +41,56 @@ Add the Maven dependency; published versions require no local SDK build or addit
1641
</dependency>
1742
```
1843

19-
Compatible with Java 8, 11, 17, 21 and 25. See the [changelog](CHANGELOG.md) for upgrading from the RC or earlier internal coordinates.
44+
Requirements:
2045

21-
## Quick start with PAT
46+
- Java **8** or later; CI covers Java **8, 11, 17, 21 and 25**.
47+
- A PAT or Service Account credential for the target region, with access to the resources you call.
2248

23-
Set `QODER_PAT`, then create a client:
49+
## Quick start
50+
51+
Set `QODER_PAT` in your environment. This complete program connects to Global and lists the enabled models:
2452

2553
```java
2654
import com.qoder.cloudagents.ForwardClient;
27-
28-
try (ForwardClient client = ForwardClient.builder()
29-
.pat(System.getenv("QODER_PAT"))
30-
.build()) {
31-
System.out.println(client.models().list().data().size());
55+
import com.qoder.cloudagents.forward.Model;
56+
57+
public class QuickStart {
58+
public static void main(String[] args) {
59+
try (ForwardClient client = ForwardClient.builder()
60+
.pat(System.getenv("QODER_PAT"))
61+
.build()) {
62+
for (Model model : client.models().list().data()) {
63+
if (model.isEnabled()) {
64+
System.out.println(model.id());
65+
}
66+
}
67+
}
68+
}
3269
}
3370
```
3471

35-
The default endpoint is Global: `https://api.qoder.com/api/v1/forward`. For CN, add `.baseUrl("https://api.qoder.com.cn/api/v1/forward")` to the client builder.
72+
| Region | Forward BaseURL |
73+
| --- | --- |
74+
| Global (default) | `https://api.qoder.com/api/v1/forward` |
75+
| CN | `https://api.qoder.com.cn/api/v1/forward` |
76+
77+
For CN, add `.baseUrl("https://api.qoder.com.cn/api/v1/forward")` to the builder. If omitted, the SDK reads `QODER_FORWARD_BASE_URL`, then uses Global. BaseURLs include the full API root path.
78+
79+
Clients are thread-safe and can be reused. Close the owning client when your application finishes using it. The following snippets assume an open `client`; replace resource IDs with IDs accessible to your credential.
3680

37-
## Service Account
81+
## PAT and Service Account authentication
3882

39-
Set `QODER_SA_KEY` and explicitly configure a credential:
83+
PAT and SA are parallel authentication modes:
84+
85+
| Mode | Configuration | Token renewal |
86+
| --- | --- | --- |
87+
| PAT | `.pat(token)` | Managed by your application |
88+
| SA Key | `.credential(ServiceAccountCredential)` | SDK exchanges, caches and refreshes the SAT on demand |
89+
| Existing SAT | `.authMode(AuthMode.SA).accessToken(token)` | Managed by your application |
90+
91+
With no explicit credentials, PAT mode reads `QODER_ACCESS_TOKEN`, then `QODER_PAT`. An explicit token or credential takes precedence over environment tokens; configure only one explicit source. The SDK does not load `.env` files or enable SA merely because `QODER_SA_KEY` is set.
92+
93+
To use automatic SA exchange, set `QODER_SA_KEY` and configure a credential:
4094

4195
```java
4296
import com.qoder.cloudagents.ForwardClient;
@@ -53,14 +107,144 @@ try (ServiceAccountCredential credential = ServiceAccountCredential.builder()
53107
}
54108
```
55109

56-
The credential exchanges the SA Key for a SAT, then caches and refreshes it. For CN, use both `Region.CN` and the CN BaseURL. See [client configuration](docs/client-configuration.md) for static SATs, authentication precedence, timeouts, retries and cancellation.
110+
Business requests use the SAT; the SA Key is sent only to the exchange service. For CN, use both `Region.CN` and the CN BaseURL. Keep a shared credential open until all clients using it are closed. Failed SA authentication does not fall back to PAT.
111+
112+
Forward also provides explicit administrator/Identity SAT issuance and revocation through `serviceAccountTokens()` and `identities().serviceAccountTokens()`. These methods take a per-call SA Key and do not retry automatically. See [SAT management](docs/usage-sat-drive.md) and [authentication configuration](docs/client-configuration.md).
113+
114+
## Conversations and streaming
115+
116+
Create a Session using an existing Identity and Template, send a user message, and consume events through SSE:
117+
118+
```java
119+
import com.qoder.cloudagents.core.RequestOptions;
120+
import com.qoder.cloudagents.forward.*;
121+
import com.qoder.cloudagents.streaming.EventStream;
122+
import java.time.Duration;
123+
import java.util.Collections;
124+
import java.util.UUID;
125+
126+
Session session = client.sessions().create(
127+
SessionCreateParams.builder()
128+
.identityId("idn_example")
129+
.templateId("tmpl_example")
130+
.title("SDK quick start")
131+
.build(),
132+
RequestOptions.builder().idempotencyKey(UUID.randomUUID().toString()).build());
133+
134+
SessionEventSendResponse sent = client.sessions().events().send(session.id(),
135+
SessionEventSendParams.builder().events(Collections.singletonList(
136+
SessionEventParam.builder()
137+
.type("user.message")
138+
.content(EventContent.text("Hello!"))
139+
.build())).build(),
140+
RequestOptions.builder().idempotencyKey(UUID.randomUUID().toString()).build());
141+
142+
// Start after the accepted input, excluding events from earlier turns.
143+
String inputEventId = sent.data().get(0).id();
144+
try (EventStream<SessionEvent> stream = client.sessions().events().streamEvents(
145+
session.id(), SessionEventStreamParams.builder().lastEventId(inputEventId).build(),
146+
RequestOptions.builder().totalTimeout(Duration.ofMinutes(5)).build())) {
147+
for (SessionEvent event : stream) {
148+
System.out.println(event.type());
149+
// Inspect event.content() for message blocks.
150+
if ("session.error".equals(event.type()) || "session.status_terminated".equals(event.type())) {
151+
throw new IllegalStateException("Session stopped: " + event.type());
152+
}
153+
if ("session.status_idle".equals(event.type())) break;
154+
}
155+
}
156+
```
157+
158+
Reuse an idempotency key when retrying the same logical write. A successful send acknowledges input, not completed execution. An idle event can mean the turn finished or paused for input; inspect the event's stop reason in your application. The example bounds the subscription to five minutes; closing it does not cancel or archive the Session.
159+
160+
Thread subscriptions use `sessions().threads().events()`. For explicit reconnects with the last delivered SSE ID, use `resumableStream(...)`; user messages are not automatically resent. See [Session operations](docs/sessions.md), [streaming and cancellation](docs/session-streaming.md) and the [runnable streaming example](examples/src/main/java/com/qoder/cloudagents/examples/SessionStreamingExample.java).
161+
162+
## Asynchronous calls and cancellation
163+
164+
The async view shares the client's authentication and transport:
165+
166+
```java
167+
import com.qoder.cloudagents.forward.Template;
168+
import java.util.concurrent.CompletableFuture;
169+
170+
CompletableFuture<Template> pending = client.async().templates().retrieve("tmpl_example");
171+
pending.thenAccept(template -> System.out.println(template.id()));
172+
// When the result is no longer needed: pending.cancel(true);
173+
```
174+
175+
Keep the owning client open until requests complete. Cancel the SDK-returned future to stop its HTTP request and retry timer. `ForwardClient.builder().buildAsync()` creates an independently owned `AsyncForwardClient`. Cancelling a request locally does not invoke `sessions().cancel(...)` on the server. See [async ownership and cancellation](docs/client-configuration.md#asynchronous-calls-and-cancellation).
176+
177+
## Pagination
178+
179+
List responses support one-page access and lazy iteration:
180+
181+
```java
182+
import com.qoder.cloudagents.forward.TemplateListParams;
183+
import com.qoder.cloudagents.forward.TemplateListResponse;
184+
185+
TemplateListResponse page = client.templates().list(TemplateListParams.builder().limit(20).build());
186+
for (com.qoder.cloudagents.forward.Template template : page) {
187+
System.out.println(template.id()); // Fetches subsequent pages as needed.
188+
}
189+
```
190+
191+
Use `page.data()` for only the current page, or `hasNextPage()` and `getNextPage()` / `getNextPageAsync()` for manual pagination. Filters, request options and server order are preserved. Drive uses `entries` / `next_page_token`; Realtime History has its own `next_before` cursor. See the [resource guides](docs/forward-api-coverage.md#使用指南) for those APIs.
192+
193+
## Timeouts, retries and errors
194+
195+
Pass `RequestOptions` as the last argument to customize a request:
196+
197+
```java
198+
import com.qoder.cloudagents.core.RequestOptions;
199+
import com.qoder.cloudagents.errors.ApiStatusException;
200+
import java.time.Duration;
201+
202+
try {
203+
client.templates().retrieve("tmpl_example", RequestOptions.builder()
204+
.timeout(Duration.ofSeconds(30))
205+
.totalTimeout(Duration.ofSeconds(60))
206+
.maxRetries(1)
207+
.build());
208+
} catch (ApiStatusException error) {
209+
System.err.println("HTTP " + error.statusCode() + ", request ID: " + error.requestId());
210+
}
211+
```
212+
213+
- **Timeouts:** the connection timeout defaults to 5 seconds; response-header and read/write idle timeouts default to 10 minutes. `timeout` adjusts per-attempt header/idle limits; `totalTimeout` bounds the whole request, including credentials and retries. SSE has separate read-lifecycle rules.
214+
- **Retries:** at most 2 retries by default, subject to method safety, body replayability and server hints. HTTP 409 is never retried; non-idempotent writes only qualify for 429 retries. An idempotency key permits other eligible write retries.
215+
- **Errors:** `ApiException` is the request-error base type. HTTP failures expose status and request ID through `ApiStatusException`; connection, timeout, cancellation and response-validation failures have distinct types.
216+
- **Responses:** models expose `requestId()` and unknown JSON fields via `field(name)`. Use `withResponse()` for HTTP status and headers. Request builders distinguish omitted fields from explicit `null`.
217+
218+
See [client configuration](docs/client-configuration.md) for detailed defaults and [Template configuration](docs/templates.md) for typed configuration and field semantics.
219+
220+
## Realtime
221+
222+
Realtime (Beta) supports conversation creation, text and PCM audio exchange over WebSocket, Work events and persisted History. Use `client.realtime().conversations()` for creation/history and `client.realtime().connect(...)` for connections. The Template must have Realtime enabled and be accessible to the credential.
223+
224+
Microphone capture and audio playback belong to the application. Connections do not automatically reconnect or replay input. See the [Realtime guide](docs/realtime.md) and [runnable example](examples/src/main/java/com/qoder/cloudagents/examples/RealtimeExample.java) for authentication, audio formats and connection lifecycle.
225+
226+
## Examples and documentation
227+
228+
- [Runnable examples](examples/README.md): shared PAT/SA setup, resource lifecycles, Session SSE and Realtime.
229+
- [API coverage](docs/forward-api-coverage.md): supported operations and guides for each resource.
230+
- [Files and downloads](docs/environments-files.md) and [Drive, Usage and SAT management](docs/usage-sat-drive.md).
231+
- [Live testing](docs/live-testing.md): opt-in CN/Global verification and coverage boundaries.
232+
233+
## Development
234+
235+
With JDK 17+ and Python 3 installed, run from the repository root:
236+
237+
```sh
238+
make quality
239+
make test
240+
```
241+
242+
These commands check formatting, documentation and maintenance scripts, then build the SDK and test the packaged JAR through the independent examples project. Default tests use local mock services. See [CONTRIBUTING.md](CONTRIBUTING.md), [maintenance](docs/maintaining.md) and [releasing](docs/releasing.md).
243+
244+
## Versioning
57245

58-
## Documentation
246+
Pin the SDK version in your build. Before 1.0, incompatible API changes use a new minor version and include migration notes. See the [changelog](CHANGELOG.md) for upgrading from the RC or earlier internal coordinates.
59247

60-
- [Runnable resource examples and shared authentication setup](examples/README.md)
61-
- [Forward API coverage and resource guides](docs/forward-api-coverage.md)
62-
- [Session/Thread SSE](docs/session-streaming.md) and [Realtime text, audio and History](docs/realtime.md)
63-
- [Usage, Forward SAT management and Drive](docs/usage-sat-drive.md)
64-
- [Live testing](docs/live-testing.md)
248+
## License
65249

66-
For source builds and contributions, see [CONTRIBUTING.md](CONTRIBUTING.md). Maintainers can follow the [maintenance](docs/maintaining.md) and [release](docs/releasing.md) guides.
250+
[MIT](LICENSE).

‎docs/forward-api-coverage.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,10 @@ HTTP BaseURL 为 CN `https://api.qoder.com.cn/api/v1/forward` 或 Global `https:
164164
| SA Credential | `ServiceAccountCredential` | 平台 Token 置换、缓存、按需续期,与 Forward SAT 管理 API 分开 | 已实现 |
165165
| 同步/异步与响应元信息 | `ForwardClient / AsyncForwardClient / withResponse` | 同一协议核心;取消和资源所有权明确;保留 request ID | 已实现 |
166166

167-
## 范围外
167+
## 当前版本未提供
168168

169-
- Managed 全部接口、资源 Search、Forward Dream。
169+
- Managed API:计划在后续版本支持,当前 0.1.0 尚未提供。
170+
- 资源 Search、Forward Dream。
170171
- Realtime Template 专用配置 GET/POST;普通 Template 的 managed_tool_config 已实现。
171172
- Agent 运行时内部工具调用和免 Token 的内部服务认证模式。
172173
- 新增 Drive 本地文件同步框架、采集/播放音频设备实现。

0 commit comments

Comments
 (0)