Basic Example
A simple fantasy story using presets for the world, plot, and character archetypes.
Source: examples/basic.ts
Code
typescript
import { Engine, World, Character, Plot } from '@spectator-ai/core'
import '@spectator-ai/presets'
const world = World.create({
genre: 'fantasy',
setting: 'A crumbling empire on the edge of chaos, where ancient magic stirs beneath forgotten ruins and rival factions scheme for the throne.',
})
const hero = Character.create({
name: 'Kira',
traits: ['brave', 'curious'],
backstory: 'An orphan raised by monks in a remote mountain monastery, unaware of her true lineage.',
goals: ['Find the truth about her parents'],
})
const villain = Character.create({
name: 'Lord Vorn',
traits: ['ruthless', 'calculating'],
goals: ['Seize the throne'],
}).withRelationship({ target: 'Kira', type: 'nemesis' })
const plot = Plot.template('hero-journey')
const engine = new Engine({ provider: 'anthropic' })
const story = await engine.generate({
world,
characters: [hero, villain],
plot,
})
console.log(story.toMarkdown())Walkthrough
- World — A custom fantasy world with a crumbling empire setting.
- Characters — Two characters: Kira (hero) and Lord Vorn (villain). Vorn has a
nemesisrelationship with Kira via.withRelationship(). - Plot — The
hero-journeytemplate from@spectator-ai/presetsprovides 7 beats from "The Ordinary World" to "The Return". - Engine — Uses Anthropic as the AI provider. Reads
ANTHROPIC_API_KEYfrom the environment. - Output —
story.toMarkdown()returns the entire story as formatted markdown with scene separators.
Run It
bash
npx tsx examples/basic.ts