demo · v138
Streaming + shared context
The Summarizer takes a session-wide sharedContext at construction and a per-call context at summarize() — and exposes summarizeStreaming() for incremental output. This is the tool: watch the same article get re-summarised under different audience contexts, token-by-token.
On-device model. First load downloads ~2GB. If the API is missing or the model isn't available, the demo emits a deterministic heuristic stream so the UX surface still demos.
checking availability…
model not downloading
no session yet
Streaming output
Token timeline
What's happening
Summarizer.availability()returnsavailable,downloadable,downloading, orunavailable.Summarizer.create({ sharedContext, type, length, format, monitor })opens a session bound to that context. The monitor reports download progress for first use.session.summarizeStreaming(text, { context, signal })returns aReadableStreamof partial output. Each chunk is appended, not delta-applied — so render the latest chunk wholesale, not concatenated.- An
AbortSignalcancels mid-stream. The session stays usable. - Re-running with the same session reuses the warm model and the sharedContext, but the per-call
contextcan change tone, audience, or constraints each time.
const summarizer = await Summarizer.create({
sharedContext: 'weekly exec update, prefer numbered insights',
type: 'tldr', length: 'medium', format: 'plain-text',
monitor(m) { m.addEventListener('downloadprogress', e => render(e.loaded)); },
});
const stream = summarizer.summarizeStreaming(article, {
context: 'audience knows what speculation rules are',
signal: ac.signal,
});
for await (const chunk of stream) {
out.textContent = chunk; // each chunk is the FULL partial, not a delta
}