> ## 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.

# Vue

> useKioskSession composable and KioskChat / KioskVoice components for Vue 3 and Nuxt.

## 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 Vue sub-package:

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

> [!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 composable

`useKioskSession` is the core primitive. Use it when you need full control over the chat UI.

```vue theme={null}
<script setup lang="ts">
import { ref } from "vue"
import { useKioskSession } from "@humain/kiosk-js/vue"

const { session, status, openSession, closeSession, sendMessage, stream } =
  useKioskSession({
    credential: "hk_live_your_credential_here",
  })

const messages = ref<Array<{ role: string; content: string }>>([])
const input = ref("")

async function send() {
  const text = input.value.trim()
  if (!text || !session.value) return
  input.value = ""
  messages.value.push({ role: "user", content: text })

  let buffer = ""
  messages.value.push({ role: "assistant", content: "" })

  for await (const event of stream(text)) {
    if (event.type === "chunk") {
      buffer += event.content
      messages.value[messages.value.length - 1].content = buffer
    }
  }
}
</script>

<template>
  <div>
    <button v-if="status === 'idle'" @click="openSession">Start chat</button>
    <div v-for="(msg, i) in messages" :key="i" :class="msg.role">
      {{ msg.content }}
    </div>
    <input v-if="status === 'open'" v-model="input" @keydown.enter="send" />
    <button v-if="status === 'open'" @click="closeSession">End</button>
  </div>
</template>
```

### Composable return values

| Name | Type | Description |
| - | - | - |
| `session` | `Ref<Session \| null>` | The active session, or `null` |
| `status` | `Ref<SessionStatus>` | `"idle"` \| `"opening"` \| `"open"` \| `"closing"` \| `"error"` |
| `openSession` | `() => Promise<void>` | Open a new text session |
| `closeSession` | `() => Promise<void>` | Close the current session |
| `sendMessage` | `(input: string) => Promise<MessageResponse>` | Send and await the full response |
| `stream` | `(input: string) => AsyncIterable<StreamEvent>` | Send and stream chunks |
| `error` | `Ref<KioskError \| null>` | Most recent error, or `null` |

## Drop-in components

For most use cases the pre-built components are the fastest path.

### `<KioskChat>`

```vue theme={null}
<script setup lang="ts">
import { KioskChat } from "@humain/kiosk-js/vue"
</script>

<template>
  <KioskChat
    credential="hk_live_your_credential_here"
    placeholder="Ask me anything…"
    @message="(msg) => console.log('User:', msg)"
    @response="(res) => console.log('AI:', res)"
  />
</template>
```

### `<KioskVoice>`

```vue theme={null}
<script setup lang="ts">
import { KioskVoice } from "@humain/kiosk-js/vue"
</script>

<template>
  <KioskVoice
    credential="hk_live_your_credential_here"
    @transcript="(text) => console.log('Heard:', text)"
    @response="(text) => console.log('AI:', text)"
  />
</template>
```

Both components emit the same events as their React counterparts: `open`, `close`, `message`,
`response`, `error`, `status-change`.

## Advanced topics

> [accordion] Nuxt.js usage
>
> The Humain SDK uses browser APIs (WebSocket, WebRTC). In Nuxt, restrict these components
> to client-side rendering:
>
> ```vue theme={null}
> <!-- pages/support.vue -->
> <template>
>   <ClientOnly>
>     <KioskChat credential="hk_live_your_credential_here" />
>     <template #fallback>
>       <p>Loading chat…</p>
>     </template>
>   </ClientOnly>
> </template>
> ```
>
> Or use the `.client.vue` file naming convention to mark the entire component as
> client-only — Nuxt will not attempt to SSR it.
>
> For credentials, store your live token in `.env` and access it via `useRuntimeConfig()`.
> Do not expose live credentials in `NUXT_PUBLIC_*` variables.

> [accordion] Pinia integration
>
> To share session state across multiple components, store the session in a Pinia store:
>
> ```typescript theme={null}
> import { defineStore } from "pinia"
> import { HumainKioskClient } from "@humain/kiosk-js"
>
> export const useKioskStore = defineStore("kiosk", () => {
>   const client = new HumainKioskClient({ credential: import.meta.env.VITE_HUMAIN_TOKEN })
>   const session = ref(null)
>   const status = ref("idle")
>
>   async function openSession() {
>     status.value = "opening"
>     session.value = await client.openSession()
>     status.value = "open"
>   }
>
>   return { session, status, openSession }
> })
> ```

> [!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.