Skip to content

feat: voice dictation module and multi-entry build - #4

Open
JDeffner wants to merge 2 commits into
core/events-controllerfrom
voice/dictation-build
Open

JDeffner wants to merge 2 commits into
core/events-controllerfrom
voice/dictation-build

Conversation

@JDeffner

@JDeffner JDeffner commented Sep 5, 2026 •

Copy link
Copy Markdown
Owner

Adds ai-form-fill/voice and splits the build into one entry per import path.

  • createDictation() wraps the Web Speech API: live transcript, auto-stop after
    a silence window (silenceMs, 1500 ms default), onEnd exactly once. One click
    covers speak-and-fill. isDictationSupported() is a function, so it is SSR-safe.
  • Build emits dist/ai-form-fill.* and dist/voice.* (ESM, CJS, rolled-up .d.ts).
    main is now dist/ai-form-fill.cjs; the UMD bundle is removed. The declare global re-append moved into the dts afterBuild hook, so the separate
    scripts/append-event-types.js step is gone.
  • The voice example page uses createDictation; new tests cover the dictation
    state machine and the built entry files.

🤖 Generated with Claude Code

Summary by Sourcery

Add a standalone voice dictation API and restructure the package into isolated core and voice builds.

New Features:

  • Add the ai-form-fill/voice entry point with Web Speech dictation, live transcripts, configurable silence auto-stop, error reporting, and SSR-safe support detection.

Enhancements:

  • Split the package into independent core and voice import paths so speech functionality is excluded from the core bundle.
  • Replace the UMD artifact with ESM and CommonJS builds for each public entry point and generate matching rolled-up type declarations.
  • Update the voice example and user-facing guidance to use the dictation API and support one-gesture speak-and-fill workflows.
  • Move global event type preservation into the declaration build hook.

Build:

  • Configure multi-entry ESM, CommonJS, and declaration output and update package exports and the main entry.

Documentation:

  • Document the voice entry point, browser support, privacy considerations, and updated build artifacts.

Tests:

  • Add dictation state-machine tests covering transcript assembly, silence handling, lifecycle callbacks, errors, and browser support.
  • Add build output tests covering entry artifacts, core bundle isolation, exports, and global event declarations.

Chores:

  • Remove the obsolete UMD bundle and standalone event-type append script.

JDeffner and others added 2 commits September 5, 2026 04:46
Add `ai-form-fill/voice`: `createDictation` wraps the Web Speech API and
reports the full transcript on every result, auto-stops after a silence
window and calls `onEnd` exactly once per session. `isDictationSupported`
is a function, so the module is safe to import under SSR.

Build one file set per public import path (`dist/ai-form-fill.*` and
`dist/voice.*`, ESM + CJS + rolled-up `.d.ts`). `main` now points at
`dist/ai-form-fill.cjs`; the UMD bundle is dropped. The `declare global`
re-append moved into the vite-plugin-dts `afterBuild` hook, replacing
`scripts/append-event-types.js`.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @JDeffner, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 3 days and 10 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 5, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR introduces a separately bundled, SSR-safe Web Speech dictation module with automatic silence stopping and exactly-once session completion, updates the example and package documentation to use it, and restructures the build/package exports into independently tested core and voice ESM/CJS/type entry points while removing UMD output.

Sequence diagram for voice dictation and form filling

sequenceDiagram
    actor User
    participant UI as Voice UI
    participant Dictation as createDictation
    participant SpeechAPI as Web Speech API
    participant FormFill as FormFillController

    User->>UI: Click microphone
    UI->>Dictation: start()
    Dictation->>SpeechAPI: start()
    loop Recognition results
        SpeechAPI-->>Dictation: onresult(event)
        Dictation-->>UI: onText(transcript, isFinal)
    end
    Note over Dictation: Silence window expires
    Dictation->>SpeechAPI: stop()
    SpeechAPI-->>Dictation: onend
    Dictation-->>UI: onEnd(finalText)
    UI->>FormFill: fill(finalText)
Loading

State diagram for dictation session lifecycle

stateDiagram-v2
    [*] --> Idle
    Idle --> Listening: start()
    Listening --> Listening: onresult / onText
    Listening --> Stopping: silence window
    Listening --> Stopping: stop()
    Stopping --> Idle: onend / onEnd once
    Idle --> Idle: start() while listening is false
    Listening --> Listening: start() is no-op
Loading

File-Level Changes

Change Details Files
Adds a standalone Web Speech API dictation controller with session lifecycle, transcript callbacks, silence-based stopping, and SSR-safe feature detection.
  • Resolves prefixed and unprefixed speech recognition implementations.
  • Assembles final and interim transcript text and reports it through onText.
  • Supports language, interim-result, silence timeout, completion, and error callbacks.
  • Ensures each session ends with at most one onEnd callback and supports repeated start/stop sessions.
lib/voice/dictation.ts
lib/voice/index.ts
dist/voice.js
dist/voice.cjs
dist/voice.d.ts
Splits the package build and public exports into independent core and voice entry points while removing the UMD artifact.
  • Builds ESM, CJS, and rolled-up declaration outputs for the core and voice entries.
  • Maps the root and ./voice import paths to their corresponding artifacts in package.json.
  • Changes main to the core CommonJS bundle and removes the UMD bundle and append script.
  • Moves global event-type declaration restoration into the vite-plugin-dts afterBuild hook.
vite.config.js
package.json
dist/ai-form-fill.cjs
dist/ai-form-fill.umd.cjs
scripts/append-event-types.js
dist/ai-form-fill.d.ts
Migrates the voice example and documentation to the new dictation API and build layout.
  • Uses createDictation for live textarea updates and automatic transcript-to-form filling.
  • Disables voice controls when feature detection reports no Web Speech API and documents browser/privacy considerations.
  • Documents the new import path, generated artifacts, CommonJS entry, and removal of UMD.
examples/pages/voice.tsx
README.md
CONTRIBUTING.md
CHANGELOG.md
Adds coverage for dictation behavior and generated entry-point artifacts.
  • Tests API detection, recognition configuration, transcript assembly, silence timers, lifecycle idempotence, and error handling.
  • Checks that both entry-point formats and declarations are emitted, speech code remains out of the core bundle, and global event types are preserved.
tests/voice/dictation.test.ts
tests/build/entries.test.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant