JSON Migration -- NOTES

JSON Migration Change Notes

Schemas

(See packages/db/src/schema/)

Every user prompt now has a Zod schema associated with it. The schema provides the contraints that the LLM output must adhere to.

Slidewriter Layout Data

(See apps/generator/tools/generate_slidewriter_enums.py, packages/db/src/schema/slidewriter-layout-data.ts)

I created a tool as part of the exporter to generate a list of valid layout names and placeholders for both the slidedoc and slideshow templates. This is used in the slidewriter schema to enforce what layout names and placeholder names the LLM can use.

Slidewriter Schema

The slidewriter schema is simply an arrry of slides each with a slide number, section number, layout name, and array of placeholders. The placeholder content should be in Markdown format, the exporter will parse the Markdown and adapt it for the PPTX output.

Completion Types

(See apps/app/src/types/completions.ts)

Typescript types for LLM output, should match their corresponding schema. Includes a mapping of Step ID to completion.

LLM Completion API

(See apps/app/src/server/ai/)

The internal functions used to generate LLM completions have been completely refactored and expanded apon.

Front-end Streaming

All front-end LLM calls are streamed, regardless if the request to the LLM provider is streaming. Streams are done via server sent events (SSE). There are five event types...

Completion Properties

These are some of the properties that can be sent to the getCompletion and getChainCompletion functions...

Validation Passes

(See apps/app/src/server/ai/completion.ts:L178)

A validation pass is the process of asking the LLM to redo a completion when a previous completion fails to validate (via Zod). It is allowed three attempts before giving up and throwing an error.

Chain Completions

(See apps/app/src/server/ai/completion.ts:L308)

Allows running multiple LLM calls back to back where the previous output informs subsequent calls. Pass a callback function, onNext to prompt the LLM on what to do next, or return null when finished. The transform callback converts the results of each completion to the single final output.
This still needs more work, it needs more flexibility to manipulate the prompts after each call.

Hooks

(See apps/app/src/hooks/use-ai-completion.ts, etc)

AI completion hooks merged in to use-ai-completion.ts which handles both streaming and non-streaming completions.

User Input

User inputs were changes to simple types that are pointers to elements inside the completion object. Available input types are...

AUDIENCE_SUMMARY is unchanged.

Completion Conversion Functions

(See apps/app/src/util/completion-to-*.ts)

Rather then updating all the front-end components to handle the new completion JSON objects I instead opted to create converters to convert them to the values expected by the front-end components.

Front-end Components

(See apps/app/src/components/project-edit/main/)
table-row-selection-step.tsx, table-cell-selection-step.tsx, etc...

Updated step components to use new hooks. Use completion to table functions to convert completion objects to table data that is used for front-end rendering.

Database

So far no changes have been made to the database schema but the data types being stored in the user_project_steps table is no longer compatible with the previous.

CLI

(See apps/app/src/cli/)

I only built up enough CLI tools to help me test things during the JSON migration project. I think these could be very useful for dev work in the future and taking some time to further build apon them could be great!

Exporter

Support for Markdown has been removed. All data sent to the exporter is now JSON, this includes both the slidewriter data as well as the empathy walk.
The slide data schema has been simplified, instead of having different placeholder data types for text, picture, table, and chart, placeholder content are now represented in plain text and parsed by the exporter.

Placeholders

text: Markdown text. Supports simple Markdown formatting... bold, italtic, lists, line breaks.
table: CSV table.
picture: Plain text file name, path pointing to source slide number / name, URL. Can be parsed from Markdown image link.
chart: Plain text path pointing to source slide number / name. Can be parsed from Markdown link.

Admin

Markdown completions have been removed from the admin as they are no longer saved in Markdown format.