Skip to content

Commit e26cf76

Browse files
committed
docs(ai): align rag and client docs
1 parent 67cd1b8 commit e26cf76

7 files changed

Lines changed: 152 additions & 57 deletions

File tree

docs/src/content/docs/clients/javascript.md

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: "TypeScript client with React, Vue, and Svelte hooks"
55

66
# atmosphere.js -- TypeScript Client
77

8-
TypeScript client for the Atmosphere Framework (currently `5.0.22`). Supports WebTransport/HTTP3, WebSocket, SSE, HTTP Streaming, and Long-Polling transports with first-class React, Vue, and Svelte hooks.
8+
TypeScript client for the Atmosphere Framework (currently `5.0.24`). Supports WebTransport/HTTP3, WebSocket, SSE, HTTP Streaming, and Long-Polling transports with first-class React, Vue, and Svelte hooks.
99

1010
## npm Coordinates
1111

@@ -35,10 +35,10 @@ The package ships ESM, CommonJS, and TypeScript declarations. Framework integrat
3535

3636
```typescript
3737
import { Atmosphere } from 'atmosphere.js';
38-
import { useAtmosphere, useStreaming, useRoom, usePresence } from 'atmosphere.js/react';
39-
import { useAtmosphere, useStreaming, useRoom } from 'atmosphere.js/vue';
40-
import { createAtmosphereStore, createStreamingStore, createRoomStore } from 'atmosphere.js/svelte';
41-
import { useAtmosphereRN, useStreamingRN, setupReactNative } from 'atmosphere.js/react-native';
38+
import { useAtmosphere, useStreaming, useChat, useRoom, usePresence } from 'atmosphere.js/react';
39+
import { useAtmosphere, useStreaming, useChat, useRoom } from 'atmosphere.js/vue';
40+
import { createAtmosphereStore, createStreamingStore, createChatStore, createRoomStore } from 'atmosphere.js/svelte';
41+
import { useAtmosphereRN, useStreamingRN, useChatRN, setupReactNative } from 'atmosphere.js/react-native';
4242
```
4343

4444
## Core API
@@ -56,7 +56,7 @@ const atm = new Atmosphere({
5656
fallbackTransport: 'long-polling',
5757
});
5858

59-
atm.version; // '5.0.22'
59+
atm.version; // '5.0.24'
6060
atm.closeAll(); // Close every active subscription
6161
atm.getSubscriptions(); // Map<string, Subscription>
6262
```
@@ -384,6 +384,28 @@ function AiChat() {
384384
}
385385
```
386386

387+
### useChat
388+
389+
AI-SDK-style message/input state layered on `useStreaming`:
390+
391+
```tsx
392+
import { useChat } from 'atmosphere.js/react';
393+
394+
function AiChatForm() {
395+
const { messages, input, setInput, handleSubmit, isLoading } = useChat({
396+
request: { url: '/ai/chat', transport: 'websocket' },
397+
});
398+
399+
return (
400+
<form onSubmit={handleSubmit}>
401+
{messages.map((message) => <p key={message.id}>{message.content}</p>)}
402+
<input value={input} onChange={(event) => setInput(event.target.value)} />
403+
<button disabled={isLoading}>Send</button>
404+
</form>
405+
);
406+
}
407+
```
408+
387409
## Vue Composables
388410

