> ## Documentation Index
> Fetch the complete documentation index at: https://humain.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Svelte

> Svelte store and KioskChat / KioskVoice components from @humain/kiosk-js/svelte.

## Install

```bash npm theme={null}
npm install @humain/kiosk-js
```

```bash yarn theme={null}
yarn add @humain/kiosk-js
```

```bash pnpm theme={null}
pnpm add @humain/kiosk-js
```

Import from the Svelte sub-package:

```typescript theme={null}
import { createKioskStore, KioskChat, KioskVoice } from "@humain/kiosk-js/svelte"
```

> [!TIP]
>
> During development, issue an **`hk_test_`** credential from the admin panel instead of a live
> `hk_live_` one. Sandbox is a property of the credential, not a different base URL — you call
> the same `https://api.humain.ai` host either way. Sandbox sessions don't consume production
> LLM credits and aren't billed. See [Sandbox mode](https://humain.mintlify.site/concepts/sandbox-mode.md).

## The store

`createKioskStore` returns a Svelte-compatible readable store with session state and methods.

```svelte theme={null}
<script lang="ts">
  import { onDestroy } from "svelte"
  import { createKioskStore } from "@humain/kiosk-js/svelte"

  const kiosk = createKioskStore({
    credential: "hk_live_your_credential_here",
  })

  let messages: Array<{ role: string; content: string }> = []
  let input = ""

  onDestroy(() => kiosk.close())

  async function send() {
    const text = input.trim()
    if (!text) return
    input = ""
    messages = [...messages, { role: "user", content: text }]

    let buffer = ""
    messages = [...messages, { role: "assistant", content: "" }]

    for await (const event of kiosk.stream(text)) {
      if (event.type === "chunk") {
        buffer += event.content
        messages[messages.length - 1] = { role: "assistant", content: buffer }
        messages = messages // trigger reactivity
      }
    }
  }
</script>

{#if $kiosk.status === "idle"}
  <button on:click={kiosk.open}>Start chat</button>
{:else if $kiosk.status === "open"}
  <div class="messages">
    {#each messages as msg}
      <div class={msg.role}>{msg.content}</div>
    {/each}
  </div>
  <input bind:value={input} on:keydown={(e) => e.key === "Enter" && send()} />
  <button on:click={send}>Send</button>
  <button on:click={kiosk.close}>End</button>
{/if}
```

### Store shape

| Property / method | Type | Description |
| - | - | - |
| `$kiosk.status` | `SessionStatus` | `"idle"` \| `"opening"` \| `"open"` \| `"closing"` \| `"error"` |
| `$kiosk.error` | `KioskError \| null` | Most recent error |
| `kiosk.open()` | `() => Promise<void>` | Open a session |
| `kiosk.close()` | `() => Promise<void>` | Close the session |
| `kiosk.send(input)` | `(string) => Promise<MessageResponse>` | Send and await full response |
| `kiosk.stream(input)` | `(string) => AsyncIterable<StreamEvent>` | Send and stream chunks |

## Drop-in components

### `<KioskChat>`

```svelte theme={null}
<script>
  import { KioskChat } from "@humain/kiosk-js/svelte"
</script>

<KioskChat
  credential="hk_live_your_credential_here"
  placeholder="Ask me anything…"
  on:message={(e) => console.log("User:", e.detail)}
  on:response={(e) => console.log("AI:", e.detail)}
/>
```

### `<KioskVoice>`

```svelte theme={null}
<script>
  import { KioskVoice } from "@humain/kiosk-js/svelte"
</script>

<KioskVoice
  credential="hk_live_your_credential_here"
  on:transcript={(e) => console.log("Heard:", e.detail)}
  on:response={(e) => console.log("AI:", e.detail)}
/>
```

## Advanced topics

> [accordion] SvelteKit usage
>
> Svelte components that use `createKioskStore` or browser APIs cannot run during server-side
> rendering. Wrap them in a dynamic import with `ssr: false`:
>
> ```svelte theme={null}
> <script>
>   import { onMount } from "svelte"
>   let KioskChat
>
>   onMount(async () => {
>     const mod = await import("@humain/kiosk-js/svelte")
>     KioskChat = mod.KioskChat
>   })
> </script>
>
> <svelte:component this={KioskChat} credential="hk_live_…" />
> ```
>
> Or use SvelteKit's `browser` guard:
>
> ```typescript theme={null}
> // +page.svelte
> import { browser } from "$app/environment"
>
> if (browser) {
>   const { createKioskStore } = await import("@humain/kiosk-js/svelte")
>   // use store here
> }
> ```

> [!WARNING]
>
> **Never expose live credentials in client-side code.** Your `hk_live_…` token is a long-lived
> secret. In browser environments, either proxy API calls through your own server or issue an
> `hk_test_…` (sandbox) credential instead for public-facing demos. Treat it like a password.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.