Skip to content

createAI()

Attaches an AI layer to an existing GuideFlow instance, exposing a .ai property that gives access to the full GuideBrain API.

Signature

ts
import { createAI } from '@guideflow/ai'

function createAI<T extends GuideFlowInstance>(
  provider: AIProvider,
  instance: T,
  opts?: GuideBrainOptions,
): T & { ai: GuideBrain }

Parameters

ParameterTypeDescription
providerAIProviderThe AI backend to use — see Providers
instanceGuideFlowInstanceAn existing GuideFlow instance created with createGuideFlow()
optsGuideBrainOptionsOptional tuning options for the GuideBrain

Returns

The same instance reference (mutated in place), typed to include an .ai: GuideBrain property.

Example

ts
import { createGuideFlow } from '@guideflow/core'
import { createAI, OpenAIProvider } from '@guideflow/ai'

const gf = createGuideFlow({ theme: 'minimal' })

const gfWithAI = createAI(
  new OpenAIProvider({ apiKey: import.meta.env.VITE_OPENAI_KEY }),
  gf,
  { autoWatch: true },
)

// Generate steps from the current page
const steps = await gfWithAI.ai.generate('Walk me through the checkout flow')
await gfWithAI.start({ id: 'ai-tour', steps })

// Answer a user question
const answer = await gfWithAI.ai.chat('How do I apply a promo code?')
console.log(answer.answer)

GuideBrainOptions

OptionTypeDefaultDescription
intentDebounceMsnumber2000Milliseconds of inactivity before intent detection fires
maxEventBuffernumber200Max user events to buffer before oldest are discarded
autoWatchbooleanfalseAutomatically start watching user events on creation

See Also

Released under the MIT License.