File size: 2,933 Bytes
a75fd0b
 
 
 
 
 
de2d519
 
 
 
 
1247aab
 
 
 
 
 
 
 
 
 
 
 
a75fd0b
1247aab
 
 
 
 
 
a75fd0b
34a05f6
 
 
 
 
a75fd0b
 
 
 
de2d519
797666c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a75fd0b
 
 
 
 
797666c
 
a75fd0b
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
 * 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,
    });
  });
}