Skip to content

Commit 99d653c

Browse files
authored
Merge pull request #12 from missing-elements/feat/build-type-files
Copy the skill's type files with a source's problems
2 parents e4530af + b9507d7 commit 99d653c

8 files changed

Lines changed: 319 additions & 43 deletions

File tree

‎README.md‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Docs and tools for the [missing-elements](https://github.com/missing-elements) w
77
| `/` | [src/index.njk](src/index.njk), project list in [src/_data/site.js](src/_data/site.js) |
88
| `/pdfjs-viewer/` | [src/pdfjs-viewer/index.md](src/pdfjs-viewer/index.md) |
99
| `/h5p/build/` | The H5P build page, [src/h5p/build/](src/h5p/build/): see [The H5P build page](#the-h5p-build-page) |
10+
| `/h5p/build/types/` | The h5p-author skill's type files, which the build page copies for the chat, written by [vite.config.ts](vite.config.ts): see [The type files](#the-type-files) |
1011
| `/h5p/bundles/` | The build tool and a library bundle per content type, written by [vite.config.ts](vite.config.ts): see [The bundles](#the-bundles) |
1112

1213
Built with [Eleventy](https://www.11ty.dev/). The pages ship no framework: the only client-side JavaScript is the theme toggle, code-block buttons, the live preview and the build page, which [Vite](https://vite.dev/) bundles with the H5P player.
@@ -51,23 +52,42 @@ Add `try` after the language of a code fence to give it a **▶ Try** button tha
5152

5253
## The H5P build page
5354

54-
`/h5p/build/` is for an AI chat that wrote a source with the [h5p-author skill](https://github.com/missing-elements/h5p-offline-player/tree/main/skills/h5p-author) but cannot build it. ChatGPT's sandbox reaches npm only through OpenAI's own mirror, which was reported refusing every install from July 2026, so `npx @missing-elements/h5p-author` does not run there, and the skill hands over the source and this page's address instead. The page builds with `@missing-elements/h5p-author/browser`, the same build as the command's, and lists every problem at once by its path, ready to copy back into the chat. Its libraries are `@missing-elements/h5p-libraries/install`'s pack, one part per library, so a build fetches only the parts its package needs and carries the editor libraries an H5P site's upload check asks for. The package then plays in the player on the page, and downloads from it.
55+
`/h5p/build/` is for an AI chat that wrote a source with the [h5p-author skill](https://github.com/missing-elements/h5p-offline-player/tree/main/skills/h5p-author) but cannot build it. ChatGPT's sandbox reaches npm only through OpenAI's own mirror, which was reported refusing every install from July 2026, so `npx @missing-elements/h5p-author` does not run there, and the skill hands over the source and this page's address instead. The page builds with `@missing-elements/h5p-author/browser`, the same build as the command's, and lists every problem at once by its path, ready to copy back into the chat with [the type files](#the-type-files) that chat lacked. Its libraries are `@missing-elements/h5p-libraries/install`'s pack, one part per library, so a build fetches only the parts its package needs and carries the editor libraries an H5P site's upload check asks for. The package then plays in the player on the page, and downloads from it.
5556

5657
Nothing leaves the browser. A link can carry the source in its fragment, which no server sees: `/h5p/build/#source=<base64url>`, the bytes being the source's JSON as UTF-8, or that JSON compressed with raw deflate (Node's `zlib.deflateRawSync`, Python's `zlib.compressobj(wbits=-15)`) to keep the link short. A linked source is built at once, unless it names files of its own, which only the person can choose. A source that names a picture by web address gets it only where that host allows CORS.
5758

5859
| File | What it holds |
5960
| --- | --- |
6061
| `src/h5p/build/index.njk` | The page's markup, in the site's layout, and its Content-Security-Policy: GitHub Pages sends no headers, so a `<meta>` tag is the only policy it gets |
6162
| `src/h5p/build/build-page.ts` | The page's wiring: the build, the player, the download, a link's source |
62-
| `src/h5p/build/build-source.ts` | What it does with a source with no DOM: the link's fragment, the files a source names, the text for the chat |
63+
| `src/h5p/build/build-source.ts` | What it does with a source with no DOM: the link's fragment, the files a source names, the content types it is written in, the text for the chat |
6364
| `src/assets/site.css` | Its styles, under *H5P build page* |
64-
| `vite.config.ts` | The page's script, `/h5p/build/build-page.js`, with the player, its runtime, the pack and their licence files in `/h5p/assets/` |
65-
| `e2e/`, `playwright.config.ts` | The browser tests: a pasted source, one from a link and one with a file of its own build, play and download; a source's problems are listed for the chat; `/h5p/bundles/` serves every bundle and part, and its tool and a bundle build a quiz in an empty folder |
65+
| `vite.config.ts` | The page's script, `/h5p/build/build-page.js`, with the player, its runtime, the pack and their licence files in `/h5p/assets/`, and the type files in `/h5p/build/types/` |
66+
| `e2e/`, `playwright.config.ts` | The browser tests: a pasted source, one from a link and one with a file of its own build, play and download; a source's problems are listed, and copied for the chat with the type files; `/h5p/bundles/` serves every bundle and part, and its tool and a bundle build a quiz in an empty folder |
6667

6768
The player's Service Worker is in `/h5p/assets/` too, so its scope is `/h5p/assets/h5p/`: no other page of the site is under it. The address names who runs the page, as H5P Group's trademark policy asks of a name with "H5P" in it, and the page uses the word descriptively.
6869

6970
The page and the bundles were embed-my.github.io's `/build` and `/bundles/` until 2026-11-10. Its `/build` becomes a redirect here that keeps the fragment, so the links chats wrote before still build: [embed-my/embed-my.github.io#18](https://github.com/embed-my/embed-my.github.io/pull/18), a step of its own, deployed once this page is live.
7071

72+
### The type files
73+
74+
A chat in a browser, such as Gemini in Chrome, has the skill's text and none of its files, and can run nothing. It guesses how a content type is written, and each round of problems tells it the names of one level. So **Copy the problems for the chat** copies more than the list: after the problems come the skill's type files of the source's own content type and of the libraries it names, each a type's notes, an example and its fields.
75+
76+
```
77+
The build page found 2 problems in the source. Fix them all and write the whole source again:
78+
- params.chapters[0]: is the params of sub-content, without the sub-content around them: write params.chapters[0] as { "library": "H5P.Column", "params": { "content": … } }
79+
- params.chapters[0].metadata.title: is required: the chapter's name in the table of contents
80+
81+
How these content types are written, from the h5p-author skill's type files:
82+
83+
# Interactive Book (H5P.InteractiveBook)
84+
…
85+
```
86+
87+
`vite.config.ts` writes them to `/h5p/build/types/<Type>.md` from the pinned `@missing-elements/h5p-author`, which carries them since 0.7.0, with `index.json`, the author's version and the types there is a file for. They are that release's, so they describe the fields of the build the page runs, and a Dependabot update of the package moves both. The page fetches them when it lists a source's problems, so the copy is written within the button's press; where they cannot be fetched, the problems are copied alone.
88+
89+
Measured in [h5p-offline-player#172](https://github.com/missing-elements/h5p-offline-player/issues/172) on the weakest Claude model, Haiku 5.5, in that position: with the files beside the first problems, 42 of 46 sources of 23 content types were right by its second reply, and 29 without them. The page copies that text byte for byte: the 39 sources that failed their first build in the test's runs were built again on this page, and all but one copied what the model had been given, the one a Game Map whose problems 0.7.0 says better.
90+
7191
## The bundles
7292

7393
`/h5p/bundles/` is for a chat that runs Node and can fetch a file but reaches no npm registry, as ChatGPT's sandbox can: its download tool takes a file the browsing tool has opened. There the h5p-author skill fetches two files, the build tool and the bundle of the source's content type, unzips the bundle and builds with `node h5p-author.mjs build source.json course.h5p --libraries parts`. The chat then sees every problem itself, fixes its source and hands over the package; the build page stays for a chat that can fetch nothing.

‎e2e/build.spec.ts‎

Lines changed: 132 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
import { readdir, readFile } from 'node:fs/promises'
12
import { deflateRawSync } from 'node:zlib'
2-
import { expect, test, type Page } from '@playwright/test'
3+
import { expect, test, type APIRequestContext, type Page } from '@playwright/test'
34

45
/*
56
* The build page, /h5p/build/, in a real browser against the built site: a source pasted, opened
67
* from a link or naming a file of its own becomes a package that plays on the page and downloads
7-
* from it, and a source with problems gets them listed, all at once, for the chat that wrote it.
8-
* Every library comes from this origin, and any Content-Security-Policy violation or page error
9-
* fails the test.
8+
* from it, and a source with problems gets them listed, all at once, for the chat that wrote it,
9+
* and copied with the h5p-author skill's type files, which that chat lacked. Every library comes
10+
* from this origin, and any Content-Security-Policy violation or page error fails the test.
1011
*/
1112

1213
const RIVERS = {
@@ -37,6 +38,19 @@ function watch(page: Page, baseURL: string | undefined): { problems: string[], e
3738
return { problems, elsewhere }
3839
}
3940

41+
/** What the copy says before the type files, and a type file as this site serves it, as the copy carries it. */
42+
const TYPES_HEADING = "How these content types are written, from the h5p-author skill's type files:"
43+
const typeFile = async (request: APIRequestContext, type: string): Promise<string> => {
44+
const response = await request.get(`/h5p/build/types/${type}.md`)
45+
expect(response.ok(), type).toBe(true)
46+
return (await response.text()).trim()
47+
}
48+
const copied = async (page: Page): Promise<string> => {
49+
await page.locator('#copy-problems').click()
50+
await expect(page.locator('#copy-result')).toHaveText('Copied.')
51+
return page.evaluate(() => navigator.clipboard.readText())
52+
}
53+
4054
const playerState = (page: Page) => page.locator('h5p-player').evaluate((element: HTMLElement & { state?: string }) => element.state)
4155

4256
async function expectPlays(page: Page): Promise<void> {
@@ -77,7 +91,7 @@ test('a pasted source builds, plays and downloads', async ({ page, baseURL }) =>
7791
expect(problems, problems.join('\n')).toEqual([])
7892
})
7993

80-
test('a source with problems gets them all listed, ready for the chat', async ({ page, context, baseURL }) => {
94+
test('a source with problems gets them all listed, ready for the chat', async ({ page, context, request, baseURL }) => {
8195
const { problems } = watch(page, baseURL)
8296
await context.grantPermissions(['clipboard-read', 'clipboard-write'])
8397
await page.goto('/h5p/build/')
@@ -91,20 +105,127 @@ test('a source with problems gets them all listed, ready for the chat', async ({
91105
await expect(listed.locator('code', { hasText: /^title$/ })).toHaveCount(1)
92106
await expect(page.locator('#play-step')).toBeHidden()
93107

94-
await page.locator('#copy-problems').click()
95-
await expect(page.locator('#copy-result')).toHaveText('Copied.')
96-
const copied = await page.evaluate(() => navigator.clipboard.readText())
97-
expect(copied).toMatch(/^The build page found \d+ problems in the source\. Fix them all and write the whole source again:\n- /)
98-
expect(copied).toContain('- colour: ')
108+
// The copy is the problems, then how the source's content type is written: its type file, whole.
109+
await expect(page.locator('#copy-types')).toHaveText('The copy also carries the skill’s notes on H5P.Blanks, with its fields and an example, so the chat does not have to guess.')
110+
const text = await copied(page)
111+
expect(text).toMatch(/^The build page found \d+ problems in the source\. Fix them all and write the whole source again:\n- /)
112+
expect(text).toContain('- colour: ')
113+
const [list, files] = text.split(`\n\n${TYPES_HEADING}\n\n`)
114+
expect(list.split('\n').slice(1).every((line) => line.startsWith('- ')), list).toBe(true)
115+
expect(files).toBe(await typeFile(request, 'H5P.Blanks'))
99116

100-
// Text that is not JSON is a problem of its own, said where it is.
117+
// Text that is not JSON is a problem of its own, said where it is, and names no content type.
101118
await page.locator('#source').fill('{ "type": "H5P.Blanks", ')
102119
await page.locator('#build').click()
103120
await expect(listed).toHaveCount(1)
104121
await expect(listed.first()).toContainText('is not valid JSON')
122+
await expect(page.locator('#copy-types')).toBeHidden()
123+
expect(await copied(page)).toMatch(/^The build page found 1 problem in the source\. Fix them all and write the whole source again:\n- source: is not valid JSON[^\n]*$/)
124+
expect(problems, problems.join('\n')).toEqual([])
125+
})
126+
127+
test('the copy carries the type files of the source’s type and of the libraries it names', async ({ page, context, request, baseURL }) => {
128+
const { problems } = watch(page, baseURL)
129+
await context.grantPermissions(['clipboard-read', 'clipboard-write'])
130+
// What a chat with the skill's text and no type file wrote (h5p-offline-player#172): a chapter
131+
// without the H5P.Column around it. H5P.Table has no type file, and a library named twice has one.
132+
const text = (words: string) => ({ library: 'H5P.AdvancedText', params: { text: words } })
133+
const book = {
134+
type: 'H5P.InteractiveBook', title: 'Rivers', language: 'en', license: 'CC BY', authors: [{ name: 'Ann Author', role: 'Author' }],
135+
params: {
136+
chapters: [{
137+
content: [
138+
text('The Danube flows into the Black Sea.'),
139+
{ library: 'H5P.MultiChoice 1.16', params: { question: 'Where does the Danube end?', answers: [{ text: 'The Black Sea', correct: true }, { text: 'The North Sea', correct: false }] } },
140+
{ library: 'H5P.Table', params: { text: '<table><tbody><tr><td>Danube</td></tr></tbody></table>' } },
141+
text('The Rhine flows into the North Sea.')
142+
]
143+
}]
144+
}
145+
}
146+
await page.goto('/h5p/build/')
147+
await page.locator('#source').fill(JSON.stringify(book))
148+
await page.locator('#build').click()
149+
await expect(page.locator('#status')).toHaveAttribute('data-state', 'error')
150+
// The build says what to write, as h5p-author 0.7.0 does.
151+
await expect(page.locator('#problems li').first()).toContainText('write params.chapters[0] as { "library": "H5P.Column", "params": { "content": … } }')
152+
await expect(page.locator('#copy-types')).toHaveText('The copy also carries the skill’s notes on H5P.InteractiveBook, H5P.AdvancedText and H5P.MultiChoice, with their fields and an example, so the chat does not have to guess.')
153+
const [list, files] = (await copied(page)).split(`\n\n${TYPES_HEADING}\n\n`)
154+
expect(list).toContain('- params.chapters[0]: is the params of sub-content')
155+
// The source's own type first, then the libraries in the order it names them.
156+
expect(files).toBe([await typeFile(request, 'H5P.InteractiveBook'), await typeFile(request, 'H5P.AdvancedText'), await typeFile(request, 'H5P.MultiChoice')].join('\n\n---\n\n'))
157+
158+
// A type the pack does not have has no file: its problems are copied alone.
159+
await page.locator('#source').fill(JSON.stringify({ ...book, type: 'H5P.ImageChoice', params: {} }))
160+
await page.locator('#build').click()
161+
await expect(page.locator('#problems li')).not.toHaveCount(0)
162+
const alone = await copied(page)
163+
expect(alone).toMatch(/^The build page found \d+ problems? in the source\./)
164+
expect(alone).not.toContain(TYPES_HEADING)
165+
await expect(page.locator('#copy-types')).toBeHidden()
105166
expect(problems, problems.join('\n')).toEqual([])
106167
})
107168

169+
test('the problems are copied alone where the type files cannot be fetched, and with them once they can', async ({ page, context, request }) => {
170+
await context.grantPermissions(['clipboard-read', 'clipboard-write'])
171+
await page.route('**/h5p/build/types/**', (route) => route.fulfill({ status: 503, body: 'unavailable' }))
172+
await page.goto('/h5p/build/')
173+
const { title: _title, ...untitled } = RIVERS
174+
await page.locator('#source').fill(JSON.stringify(untitled))
175+
await page.locator('#build').click()
176+
await expect(page.locator('#problems li')).toHaveCount(1)
177+
expect(await copied(page)).toMatch(/^The build page found 1 problem in the source\. Fix them all and write the whole source again:\n- title: [^\n]*$/)
178+
await expect(page.locator('#copy-types')).toBeHidden()
179+
180+
await page.unroute('**/h5p/build/types/**')
181+
await page.locator('#build').click()
182+
await expect(page.locator('#copy-types')).toContainText('H5P.Blanks')
183+
expect((await copied(page)).endsWith(`\n\n${TYPES_HEADING}\n\n${await typeFile(request, 'H5P.Blanks')}`)).toBe(true)
184+
})
185+
186+
test('type files that arrive once newer problems are shown are not copied with those', async ({ page, context }) => {
187+
await context.grantPermissions(['clipboard-read', 'clipboard-write'])
188+
let release = (): void => {}
189+
const held = new Promise<void>((resolve) => { release = resolve })
190+
await page.route('**/h5p/build/types/H5P.Blanks.md', async (route) => {
191+
await held
192+
await route.continue()
193+
})
194+
await page.goto('/h5p/build/')
195+
const { title: _title, ...untitled } = RIVERS
196+
await page.locator('#source').fill(JSON.stringify(untitled))
197+
await page.locator('#build').click()
198+
await expect(page.locator('#problems li code')).toHaveText('title')
199+
// Its type file is on its way when the next source's problems replace these: text that names no type.
200+
await page.locator('#source').fill('{ "type": ')
201+
await page.locator('#build').click()
202+
await expect(page.locator('#problems li')).toContainText('is not valid JSON')
203+
const arrived = page.waitForResponse('**/h5p/build/types/H5P.Blanks.md')
204+
release()
205+
await (await arrived).finished()
206+
// Long enough for the page to have taken the file, had it not dropped it.
207+
await page.waitForTimeout(300)
208+
await expect(page.locator('#copy-types')).toBeHidden()
209+
expect(await copied(page)).not.toContain(TYPES_HEADING)
210+
})
211+
212+
test('the type files are served as the pinned author package carries them', async ({ request }) => {
213+
const folder = new URL('../node_modules/@missing-elements/h5p-author/references/types/', import.meta.url)
214+
const names = (await readdir(folder)).filter((name) => name.endsWith('.md')).sort()
215+
const listing = await (await request.get('/h5p/build/types/index.json')).json() as { author: string, types: string[] }
216+
const bundles = await (await request.get('/h5p/bundles/index.json')).json() as { author: string }
217+
// The same release as the build's, so the files describe the fields this page's build takes.
218+
expect(listing.author).toBe(bundles.author)
219+
expect(listing.types).toEqual(names.map((name) => name.slice(0, -'.md'.length)))
220+
// Every content type the skill lists, and the parts other content holds.
221+
expect(listing.types.length).toBeGreaterThanOrEqual(32)
222+
for (const type of listing.types) {
223+
const response = await request.get(`/h5p/build/types/${type}.md`)
224+
expect(response.ok(), type).toBe(true)
225+
expect(await response.text(), type).toBe(await readFile(new URL(`${type}.md`, folder), 'utf8'))
226+
}
227+
})
228+
108229
test('a link carrying the source builds it at once, deflated or not', async ({ page, baseURL }) => {
109230
const { problems, elsewhere } = watch(page, baseURL)
110231
const deflated = deflateRawSync(Buffer.from(JSON.stringify(RIVERS))).toString('base64url')

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
"vite": "8.3.5"
2323
},
2424
"dependencies": {
25-
"@missing-elements/h5p-author": "0.6.0",
25+
"@missing-elements/h5p-author": "0.7.0",
2626
"@missing-elements/h5p-libraries": "1.1.0",
27-
"@missing-elements/h5p-offline-player": "1.5.1",
27+
"@missing-elements/h5p-offline-player": "1.6.0",
2828
"@missing-elements/h5p-runtime": "1.0.1",
2929
"@missing-elements/pdfjs-viewer": "4.5.0"
3030
}

0 commit comments

Comments
 (0)