feat: add document OCR and offline model archives

This commit is contained in:
lofyer
2026-08-11 16:49:51 +08:00
parent 19a4469561
commit e0e7bc573c
46 changed files with 7831 additions and 85 deletions
@@ -373,6 +373,47 @@ describe('SpeechModelManager downloads', () => {
operations: []
})
})
it('round-trips a verified model through an offline ZIP archive', async () => {
const userData = await temporaryDirectory()
const modelBytes = new TextEncoder().encode('verified model bytes')
const tokenBytes = new TextEncoder().encode('verified tokens')
const catalog = downloadableCatalog(modelBytes, tokenBytes)
const manager = new SpeechModelManager({
userDataDirectory: userData,
catalog,
fetch: vi.fn<typeof fetch>(async (input) => {
const bytes = String(input).endsWith('model.onnx')
? modelBytes
: tokenBytes
return new Response(bytes, {
headers: { 'content-length': String(bytes.byteLength) }
})
})
})
const archive = join(userData, 'speech-model.zip')
await manager.install('download-test-model')
await manager.exportArchive('download-test-model', archive)
await manager.remove('download-test-model')
await expect(
manager.importArchive('download-test-model', archive)
).resolves.toMatchObject({
id: 'download-test-model',
source: 'local',
files: [
{
name: 'model.onnx',
sha256: sha256(modelBytes)
},
{
name: 'tokens.txt',
sha256: sha256(tokenBytes)
}
]
})
})
})
describe('SpeechModelManager local import', () => {