Skip to main content

Overview

Streams an AI-generated answer to a natural language question, grounded in your project’s content. Uses SSE (Server-Sent Events) to deliver tokens incrementally. Returns source citations once the stream completes. For integration guidance, see Ask Content.

Usage Example

Parameters

Call ask with:
query
string
required
The natural language question.
sourceTypes
("entity" | "comment" | "message")[]
Limit the content types searched for context.
spaceId
string
Scope context lookup to a specific space.
includeChildSpaces
boolean
default:"false"
Only applies with spaceId. When true, the context lookup also covers every space nested under it — children, grandchildren, the whole subtree at any depth — so you can ask across a community and all of its channels at once. Ignored without spaceId.
conversationId
string
Scope context lookup to a specific conversation.
limit
number
Maximum number of source records to use as context.

Returns

answer
string
The AI-generated answer. Grows token by token while streaming is true.
sources
ContentSearchResult[]
Source records used as context. Populated after streaming ends. When spaceReputation is requested, each record’s embedded author carries an added spaceReputation number. See Reputation.
streaming
boolean
true while the SSE stream is open and tokens are arriving.
loading
boolean
true from ask() call until the first token arrives.
error
string | null
Error message if the request failed.
ask
(props) => void
Starts a new question. Aborts any in-flight stream first.
reset
() => void
Aborts in-flight stream and clears all state.
In React Native, SSE streaming requires polyfills for fetch, ReadableStream, and TextDecoder. Install react-native-fetch-api, web-streams-polyfill@^3, react-native-polyfill-globals, and text-encoding, then call the targeted sub-polyfills once at app startup, before using this hook:
Prefer these targeted polyfills over the all-in-one polyfillGlobals(): that helper also pulls in react-native-get-random-values, a native module that forces a development-client rebuild. The three above are pure JavaScript, so a Metro reload is enough. Pin web-streams-polyfill to v3 — v4 removed the ponyfill/es6 subpath that react-native-polyfill-globals requires.