For a complete working application — send, live cell streaming, and reload
re-attach — see the
chat-demo example.
@textql/sdk
v1.2.2+). All examples below are TypeScript.
The TextQL API exposes several server-streaming endpoints that are not part
of the REST surface documented elsewhere in this reference. They are consumed
through the SDK’s streaming client, which speaks
Connect-RPC to the same gateway with the same API key.
Quickstart
AbortSignal to cancel:
serverURL defaults to https://app.textql.com — on-prem deployments pass
their own host and the SDK routes RPCs correctly from there.
Streaming Methods
watchChat vs streamChat
Both deliver the same cell snapshots from the same event bus; they differ in what they tell you about run state.watchChatis a chat-scoped subscription: it announcesrunStartedimmediately when a run is live, delivers cells, signalsrunComplete/runError, and sends heartbeats every 20 seconds so idle connections survive proxies. It stays open across runs. Pass your last known cell id aslatestCompleteCellIdto replay anything you missed — this is how a UI re-attaches to a run after a page reload.streamChatis a run-scoped firehose: cells only, ending when the run ends. Right for one-shot scripts (send → for await cells → exit) that don’t need lifecycle state.
Driving a Chat End to End
The chat-demo example app implements this full flow (plus reload re-attach vialatestCompleteCellId);
the condensed version:
Cell message reference.
Notes
-
Runtime: browsers and Node 18+ (server-streaming rides on
fetchresponse streams). - Types: streaming methods return fully typed objects — discriminated unions for event payloads, TypeScript enums for statuses. They differ slightly in shape from the REST models documented elsewhere in this reference.
-
Disconnecting vs cancelling: aborting the signal or
breaking out of the loop closes your subscription — the run keeps executing server-side. To actually stop a chat run, call the Cancel Stream endpoint:You can watch the same chat again afterwards;watchChatreports the outcome via its lifecycle events.