Skip to main content
userTourKit
@tour-kit/ai

API Reference

Complete API reference for @tour-kit/ai: client hooks, server utilities, chat components, and configuration types

domidex01Published

Client Exports (@tour-kit/ai)

Hooks

useAiChat()

Core chat hook. Must be used within AiChatProvider.

Returns UseAiChatReturn:

PropertyTypeDescription
messagesUIMessage[]Chat message history
sendMessage(input: { text: string }) => voidSend a user message
statusChatStatusCurrent chat status ('ready', 'submitted', 'streaming', 'error')
errorError | nullCurrent error, if any
stop() => voidStop the current generation
reload() => voidRegenerate the last response
setMessages(messages: UIMessage[]) => voidReplace message history (pass [] to clear)
isOpenbooleanWhether the chat panel is open
open() => voidOpen the chat panel
close() => voidClose the chat panel
toggle() => voidToggle the chat panel

useTourAssistant()

Tour-aware chat hook. Extends useAiChat with tour context.

Returns UseTourAssistantReturn (extends UseAiChatReturn):

PropertyTypeDescription
tourContextTourAssistantContextCurrent tour state
isLoadingbooleanWhether the assistant is loading
suggestionsstring[]Contextual suggestions based on current step
askAboutStep() => voidAsk the AI about the current tour step
askForHelp(topic?: string) => voidAsk for help, optionally on a topic
...all UseAiChatReturn properties

useSuggestions()

AI-generated follow-up suggestions.

Returns UseSuggestionsReturn:

PropertyTypeDescription
suggestionsstring[]Current suggestions
isLoadingbooleanLoading 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.