Skip to content

Story

The Story class represents a complete generated story — a collection of scenes with metadata.

Import

typescript
import { Story } from '@spectator-ai/core'
import type { StoryInput, StoryData } from '@spectator-ai/core'

Constructor

typescript
new Story(input: StoryInput)

Validates input against StorySchema and freezes the data.

Throws: ValidationError if input is invalid.

Static Methods

Story.fromJSON()

typescript
Story.fromJSON(data: StoryInput): Story

Creates a Story from a plain object. Useful for restoring serialized stories.

typescript
const json = story.toJSON()
const restored = Story.fromJSON(json)

Properties

All properties are readonly getters.

PropertyTypeDescription
scenesScene[]All scenes in order
textstringAll scene text joined with --- separators
titlestring | undefinedStory title
worldWorldData | undefinedWorld used for generation
charactersCharacterData[] | undefinedCharacters used
plotPlotData | undefinedPlot used
wordCountnumberTotal word count across all scenes
sceneCountnumberNumber of scenes
characterStatesCharacterStateData[] | undefinedCharacter states from the final scene

Methods

toJSON()

typescript
story.toJSON(): StoryData

Returns a plain serializable object. Use this for persistence or transmission.

toMarkdown()

typescript
story.toMarkdown(): string

Returns the story as formatted markdown:

  • Title as # heading (if present)
  • Scenes separated by --- horizontal rules
  • Each scene includes location/participants header and text

Types

StoryInput

typescript
interface StoryInput {
  title?: string
  scenes: SceneInput[]
  world?: WorldInput
  characters?: CharacterInput[]
  plot?: PlotInput
  metadata?: Record<string, unknown>
  createdAt: string  // ISO 8601 datetime
}

StoryData

Same shape as StoryInput — the output of Zod parsing.

Released under the MIT License.