@blockslides/ai-context 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +36 -0
- package/README.md +268 -0
- package/dist/index.cjs +806 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +704 -0
- package/dist/index.d.ts +704 -0
- package/dist/index.js +781 -0
- package/dist/index.js.map +1 -0
- package/package.json +44 -0
- package/src/bundles/v1/all.ts +26 -0
- package/src/bundles/v1/allContexts.ts +32 -0
- package/src/bundles/v1/allSchemas.ts +20 -0
- package/src/bundles/v1/imageEditing.ts +5 -0
- package/src/bundles/v1/index.ts +6 -0
- package/src/bundles/v1/minimalCreate.ts +5 -0
- package/src/contexts/v1/blockquote.ts +14 -0
- package/src/contexts/v1/bulletList.ts +15 -0
- package/src/contexts/v1/codeBlock.ts +15 -0
- package/src/contexts/v1/column.ts +15 -0
- package/src/contexts/v1/core.ts +17 -0
- package/src/contexts/v1/editingRules.ts +9 -0
- package/src/contexts/v1/hardBreak.ts +14 -0
- package/src/contexts/v1/heading.ts +15 -0
- package/src/contexts/v1/horizontalRule.ts +14 -0
- package/src/contexts/v1/image.ts +17 -0
- package/src/contexts/v1/imageBlock.ts +27 -0
- package/src/contexts/v1/index.ts +19 -0
- package/src/contexts/v1/output.fullDocument.ts +8 -0
- package/src/contexts/v1/paragraph.ts +14 -0
- package/src/contexts/v1/row.ts +17 -0
- package/src/contexts/v1/sizing.ts +8 -0
- package/src/contexts/v1/slide.ts +16 -0
- package/src/contexts/v1/style.ts +8 -0
- package/src/contexts/v1/youtube.ts +18 -0
- package/src/examples/v1/flyers.ts +30 -0
- package/src/examples/v1/index.ts +4 -0
- package/src/examples/v1/slides.ts +31 -0
- package/src/index.ts +7 -0
- package/src/recipes/v1/addTwoColumns.ts +13 -0
- package/src/recipes/v1/createSlide.ts +29 -0
- package/src/recipes/v1/editImageToCover.ts +13 -0
- package/src/recipes/v1/index.ts +5 -0
- package/src/schemas/v1/blockquote.schema.json +16 -0
- package/src/schemas/v1/bulletList.schema.json +16 -0
- package/src/schemas/v1/codeBlock.schema.json +19 -0
- package/src/schemas/v1/column.schema.json +23 -0
- package/src/schemas/v1/hardBreak.schema.json +16 -0
- package/src/schemas/v1/heading.schema.json +23 -0
- package/src/schemas/v1/horizontalRule.schema.json +16 -0
- package/src/schemas/v1/image.schema.json +23 -0
- package/src/schemas/v1/imageBlock.schema.json +31 -0
- package/src/schemas/v1/index.ts +14 -0
- package/src/schemas/v1/paragraph.schema.json +16 -0
- package/src/schemas/v1/row.schema.json +22 -0
- package/src/schemas/v1/slide.schema.json +32 -0
- package/src/schemas/v1/youtube.schema.json +22 -0
- package/src/types/v1.ts +55 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 BlockSlides
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Acknowledgments
|
|
26
|
+
|
|
27
|
+
This project includes code and patterns adapted from [Tiptap](https://tiptap.dev),
|
|
28
|
+
an open-source headless editor framework for web artisans.
|
|
29
|
+
|
|
30
|
+
**Tiptap License:**
|
|
31
|
+
|
|
32
|
+
- Copyright (c) 2025, Tiptap GmbH
|
|
33
|
+
- Licensed under MIT License
|
|
34
|
+
- Original source: https://github.com/ueberdosis/tiptap
|
|
35
|
+
|
|
36
|
+
See `_tiptap/LICENSE.md` for the full Tiptap license.
|
package/README.md
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
## @blockslides/ai-context
|
|
2
|
+
|
|
3
|
+
Versioned context atoms, examples, schemas, and types for guiding LLMs to create/edit **BlockSlides JSON** (slides, rows, columns, image blocks, sizing, etc).
|
|
4
|
+
|
|
5
|
+
This package is designed to be read by **LLMs** and **humans**: it gives you ready‑made prompt text, examples, and schemas so another AI can reliably generate and edit BlockSlides documents.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
### Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @blockslides/ai-context
|
|
13
|
+
# or
|
|
14
|
+
npm install @blockslides/ai-context
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
### Exports overview
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import {
|
|
23
|
+
contextsV1,
|
|
24
|
+
bundlesV1,
|
|
25
|
+
examplesV1,
|
|
26
|
+
recipesV1,
|
|
27
|
+
schemasV1,
|
|
28
|
+
// Types
|
|
29
|
+
SizeKey,
|
|
30
|
+
SlideAttrs,
|
|
31
|
+
RowAttrs,
|
|
32
|
+
ColumnAttrs,
|
|
33
|
+
ImageBlockAttrs,
|
|
34
|
+
} from '@blockslides/ai-context';
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
- **contextsV1**: Small, focused instruction strings that describe:
|
|
38
|
+
- **`core`**: global JSON rules and invariants.
|
|
39
|
+
- **`fullDocument`**: how the root `doc` and its top‑level children are shaped.
|
|
40
|
+
- **`slide`**, **`row`**, **`column`**, **`imageBlock`**: contracts for each node.
|
|
41
|
+
- **`style`**: how to use styling and `className` safely (e.g. Tailwind).
|
|
42
|
+
- **`editingRules`**: do/don’t rules for editing an existing document.
|
|
43
|
+
- **`sizing`**: allowed slide `size` values and when to use them.
|
|
44
|
+
|
|
45
|
+
- **bundlesV1**: Pre‑composed context strings:
|
|
46
|
+
- **`minimalCreate`** – core + full document + slide/row/column/style.
|
|
47
|
+
Good default for “create a deck” flows.
|
|
48
|
+
- **`imageEditing`** – core + full document + imageBlock + editingRules.
|
|
49
|
+
Good for “edit image blocks” flows.
|
|
50
|
+
- **`all`** – everything combined (heavier, but fully featured).
|
|
51
|
+
|
|
52
|
+
- **examplesV1**:
|
|
53
|
+
- **`slides`**, **`flyers`** – realistic BlockSlides JSON examples that models can imitate.
|
|
54
|
+
|
|
55
|
+
- **recipesV1**:
|
|
56
|
+
- **`createSlide`**, **`addTwoColumns`**, **`editImageToCover`** – textual recipes describing *how* to use the schema to perform common operations.
|
|
57
|
+
|
|
58
|
+
- **schemasV1**:
|
|
59
|
+
- JSON Schemas for validating and tooling (`slide`, `row`, `column`, `imageBlock`, etc.).
|
|
60
|
+
|
|
61
|
+
- **Types**:
|
|
62
|
+
- `SizeKey`, `SlideAttrs`, `RowAttrs`, `ColumnAttrs`, `ImageBlockAttrs` – TypeScript types that describe the attributes an LLM should output.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
### Quick start: build a system prompt for an LLM
|
|
67
|
+
|
|
68
|
+
The typical pattern is to build a **single context string** and feed it as the **system prompt** (or “instructions”) to your LLM.
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { bundlesV1, examplesV1 } from '@blockslides/ai-context';
|
|
72
|
+
|
|
73
|
+
// Use a prebuilt bundle
|
|
74
|
+
const baseCtx = bundlesV1.minimalCreate;
|
|
75
|
+
|
|
76
|
+
// Optionally extend with examples
|
|
77
|
+
const systemContext = [
|
|
78
|
+
'You are a BlockSlides layout assistant.',
|
|
79
|
+
'You ONLY output JSON (no prose), following the schemas described below.',
|
|
80
|
+
'',
|
|
81
|
+
baseCtx,
|
|
82
|
+
examplesV1.slides, // optional, but helps models learn good patterns
|
|
83
|
+
].join('\n\n');
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Now pass `systemContext` to your LLM:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
const messages = [
|
|
90
|
+
{ role: 'system', content: systemContext },
|
|
91
|
+
{
|
|
92
|
+
role: 'user',
|
|
93
|
+
content:
|
|
94
|
+
'Create a 3-slide presentation about electric vehicles. ' +
|
|
95
|
+
'Use slide size "16x9" for all slides. Return ONLY JSON.',
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
|
|
99
|
+
// Call your LLM client of choice with these messages.
|
|
100
|
+
// Then JSON.parse the result and feed it to BlockSlides.
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
### Using atomic contexts directly
|
|
106
|
+
|
|
107
|
+
If you need more control, you can assemble your own context from the atomic pieces:
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import { contextsV1, examplesV1 } from '@blockslides/ai-context';
|
|
111
|
+
|
|
112
|
+
const ctx = [
|
|
113
|
+
contextsV1.core,
|
|
114
|
+
contextsV1.fullDocument,
|
|
115
|
+
contextsV1.slide,
|
|
116
|
+
contextsV1.row,
|
|
117
|
+
contextsV1.column,
|
|
118
|
+
contextsV1.style,
|
|
119
|
+
contextsV1.sizing,
|
|
120
|
+
examplesV1.slides,
|
|
121
|
+
].join('\n\n');
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
This is equivalent in spirit to `bundlesV1.minimalCreate`, but allows you to add/remove individual contexts as your use‑case evolves.
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
### Prebuilt bundles (recommended starting points)
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
import { bundlesV1 } from '@blockslides/ai-context';
|
|
132
|
+
|
|
133
|
+
// Minimal set for creating new documents
|
|
134
|
+
const createCtx = bundlesV1.minimalCreate;
|
|
135
|
+
|
|
136
|
+
// Focused set for editing image blocks in an existing doc
|
|
137
|
+
const imageEditingCtx = bundlesV1.imageEditing;
|
|
138
|
+
|
|
139
|
+
// Full set of all V1 contexts
|
|
140
|
+
const fullCtx = bundlesV1.all;
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Use these directly as your system prompt content, or combine them with additional project‑specific instructions.
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
### Editing existing documents
|
|
148
|
+
|
|
149
|
+
For “edit this JSON” workflows, include **editing rules** and the current document:
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
import { bundlesV1 } from '@blockslides/ai-context';
|
|
153
|
+
|
|
154
|
+
const editCtx = [
|
|
155
|
+
bundlesV1.imageEditing, // core + fullDocument + imageBlock + editingRules
|
|
156
|
+
].join('\n\n');
|
|
157
|
+
|
|
158
|
+
const messages = [
|
|
159
|
+
{ role: 'system', content: editCtx },
|
|
160
|
+
{
|
|
161
|
+
role: 'user',
|
|
162
|
+
content: [
|
|
163
|
+
'Here is the current document JSON:',
|
|
164
|
+
JSON.stringify(currentDoc, null, 2),
|
|
165
|
+
'',
|
|
166
|
+
'Task: Change only the first slide’s image to layout="cover" and fullBleed=true.',
|
|
167
|
+
'Return the FULL updated JSON document.',
|
|
168
|
+
].join('\n'),
|
|
169
|
+
},
|
|
170
|
+
];
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
The LLM is instructed to **minimize changes** and respect the existing IDs/structure.
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
### Using recipes to steer behavior
|
|
178
|
+
|
|
179
|
+
Recipes are textual “playbooks” that describe multi‑step operations.
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
import { bundlesV1, recipesV1 } from '@blockslides/ai-context';
|
|
183
|
+
|
|
184
|
+
const systemContext = [
|
|
185
|
+
bundlesV1.minimalCreate,
|
|
186
|
+
'',
|
|
187
|
+
'You may follow these high-level recipes:',
|
|
188
|
+
recipesV1.createSlide,
|
|
189
|
+
recipesV1.addTwoColumns,
|
|
190
|
+
].join('\n\n');
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
This helps the model understand how to translate user intentions (“add two columns below the hero image”) into valid BlockSlides JSON operations.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
### Validating AI output with schemas
|
|
198
|
+
|
|
199
|
+
`schemasV1` exposes JSON Schemas you can plug into tools like AJV, Zod (via adapters), or your own validator.
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
import { schemasV1 } from '@blockslides/ai-context';
|
|
203
|
+
import Ajv from 'ajv';
|
|
204
|
+
|
|
205
|
+
const ajv = new Ajv({ allErrors: true });
|
|
206
|
+
const validateSlide = ajv.compile(schemasV1.slide);
|
|
207
|
+
|
|
208
|
+
const isValid = validateSlide(candidateSlide);
|
|
209
|
+
|
|
210
|
+
if (!isValid) {
|
|
211
|
+
console.error('Invalid slide:', validateSlide.errors);
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
You can validate:
|
|
216
|
+
|
|
217
|
+
- Individual nodes (`schemasV1.slide`, `schemasV1.row`, `schemasV1.column`, `schemasV1.imageBlock`).
|
|
218
|
+
- Or a whole document by:
|
|
219
|
+
- Ensuring `doc.type === "doc"`.
|
|
220
|
+
- Ensuring each top‑level node validates against `schemasV1.slide`.
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
### Types for tooling and safety
|
|
225
|
+
|
|
226
|
+
The TypeScript types exported from `types/v1` mirror what the LLM is expected to produce:
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
import {
|
|
230
|
+
SizeKey,
|
|
231
|
+
SlideAttrs,
|
|
232
|
+
RowAttrs,
|
|
233
|
+
ColumnAttrs,
|
|
234
|
+
ImageBlockAttrs,
|
|
235
|
+
} from '@blockslides/ai-context';
|
|
236
|
+
|
|
237
|
+
const size: SizeKey = '16x9'; // or '4x3', 'a4-portrait', etc.
|
|
238
|
+
|
|
239
|
+
const slideAttrs: SlideAttrs = {
|
|
240
|
+
id: 'intro',
|
|
241
|
+
size: '16x9',
|
|
242
|
+
className: 'bg-slate-950 text-white',
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
const imageAttrs: ImageBlockAttrs = {
|
|
246
|
+
src: 'https://example.com/hero.jpg',
|
|
247
|
+
layout: 'cover',
|
|
248
|
+
align: 'center',
|
|
249
|
+
fullBleed: true,
|
|
250
|
+
};
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
Use these in your app or integration layer to:
|
|
254
|
+
|
|
255
|
+
- Strongly type the content you send to / receive from the model.
|
|
256
|
+
- Drive form builders or visual editors that sit in front of the LLM.
|
|
257
|
+
- Narrow the surface area of what the model is allowed to change.
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
### Versioning notes (for humans and AIs)
|
|
262
|
+
|
|
263
|
+
- All exports in this package are **versioned** under `*V1` (e.g. `contextsV1`, `bundlesV1`).
|
|
264
|
+
- When constructing prompts, it’s a good idea to say explicitly:
|
|
265
|
+
**“You are using @blockslides/ai-context v1.”**
|
|
266
|
+
- If/when a V2 is added, you will be able to run V1 and V2 side‑by‑side by choosing the appropriate namespace.
|
|
267
|
+
|
|
268
|
+
This README is safe for LLM ingestion: you can copy its text directly into a system prompt to teach a new AI how to work with BlockSlides JSON via `@blockslides/ai-context`.
|