Skip to main content

Class: AIGatewayVercelUi

Defined in: entries/vercel-ui/AIGatewayVercelUi.ts:77

AIGatewayVercelUi -- the gateway for one chat use case of a Vercel chat client

About​

An endpoint is one call: the request in, the SSE response out.

Composes an AIGateway for the browser's useChat: parses the client's messages, calls ask / run / resume, reads the call's events (D38) and streams them as the SDK's UI message chunks; reads a thread and its pause as the messages to draw. The gateway itself knows nothing of it (D40).

  • One instance per use case: the profile, the KB scope, the tools and the instructions are configuration, a second endpoint is a second instance.
  • The request body never names the tenant or the user: the config's userContext hook is the trust boundary (D118).
  • The client's copy of the history is never the truth: only the last message of a request is read.

Sits between the application's route handlers and the gateway; the mapping itself is the UiMapper.

Who needs it​

The application's chat endpoints: POST /api/chat → chat, GET /api/chat/:threadId → history, the form of a user question or an edit → resume.

What needs​

The AIGateway instance of the application (deps.gateway) and one IAIGatewayVercelUiConfig.

Usage​

When to use it​

A chat screen on useChat (or any client of the SDK's UI message stream protocol) talking to this gateway over HTTP.

When shouldn't use it​

Another transport (a WebSocket, a resumable stream after a reload): compose UiMapper with the gateway's events yourself. A backend service that needs no streaming: call the gateway directly.

Pitfalls​

The thread list of the sidebar, uploads, renaming and deleting are the gateway's own methods, not this module's: a chat screen calls both. The reviewer's screen of a RESULT_REVIEW (D99) is AIGateway.getPausedRun, an admin surface, never served through history.

Constructors​

Constructor​

new AIGatewayVercelUi(config, deps): AIGatewayVercelUi

Defined in: entries/vercel-ui/AIGatewayVercelUi.ts:80

Parameters​

config​

IAIGatewayVercelUiConfig

deps​

IAIGatewayVercelUiDeps

Returns​

AIGatewayVercelUi

Methods​

chat()​

chat(__namedParameters): Promise<Response>

Defined in: entries/vercel-ui/AIGatewayVercelUi.ts:103

chat -- the useChat endpoint

About​

The last user message in, the streamed answer out; the SDK's Approve / Reject in, the streamed continuation out.

A request whose last message is the user's starts ask or run (config.mode) on body.threadId, or on a new thread. A request whose last message is the assistant's with approval responses (D35) resumes the pause those name (approval.id = pauseId, D110), found among the user's own paused runs.

Pitfalls​

An error before the first chunk (a 400 of the input, a 404 of a foreign thread, a 409 of a paused thread, the 401 of userContext) is a JSON response with that status; an error once the stream runs is an error chunk, the status stays 200. A 5xx never carries its message to the client.

Parameters​

__namedParameters​
request​

Request

Returns​

Promise<Response>


history()​

history(__namedParameters): Promise<TGatewayUiMessage[]>

Defined in: entries/vercel-ui/AIGatewayVercelUi.ts:149

history -- the messages of a thread, for useChat({messages})

About​

The whole thread, oldest first, with the pause it waits on.

AIGateway.getTurns (D37) and the thread's paused run among the user's (listPausedRuns), mapped by UiMapper.toUiMessages. Throws what the gateway throws: a thread of another user is a 404 (D32).

Parameters​

__namedParameters​
request​

Request

threadId​

string

Returns​

Promise<TGatewayUiMessage[]>


resume()​

resume(__namedParameters): Promise<Response>

Defined in: entries/vercel-ui/AIGatewayVercelUi.ts:193

resume -- the continuation of a paused run, streamed

About​

For the decisions the SDK's approval card cannot express.

ANSWER with the answers of a user question (D62), EDIT of a tool input or of a reviewed answer, a REJECT with the asker's own text: the application builds the decisions (one per envelope, D102) from metadata.pause and calls this. The response streams like chat. The pause must be one of the user's own paused runs: a 404 otherwise.

Parameters​

__namedParameters​
decisions​

IResumeDecision[]

pauseId​

string

request​

Request

runId​

string

Returns​

Promise<Response>