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…

no session yet

Streaming output

Token timeline

What's happening

  1. Summarizer.availability() returns available, downloadable, downloading, or unavailable.
  2. Summarizer.create({ sharedContext, type, length, format, monitor }) opens a session bound to that context. The monitor reports download progress for first use.
  3. session.summarizeStreaming(text, { context, signal }) returns a ReadableStream of partial output. Each chunk is appended, not delta-applied — so render the latest chunk wholesale, not concatenated.
  4. An AbortSignal cancels mid-stream. The session stays usable.
  5. Re-running with the same session reuses the warm model and the sharedContext, but the per-call context can 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
}

see also