← Public packages
@jpfi/stories
Create personalized Teddy & Pinguin bedtime stories for your child and get the finished text back.
src/get-story-result.ts
25 lines · 1.0 KB · TypeScriptimport { packageStorage } from "kody:runtime";
import type { GetStoryResultInput, StoryGenerationResult } from "./domain";
import { openStorySession } from "./story-run";
/**
* Pick up a story that was still being written when `generate-story` returned `pending`.
* Call this with the `runId` from that result. Pass `maxWaitSeconds: 0` for a single
* status check without blocking. Never creates a story and never spends quota.
*
* @param input - `runId` plus optional `maxWaitSeconds` (default 300, capped at 360)
* @returns `ready` with the story, `pending` if still running, or a failure status
*
* @example
* import getStoryResult from 'kody:@jpfi/stories/get-story-result'
*
* const result = await getStoryResult({ runId: 'a3f1…', maxWaitSeconds: 0 })
* if (result.status === 'pending') console.log(result.nextStep)
*/
export default async function getStoryResult(
input: GetStoryResultInput,
): Promise<StoryGenerationResult> {
const session = await openStorySession(await packageStorage());
return session.resume(input);
}