import { packageStorage } from "kody:runtime"; import type { GenerateStoryInput, StoryGenerationResult } from "./domain"; import { openStorySession } from "./story-run"; /** * Create a Teddy & Pinguin bedtime story from an idea and wait for the finished prose. * Call this when someone asks for a story. If you already have a `runId` from a `pending` * result, call `get-story-result` instead of this export. * * @param input - `storyIdea` (1–500 chars) plus optional `contentLocale` (default `"de"`), * `targetReadMinutes` (default 8, clamped to 5–12), and `maxWaitSeconds` (default 300, * capped at 360). `0` performs one status read. Optional `series: { start: true }` * starts a Story Series. `series: { continue: seriesId }` or `continueFromStoryId` * writes the next episode. * @returns `ready` with the story, `pending` with a `runId` to resume, or `declined`, * `unavailable`, `disconnected`, `invalid_input` * * @example * import generateStory from 'kody:@jpfi/stories/generate-story' * * const result = await generateStory({ * storyIdea: 'Teddy und Pinguin finden eine Sternenkarte im Schnee', * targetReadMinutes: 10, * }) * if (result.status === 'ready') console.log(result.story.prose) */ export default async function generateStory( input: GenerateStoryInput, ): Promise { const session = await openStorySession(await packageStorage()); return session.generate(input); }