minimal-conversation / src /dispatch.ts
tfrere's picture
tfrere HF Staff
chore(deps): drop @pollen-robotics/reachy-mini-host, use sdk/host subpath
de2d519
/**
* Single entry point for both the host shell and the embedded app.
* See `reachy_mini_emotions/src/dispatch.ts` for the shared rationale.
*
* Vanilla TS variant: this app deliberately doesn't pull in React,
* MUI, or any UI framework. The embed entry is plain DOM + Web Audio,
* so the `@pollen-robotics/reachy-mini-sdk/host/embed` subpath -
* which is framework-free - is the only host-related code that ever
* ships to this Space's embed bundle. The host shell (standalone
* visit) loads `auto.js` once at boot; that bundle carries its own
* React + MUI, isolated from the embed bundle by Vite chunking.
*
* SDK bootstrapping
* ─────────────────
* The host shell and the embed client both consume `window.ReachyMini`
* (constructor injected by the SDK). Historically that global was set
* by a `<script type="module">` tag in `index.html` pointing at a
* jsdelivr CDN URL pinned to a branch; this file now statically imports
* the SDK from the `@pollen-robotics/reachy-mini-sdk` npm package and
* assigns the constructor onto `window` synchronously, BEFORE the
* dynamic import of the host module resolves. We still dispatch the
* `reachymini:ready` event so the embed's wait loop takes its fast
* path immediately.
*/
import { ReachyMini } from "@pollen-robotics/reachy-mini-sdk";
(window as unknown as { ReachyMini: typeof ReachyMini }).ReachyMini = ReachyMini;
window.dispatchEvent(new Event("reachymini:ready"));
const params = new URLSearchParams(window.location.search);
// Accept both `?embedded=1` (current) and the transient `?embed=1`
// used by an intermediate host refactor, so this app boots correctly
// against any combination of mobile build / vendored host dist.
const isEmbed =
params.get("embedded") === "1" || params.get("embed") === "1";
if (isEmbed) {
void import("./embed");
} else {
void import("@pollen-robotics/reachy-mini-sdk/host/auto").then(({ mountHost }) => {
// Local dev shortcuts (see `.env.example` for details):
//
// - `VITE_HF_TOKEN` + `VITE_HF_USERNAME` seed the SDK directly
// so `authenticate()` resolves with no OAuth redirect.
// - `VITE_HF_OAUTH_CLIENT_ID` lets us exercise the real OAuth
// flow against a personal HF OAuth app.
//
// Both are ignored when undefined (production / HF Spaces path
// pulls the client ID from `window.huggingface.variables` set
// by the Docker entrypoint).
const devToken =
import.meta.env.VITE_HF_TOKEN && import.meta.env.VITE_HF_USERNAME
? {
token: import.meta.env.VITE_HF_TOKEN,
userName: import.meta.env.VITE_HF_USERNAME,
}
: undefined;
mountHost({
appName: "Minimal Conversation",
appIconUrl: "/icon.svg",
appEmoji: "πŸŽ™οΈ",
enableMicrophone: true,
clientId: import.meta.env.VITE_HF_OAUTH_CLIENT_ID,
devToken,
});
});
}