389411
Vue composables do not require a provider -- they create or accept an Atmosphere instance directly.
@@ -453,6 +475,26 @@ const { fullText, isStreaming, send, reset } = useStreaming({
453475
</template>
454476
```
455477

478+
### useChat
479+
480+
```vue
481+
<script setup lang="ts">
482+
import { useChat } from 'atmosphere.js/vue';
483+
484+
const { messages, input, handleSubmit, isLoading } = useChat({
485+
request: { url: '/ai/chat', transport: 'websocket' },
486+
});
487+
</script>
488+
489+
<template>
490+
<form @submit="handleSubmit">
491+
<p v-for="message in messages" :key="message.id">{{ message.content }}</p>
492+
<input v-model="input" />
493+
<button :disabled="isLoading">Send</button>
494+
</form>
495+
</template>
496+
```
497+
456498
## Svelte Stores
457499

458500
Svelte integrations use the store pattern -- each factory returns a Svelte-compatible readable store plus action functions.
@@ -520,6 +562,24 @@ Svelte integrations use the store pattern -- each factory returns a Svelte-compa
520562
{#if $store.isStreaming}<span>Generating...</span>{/if}
521563
```
522564

565+
### createChatStore
566+
567+
```svelte
568+
<script>
569+
import { createChatStore } from 'atmosphere.js/svelte';
570+
571+
const { store: chat, append, reset } = createChatStore({
572+
request: { url: '/ai/chat', transport: 'websocket' },
573+
});
574+
</script>
575+
576+
{#each $chat.messages as message}
577+
<p>{message.content}</p>
578+
{/each}
579+
<button on:click={() => append('What is Atmosphere?')}>Ask</button>
580+
<button on:click={reset}>Reset</button>
581+
```
582+
523583
## AI Streaming Wire Protocol
524584

525585
The server sends JSON messages using the Atmosphere AI streaming protocol:
@@ -532,7 +592,9 @@ The server sends JSON messages using the Atmosphere AI streaming protocol:
532592
{"type": "error", "data": "Rate limited","sessionId": "abc-123", "seq": 11}
533593
```
534594

535-
Use `subscribeStreaming` for framework-agnostic streaming, or the hooks above for React/Vue/Svelte.
595+
Use `subscribeStreaming` for framework-agnostic streaming, `useStreaming` /
596+
`createStreamingStore` for raw text accumulation, or `useChat` /
597+
`createChatStore` for message/input state.
536598

537599
## Request Options
538600

@@ -647,7 +709,7 @@ Complete TypeScript type reference for the public surface.
647709

648710
```typescript
649711
class Atmosphere {
650-
readonly version: string; // '5.0.22'
712+
readonly version: string; // '5.0.24'
651713

652714
constructor(config?: {
653715
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'silent';

docs/src/content/docs/clients/react-native.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: "React Native hooks with EventSource polyfill"
55

66
# React Native / Expo Guide
77

8-
atmosphere.js `5.0.22` supports React Native and Expo via the `atmosphere.js/react-native` subpath export. Tested baseline: Expo SDK 55, React Native 0.83, React 19.2 (see `samples/spring-boot-ai-classroom/expo-client/package.json`).
8+
atmosphere.js `5.0.24` supports React Native and Expo via the `atmosphere.js/react-native` subpath export. Tested baseline: Expo SDK 55, React Native 0.83, React 19.2 (see `samples/spring-boot-ai-classroom/expo-client/package.json`).
99

1010
## Installation
1111

@@ -132,6 +132,19 @@ const { fullText, isStreaming, isConnected, send, reset, close } = useStreamingR
132132

133133
Sends are suppressed when the device is offline.
134134

135+
### `useChatRN`
136+
137+
AI-SDK-style message/input state layered on `useStreamingRN`.
138+
139+
```typescript
140+
const { messages, input, setInput, handleSubmit, isLoading } = useChatRN({
141+
request: { url: 'https://example.com/ai/chat', transport: 'websocket' },
142+
});
143+
```
144+
145+
`append()`, `reload()`, `stop()`, and `reset()` are also available for custom
146+
chat UIs.
147+
135148
### `useAtmosphereCore`
136149

137150
Shared low-level hook exported from `atmosphere.js/react-native` for building custom hooks. It manages subscription lifecycle, state, and cleanup — the RN-aware `useAtmosphereRN` and `useStreamingRN` hooks are built on top of it. Use it when the built-in hooks don't fit your use case.

docs/src/content/docs/reference/ai.md

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -621,41 +621,44 @@ The `AiEvent` sealed interface provides 15 structured event types emitted via `s
621621

622622
## Capability Matrix
623623

624-
Each runtime declares capabilities via `AiCapability`. The framework uses these for model routing, tool negotiation, and feature discovery.
625-
626-
### Guaranteed by Core
627-
628-
Available on **all** runtimes:
629-
630-
| Capability | Description |
631-
|-----------|-------------|
632-
| `TEXT_STREAMING` | Basic text streaming |
633-
| `SYSTEM_PROMPT` | System prompt support |
634-
635-
### Runtime-Dependent
636-
637-
| Capability | Built-in | LangChain4j | Spring AI | ADK | Embabel | Koog | SK |
638-
|-----------|----------|-------------|-----------|-----|---------|------|----|
639-
| `TOOL_CALLING` | Y | Y | Y | Y | | Y | |
640-
| `STRUCTURED_OUTPUT` | Y | Y | Y | Y | Y | Y | Y |
641-
| `CONVERSATION_MEMORY` | | | | Y | | Y | Y |
642-
| `TOOL_APPROVAL` | Y | Y | Y | Y | | Y | |
643-
| `VISION` | Y | Y | Y | Y | | | |
644-
| `AUDIO` | | Y | Y | Y | | | |
645-
| `MULTI_MODAL` | Y | Y | Y | Y | | | |
646-
| `PROMPT_CACHING` | Y | Y | Y | | | | |
647-
| `TOKEN_USAGE` | Y | Y | Y | Y | Y | Y | Y |
624+
Each runtime declares capabilities via `AiCapability`. The framework uses
625+
these flags for model routing, tool negotiation, and feature discovery. The
626+
table below mirrors the nine-runtime snapshot pinned by each runtime's
627+
`expectedCapabilities()` contract test; `Y` means the runtime declares the
628+
capability and the contract tests assert it.
629+
630+
Legend: TS=TEXT_STREAMING, TC=TOOL_CALLING, SO=STRUCTURED_OUTPUT,
631+
SP=SYSTEM_PROMPT, AO=AGENT_ORCHESTRATION, CM=CONVERSATION_MEMORY,
632+
TA=TOOL_APPROVAL, V=VISION, A=AUDIO, MM=MULTI_MODAL, PC=PROMPT_CACHING,
633+
TU=TOKEN_USAGE, PRR=PER_REQUEST_RETRY, TCD=TOOL_CALL_DELTA,
634+
BE=BUDGET_ENFORCEMENT, CS=CONFIDENCE_SCORES, PSV=PASSIVATION.
635+
636+
| Runtime | Priority | TS | TC | SO | SP | AO | CM | TA | V | A | MM | PC | TU | PRR | TCD | BE | CS | PSV |
637+
|---------|---------:|:--:|:--:|:--:|:--:|:--:|:--:|:--:|:-:|:-:|:--:|:--:|:--:|:--:|:--:|:--:|:--:|:--:|
638+
| Built-in | 0 | Y | Y | Y | Y | | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y |
639+
| Spring AI | 100 | Y | Y | Y | Y | | Y | Y | Y | Y | Y | Y | Y | Y | | Y | Y | Y |
640+
| LangChain4j | 100 | Y | Y | Y | Y | | Y | Y | Y | Y | Y | Y | Y | Y | | Y | Y | Y |
641+
| Google ADK | 100 | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | Y | Y | Y |
642+
| Embabel | 100 | Y | Y | Y | Y | Y | Y | Y | Y | | Y | | Y | Y | | Y | Y | Y |
643+
| JetBrains Koog | 100 | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | Y | Y | Y |
644+
| Alibaba AgentScope | 100 | Y | | Y | Y | | Y | | | | | | Y | Y | | Y | Y | Y |
645+
| Spring AI Alibaba | 100 || | Y | Y | | Y | | | | | | | Y | || Y | Y |
646+
| Microsoft Semantic Kernel | 100 | Y | Y | Y | Y | | Y | Y | | | | | Y | Y | | Y | Y | Y |
647+
648+
¹ Spring AI Alibaba emits its final reply as one Atmosphere stream chunk, but
649+
the upstream `ReactAgent.call()` path is buffered rather than token-by-token.
650+
651+
² Spring AI Alibaba participates in wall-clock budget enforcement. Token and
652+
step budget breaches require token-usage metadata, which that SDK path does not
653+
surface today.
648654

649655
**How structured output works:** `AiPipeline` wraps the streaming session with `StructuredOutputCapturingSession` and augments the system prompt with JSON-schema instructions before the runtime runs. Any runtime that honors `SYSTEM_PROMPT` therefore gets `STRUCTURED_OUTPUT` automatically via the pipeline — no per-runtime adapter code required. `BuiltInAgentRuntime` additionally enables native `jsonMode` on the OpenAI-compatible client for provider-level JSON enforcement on top of the pipeline wrap. Source: `modules/ai/src/main/java/org/atmosphere/ai/pipeline/AiPipeline.java:128-135`, `modules/ai/src/main/java/org/atmosphere/ai/llm/BuiltInAgentRuntime.java:72-74`.
650656

651-
**Capability gaps:**
652-
- `EmbabelAgentRuntime` does not advertise `TOOL_CALLING`: Embabel agents expose skills via their own `@Agent` API, not free-form tool calling. Source: `modules/embabel/src/main/kotlin/org/atmosphere/embabel/EmbabelAgentRuntime.kt`.
653-
654-
### Experimental
655-
656-
| Capability | Built-in | LangChain4j | Spring AI | ADK | Embabel | Koog | SK |
657-
|-----------|----------|-------------|-----------|-----|---------|------|----|
658-
| `AGENT_ORCHESTRATION` | | | | Y | Y | Y | |
657+
**Capability gaps:** AgentScope and Spring AI Alibaba do not declare
658+
`TOOL_CALLING` or `TOOL_APPROVAL` because their current SDK surfaces do not
659+
provide a native tool-dispatch loop that maps cleanly to Atmosphere's
660+
`@AiTool` protocol. Spring AI Alibaba also omits `TOKEN_USAGE` because
661+
`ReactAgent.call()` returns an `AssistantMessage` without usage metadata.
659662

660663
## Cross-Runtime Contract Tests (TCK)
661664

@@ -688,7 +691,7 @@ Add `atmosphere-ai-test` as a test dependency and extend the base class:
688691
</dependency>
689692
```
690693

691-
The `RecordingSession` test double captures all events, text chunks, metadata, and errors for assertion. Currently enforced on: ADK, LangChain4j, Spring AI.
694+
The `RecordingSession` test double captures all events, text chunks, metadata, and errors for assertion. The contract suite is implemented for all nine runtime adapters.
692695

693696
## Samples
694697

docs/src/content/docs/tutorial/04-transports.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ The client attaches the following headers (or query parameters) to every request
204204

205205
| Header / Query Param | Description |
206206
|----------------------|-------------|
207-
| `X-Atmosphere-Framework` | The Atmosphere client version (e.g., `5.0.22`) |
207+
| `X-Atmosphere-Framework` | The Atmosphere client version (e.g., `5.0.24`) |
208208
| `X-Atmosphere-Transport` | The transport in use: `webtransport`, `websocket`, `sse`, `long-polling`, `streaming`, or `close` |
209209
| `X-Atmosphere-tracking-id` | A UUID that uniquely identifies this client. Initially `0`; the server assigns the real value on first response |
210210
| `X-Cache-Date` | Timestamp for cache coordination |
@@ -220,7 +220,7 @@ The client attaches the following headers (or query parameters) to every request
220220
A typical first request on the wire looks like:
221221

222222
```
223-
GET /chat?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=5.0.22
223+
GET /chat?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=5.0.24
224224
&X-Atmosphere-Transport=websocket&X-atmo-protocol=true HTTP/1.1
225225
Host: localhost:8080
226226
```

docs/src/content/docs/tutorial/09-ai-endpoint.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,17 +617,30 @@ Three built-in providers are available:
617617
| `SpringAiVectorStoreContextProvider` | `atmosphere-rag` | Bridges Spring AI vector stores |
618618
| `LangChain4jEmbeddingStoreContextProvider` | `atmosphere-rag` | Bridges LangChain4j retrievers |
619619

620-
The `ContextProvider` SPI supports query transformation and reranking:
620+
The `ContextProvider` SPI supports the full RAG shaping pipeline:
621621

622622
```java
623623
public interface ContextProvider {
624624
List<Document> retrieve(String query, int maxResults);
625+
625626
default String transformQuery(String originalQuery) { return originalQuery; }
627+
default List<Document> filter(String query, List<Document> documents) { return documents; }
626628
default List<Document> rerank(String query, List<Document> documents) { return documents; }
629+
default List<Document> postProcess(String query, List<Document> documents) { return documents; }
630+
631+
static String formatCitation(Document document) { ... }
627632
}
628633
```
629634

630-
Execution order: `transformQuery()` -> `retrieve()` -> `rerank()` -> inject into `AiRequest.message`.
635+
Execution order: `transformQuery()` -> normalize/blank-query guard ->
636+
`retrieve()` -> `filter()` -> `rerank()` -> `postProcess()` ->
637+
`formatCitation()` -> inject into `AiRequest.message`.
638+
639+
`formatCitation()` includes source and chunk metadata when present:
640+
`source_document`, `chunk_index`, `chunk_count`, `chunk_start`, and
641+
`chunk_end`. The Spring Boot RAG Chat sample preserves that metadata when it
642+
chunks its Markdown knowledge base, so citations point to a source passage
643+
instead of only naming the whole file.
631644

632645
## Client Integration
633646

docs/src/content/docs/tutorial/26-foundation-primitives.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,5 @@ HTTP request ─► AiEndpointHandler ─► AiStreamingSession ─► AgentRunt
163163
autonomous ramp.
164164
- [Durable HITL Workflows](./24-durable-hitl)@RequiresApproval that
165165
survives a process restart.
166-
- [AI Adapters](./11-ai-adapters) — the seven `AgentRuntime`
166+
- [AI Adapters](./11-ai-adapters) — the nine `AgentRuntime`
167167
implementations and their capability matrix.

docs/src/content/docs/whats-new.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pluggable AI runtimes, orchestration primitives, WebTransport/HTTP3, React Nativ
1313
support, and major compatibility refreshes.
1414

1515
The latest build tracks **Spring Boot 4.0.6**, **Quarkus 3.35.2**,
16-
**Jackson 3.1.1**, and **atmosphere.js 5.0.22**, and requires **JDK 21** as a minimum.
16+
**Jackson 3.1.1**, and **atmosphere.js 5.0.24**, and requires **JDK 21** as a minimum.
1717

1818
This page is a highlights reel. For the per-patch history, see the
1919
[CHANGELOG](https://github.com/Atmosphere/atmosphere/blob/main/CHANGELOG.md).
@@ -133,9 +133,13 @@ This page is a highlights reel. For the per-patch history, see the
133133
- **`StructuredOutputParser` SPI** — generate JSON Schema instructions from Java
134134
classes, parse LLM output into typed objects. `JacksonStructuredOutputParser`
135135
works with any model.
136-
- **Enhanced RAG**`ContextProvider.transformQuery()` and `rerank()` enable
137-
query rewriting and result re-ranking without a custom pipeline;
138-
`InMemoryContextProvider` gives a zero-dependency provider for development.
136+
- **Enhanced RAG**`ContextProvider.transformQuery()`, `filter()`,
137+
`rerank()`, and `postProcess()` cover query rewriting, metadata/tenant
138+
filtering, result re-ranking, and final context shaping without a custom
139+
pipeline. Prompt injection uses `ContextProvider.formatCitation()` so chunk
140+
metadata (`source_document`, `chunk_index`, `chunk_start`, `chunk_end`) is
141+
visible to the model; `InMemoryContextProvider` gives a zero-dependency
142+
provider for development.
139143
- **First-class identity fields**`AiRequest` carries `userId`, `sessionId`,
140144
`agentId`, and `conversationId` as explicit fields instead of an untyped
141145
`hints()` map.
@@ -400,15 +404,15 @@ the wire surfaces, samples, and CI gates that make it adoptable. See the
400404

401405
## Client Libraries
402406

403-
- **atmosphere.js 5.0.22** — TypeScript client with no runtime dependencies.
407+
- **atmosphere.js 5.0.24** — TypeScript client with no runtime dependencies.
404408
ESM + CJS + IIFE bundles, WebSocket with configurable fallback to SSE, HTTP
405409
streaming, or long-polling. See [atmosphere.js](/docs/clients/javascript/).
406410
- **React, Vue, Svelte hooks**`useAtmosphere`, `useRoom`, `usePresence`,
407-
`useStreaming` via `atmosphere.js/react`, `/vue`, and `/svelte`. Shared chat
408-
components via `atmosphere.js/chat`.
409-
- **React Native / Expo**`useAtmosphere` React Native hook with an
410-
`EventSource` polyfill, NetInfo injection, and markdown rendering for mobile
411-
AI chat. See [React Native](/docs/clients/react-native/).
411+
`useStreaming`, and AI-SDK-style chat state via `useChat` /
412+
`createChatStore`. Shared chat components ship through `atmosphere.js/chat`.
413+
- **React Native / Expo**`useAtmosphereRN`, `useStreamingRN`, and
414+
`useChatRN` with an `EventSource` polyfill, NetInfo injection, and markdown
415+
rendering for mobile AI chat. See [React Native](/docs/clients/react-native/).
412416
- **wAsync 4.0** — the Java client rewritten on `java.net.http` with gRPC
413417
support. See [Java Client](/docs/clients/java/).
414418

0 commit comments

Comments
 (0)