Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion src/data/languages/languageData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default {
android: '1.2',
},
aiTransport: {
javascript: '0.3',
javascript: '0.4',
},
spaces: {
javascript: '0.5',
Expand Down
8 changes: 8 additions & 0 deletions src/data/nav/aitransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ export default {
name: 'History and replay',
link: '/docs/ai-transport/features/history',
},
{
name: 'Database hydration',
link: '/docs/ai-transport/features/database-hydration',
},
{
name: 'Branching, edit, and regenerate',
link: '/docs/ai-transport/features/branching',
Expand Down Expand Up @@ -259,6 +263,10 @@ export default {
name: 'useCreateView',
link: '/docs/ai-transport/api/react/core/use-create-view',
},
{
name: 'useMessagesWithSeed',
link: '/docs/ai-transport/api/react/core/use-messages-with-seed',
},
{
name: 'useTree',
link: '/docs/ai-transport/api/react/core/use-tree',
Expand Down
20 changes: 8 additions & 12 deletions src/pages/docs/ai-transport/api/errors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ The `ErrorInfo` type is exported from `ably`. AI Transport surfaces it as the re
| 104003 | RunLifecycleError | 500 | A publish within a Run failed (lifecycle event, message, or codec event). | Check channel permissions and connection state. Surface the error to the calling HTTP handler so the client's pending send fails. |
| 104004 | SessionClosed | 400 | An operation was attempted on a session that has already been closed. | Create a new session. Do not reuse a closed session. |
| 104005 | SessionSendFailed | 500 | A send failed: either the core's channel publish failed, or the Vercel chat transport's agent-invocation POST failed (network error or non-2xx response). | Check the API endpoint URL, network connectivity, and authentication. Inspect the underlying error for details. |
| 104006 | ChannelContinuityLost | 500 | The Ably channel lost message continuity. The channel entered `FAILED`, `SUSPENDED`, or `DETACHED`, or re-attached with `resumed: false`. Active streams can no longer be guaranteed to receive all events. | Surfaced via the session's `on('error')` and the agent session's `onError` option. End active Runs; subsequent operations can resume once the channel reattaches. |
| 104006 | ChannelContinuityLost | 500 | The Ably channel lost message continuity. The channel entered `FAILED`, `SUSPENDED`, or `DETACHED`, or re-attached with `resumed: false`. Active streams can no longer be guaranteed to receive all events. | Surfaced via the session's `on('error')` on both the client and the agent. End active Runs; subsequent operations can resume once the channel reattaches. |
| 104007 | ChannelNotReady | 400 | An operation was attempted but the channel is not in a usable state (not `ATTACHED` or `ATTACHING`). | Wait for the channel to attach before retrying, or inspect channel state and connection state for the underlying cause. |
| 104008 | StreamError | 500 | An error occurred while piping a response stream to the channel. Either the source event stream threw (LLM provider rate limit, model error, network failure) or an underlying publish failed mid-stream. | Inspect `cause` for the provider error. End the Run with reason `'error'`. The error is also returned on `StreamResult.error` from `Run.pipe`. |
| 104010 | InputEventNotFound | 504 | The agent attached to the channel and waited for the input events the invocation points at (rewind + live wait) but `inputEventLookupTimeoutMs` lapsed without seeing them. | Surface the rejection from `Run.start()` as a non-2xx response so the client's pending send fails. The client retries with a fresh send. |

### Auth and channel errors <a id="platform"/>

Expand All @@ -65,7 +64,7 @@ Auth and channel errors come from the Ably platform, not AI Transport. The most
| 90000 | Internal channel error. | Retry the operation. If the error persists, contact support. |
| 93002 | `Can only update/delete/append messages on channels with mutableMessages enabled`. The namespace lacks the `mutableMessages` rule, so AI Transport cannot append stream tokens. This is the most common AI Transport setup failure. | Enable the **Message annotations, updates, deletes, and appends** rule on the namespace. See [Configure the channel rule](/docs/ai-transport/getting-started/channel-rules). |

The full Ably error code list lives at [Ably error codes](/docs/sdks/error-codes).
The full Ably error code list lives at [Ably error codes](/docs/platform/errors/codes).

## Match an ErrorInfo against a code <a id="error-info-is"/>

Expand All @@ -87,7 +86,7 @@ session.on('error', (error) => {

## Example <a id="example"/>

Handle session-level and run-level errors separately. The client subscribes to session errors. The agent uses the `onError` option on `AgentSessionOptions` for session-wide events and the run runtime's `onError` for per-Run failures.
Handle session-level and run-level errors separately. Both the client and the agent subscribe to session errors with `session.on('error')`. The agent additionally uses the run runtime's `onError` for per-Run failures.

<Code>
```javascript
Expand All @@ -102,17 +101,14 @@ session.on('error', (error) => {
});

// Agent side: handle session and run-level errors separately.
const agentSession = createAgentSession({
client: ably,
channelName,
codec,
onError(error) {
console.error('Session error:', error);
},
});
const agentSession = createAgentSession({ client: ably, channelName, codec });

await agentSession.connect();

agentSession.on('error', (error) => {
console.error('Session error:', error);
});

const run = agentSession.createRun(invocation, {
signal: req.signal,
onError(error) {
Expand Down
10 changes: 8 additions & 2 deletions src/pages/docs/ai-transport/api/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ See the individual reference pages for the full API.
| Entry point | Import path | Contents |
| --- | --- | --- |
| Core | `@ably/ai-transport` | `createClientSession`, `createAgentSession`, `Invocation`, `Codec` interface |
| React | `@ably/ai-transport/react` | `ClientSessionProvider`, `useClientSession`, `useView`, `useTree`, `useCreateView`, `useAblyMessages`, `createSessionHooks` |
| React | `@ably/ai-transport/react` | `ClientSessionProvider`, `useClientSession`, `useView`, `useTree`, `useCreateView`, `useMessagesWithSeed`, `useAblyMessages`, `createSessionHooks` |
| Vercel | `@ably/ai-transport/vercel` | `UIMessageCodec`, Vercel-bound `createClientSession` and `createAgentSession`, `createChatTransport`, `vercelRunOutcome` |
| Vercel React | `@ably/ai-transport/vercel/react` | `ChatTransportProvider`, `useChatTransport`, `useMessageSync`, plus the Vercel-baked re-exports of `ClientSessionProvider`, `useClientSession`, `useView`, `useCreateView`, `useTree`, and `useAblyMessages` |
| Vercel React | `@ably/ai-transport/vercel/react` | `ChatTransportProvider`, `useChatTransport`, `useMessageSync`, `useMessagesWithSeed`, plus the Vercel-baked re-exports of `ClientSessionProvider`, `useClientSession`, `useView`, `useCreateView`, `useTree`, and `useAblyMessages` |

<Aside data-type='note'>
The Vercel entry points re-export the core factories with the codec pre-bound. If you use `@ably/ai-transport/vercel`, you do not need to import from `@ably/ai-transport` separately.
Expand Down Expand Up @@ -126,6 +126,12 @@ The Vercel entry points re-export the core factories with the codec pre-bound. I
image: 'icon-tech-react',
link: '/docs/ai-transport/api/react/core/use-create-view',
},
{
title: 'useMessagesWithSeed',
description: 'Reconcile a persisted conversation seed with the live channel and render the composed conversation.',
image: 'icon-tech-react',
link: '/docs/ai-transport/api/react/core/use-messages-with-seed',
},
{
title: 'useTree',
description: 'Stable structural query callbacks for inspecting Runs outside the visible branch.',
Expand Down
Loading
Loading