|
| 1 | +import { useCopilotAction } from "@copilotkit/react-core"; |
| 2 | +import { SlideModel } from "../types"; |
| 3 | +import { SlidePreview } from "../components/misc/SlidePreview"; |
| 4 | + |
| 5 | +interface AppendSlideParams { |
| 6 | + setSlides: (fn: (slides: SlideModel[]) => SlideModel[]) => void; |
| 7 | + setCurrentSlideIndex: (fn: (i: number) => number) => void; |
| 8 | + slides: SlideModel[]; |
| 9 | +} |
| 10 | + |
| 11 | +export default function useAppendSlide({ |
| 12 | + setSlides, |
| 13 | + setCurrentSlideIndex, |
| 14 | + slides, |
| 15 | +}: AppendSlideParams) { |
| 16 | + useCopilotAction({ |
| 17 | + name: "appendSlide", |
| 18 | + description: |
| 19 | + "Add a slide after all the existing slides. Call this function multiple times to add multiple slides.", |
| 20 | + parameters: [ |
| 21 | + { |
| 22 | + name: "content", |
| 23 | + description: |
| 24 | + "The content of the slide. MUST consist of a title, then an empty newline, then a few bullet points. Always between 1-3 bullet points - no more, no less.", |
| 25 | + }, |
| 26 | + { |
| 27 | + name: "backgroundImageDescription", |
| 28 | + description: |
| 29 | + "What to display in the background of the slide. For example, 'dog', 'house', etc.", |
| 30 | + }, |
| 31 | + { |
| 32 | + name: "spokenNarration", |
| 33 | + description: |
| 34 | + "The text to read while presenting the slide. Should be distinct from the slide's content, " + |
| 35 | + "and can include additional context, references, etc. Will be read aloud as-is. " + |
| 36 | + "Should be a few sentences long, clear, and smooth to read." + |
| 37 | + "DO NOT include meta-commentary, such as 'in this slide', 'we explore', etc.", |
| 38 | + }, |
| 39 | + ], |
| 40 | + |
| 41 | + handler: async ({ content, backgroundImageDescription, spokenNarration }) => { |
| 42 | + const newSlide: SlideModel = { |
| 43 | + content, |
| 44 | + backgroundImageDescription, |
| 45 | + spokenNarration, |
| 46 | + }; |
| 47 | + |
| 48 | + setSlides((slides) => [...slides, newSlide]); |
| 49 | + setCurrentSlideIndex((i) => slides.length); |
| 50 | + }, |
| 51 | + render: (props) => { |
| 52 | + return <SlidePreview {...props.args} done={props.status === "complete"} />; |
| 53 | + }, |
| 54 | + }); |
| 55 | +} |
0 commit comments