API Reference
Complete API reference for @tour-kit/ai: client hooks, server utilities, chat components, and configuration types
Client Exports (@tour-kit/ai)
Hooks
useAiChat()
Core chat hook. Must be used within AiChatProvider.
Returns UseAiChatReturn:
| Property | Type | Description |
|---|---|---|
messages | UIMessage[] | Chat message history |
sendMessage | (input: { text: string }) => void | Send a user message |
status | ChatStatus | Current chat status ('ready', 'submitted', 'streaming', 'error') |
error | Error | null | Current error, if any |
stop | () => void | Stop the current generation |
reload | () => void | Regenerate the last response |
setMessages | (messages: UIMessage[]) => void | Replace message history (pass [] to clear) |
isOpen | boolean | Whether the chat panel is open |
open | () => void | Open the chat panel |
close | () => void | Close the chat panel |
toggle | () => void | Toggle the chat panel |
useTourAssistant()
Tour-aware chat hook. Extends useAiChat with tour context.
Returns UseTourAssistantReturn (extends UseAiChatReturn):
| Property | Type | Description |
|---|---|---|
tourContext | TourAssistantContext | Current tour state |
isLoading | boolean | Whether the assistant is loading |
suggestions | string[] | Contextual suggestions based on current step |
askAboutStep | () => void | Ask the AI about the current tour step |
askForHelp | (topic?: string) => void | Ask for help, optionally on a topic |
...all UseAiChatReturn properties |
useSuggestions()
AI-generated follow-up suggestions.
Returns UseSuggestionsReturn:
| Property | Type | Description |
|---|---|---|
suggestions | string[] | Current suggestions |
isLoading | boolean | Loading state |
Utilities
SlidingWindowRateLimiter
Client-side rate limiter using a sliding window algorithm.
createRateLimiter(config)
Factory function for creating a rate limiter instance.
createAnalyticsBridge(config)
Bridges AI chat events to @tour-kit/analytics.
Server Exports (@tour-kit/ai/server)
Route Handling
createChatRouteHandler(options)
Creates an API route handler for chat requests.
import { openai } from '@ai-sdk/openai'
const { POST } = createChatRouteHandler({
model: openai('gpt-4o-mini'),
context: {
strategy: 'context-stuffing',
documents: [{ id: 'doc-1', content: '...' }],
},
instructions: {
productName: 'My App',
tone: 'friendly',
},
})RAG Pipeline
createInMemoryVectorStore()
Creates an in-memory vector store for development and testing.
createAiSdkEmbedding(options)
Creates an embedding adapter using the AI SDK.
createRetriever(options)
Creates a document retriever from a vector store.
chunkDocument(doc, options) / chunkDocuments(docs, options)
Splits documents into chunks for embedding.
createRAGMiddleware(options)
Creates middleware that adds retrieved context to chat requests.
Utilities
createSystemPrompt(config)
Builds a structured system prompt from configuration.
createServerRateLimiter(config)
Server-side rate limiter.
createInMemoryRateLimitStore()
In-memory store for server rate limiting.
generateSuggestions(options) / parseSuggestions(text)
Generate and parse AI follow-up suggestions.
Types
See the full type definitions in the source code.