Optional SDK chat binding
Optional AI SDK 7 chat binding
Section titled “Optional AI SDK 7 chat binding”The explicit @alneas/react-ai/ai-chat entry supplies createAIChatTransport and
toAIChatMessages. Install ai@^7.0.105 to use its SDK types. The peer is optional;
the root and generative UI entry have no SDK type dependency. The binding uses
SDK type imports only, so importing its JavaScript requires no SDK runtime.
The package’s normal dependency remains @alneas/ai-core@0.1.0, never data-engine.
import { createAIChatTransport } from '@alneas/react-ai/ai-chat';const transport = createAIChatTransport(adapter, { parameters: { temperature: 0.2 } });// Pass transport to the consuming SDK's Chat/useChat setup.Supply an ai-core AIChatAdapter. SDK request body overrides configured
parameters; chatId/trigger/messageId and abortSignal are forwarded. SDK 7 types
are tested at 7.0.105 with React 18/19 and strict NodeNext ESM/CJS declarations.
When a CommonJS TypeScript file imports SDK types directly, use
import type { UIMessage } from 'ai' with { 'resolution-mode': 'import' };
because SDK 7 publishes ESM declarations. The binding’s declarations already do so.
Other SDK majors are not supported by this entry.
History conversion preserves IDs, roles, text, file URL/mediaType/filename,
metadata, persistent data parts, complete tool input/output and error results.
Reasoning, sources, step markers and incomplete tool inputs are omitted, matching
the former frontend binding. Static tool-* and dynamic-tool parts map to the
same provider-neutral tool shape. Error history keeps {error: errorText} with
isError; incoming error results expose the generic SDK text Tool execution failed.
No tools run automatically. Converted values pass through ai-core’s bounded,
detached JSON/history validation. Non-JSON data and malformed identities reject.
The transport maps normalized events into SDK start/text/tool/data/metadata/finish
chunks. ai-core owns finish/EOF validation, size limits, request snapshots and
abort/cleanup behavior; see conversation guide.
Truncated/post-finish streams reject. Cancellation reaches pending reads, but
adapters must obey AbortSignal to stop their actual I/O. reconnectToStream
returns null: resumption is unsupported. No localStorage, IndexedDB, React hook,
provider SDK, network endpoint, retry or authorization policy is created here.
The application retains browser state, useChat wiring and explicit action dispatch.
Strict SDK declarations also require development typings @types/node@^24 and
@types/json-schema@^7.0.15 (the latter is an optional type peer). Install these
when using the SDK entry; the SDK-free base consumer needs neither.