Socket
Book a DemoInstallSign in
Socket

@tanstack/ai-svelte

Package Overview
Dependencies
Maintainers
4
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tanstack/ai-svelte

Svelte bindings for TanStack AI

latest
Source
npmnpm
Version
0.2.2
Version published
Maintainers
4
Created
Source

@tanstack/ai-svelte

Svelte bindings for TanStack AI.

Installation

npm install @tanstack/ai-svelte
# or
pnpm add @tanstack/ai-svelte
# or
yarn add @tanstack/ai-svelte

Usage

<script>
  import { createChat, fetchServerSentEvents } from '@tanstack/ai-svelte'

  const chat = createChat({
    connection: fetchServerSentEvents('/api/chat'),
  })
</script>

<div>
  {#each chat.messages as message}
    <div>{message.role}: {message.parts[0].content}</div>
  {/each}

  {#if chat.isLoading}
    <button onclick={chat.stop}>Stop</button>
  {/if}

  <button onclick={() => chat.sendMessage('Hello!')}> Send </button>
</div>

API

createChat(options)

Creates a reactive chat instance. Returns an object with reactive getters and methods:

Reactive Properties (no $ prefix needed):

  • messages - Array of messages in the conversation
  • isLoading - Boolean indicating if a response is being generated
  • error - Current error, if any

Methods:

  • sendMessage(content) - Send a message
  • append(message) - Append a message
  • reload() - Reload the last assistant message
  • stop() - Stop the current response generation
  • clear() - Clear all messages
  • setMessages(messages) - Set messages manually
  • addToolResult(result) - Add a tool result
  • addToolApprovalResponse(response) - Respond to a tool approval request

Svelte 5 Runes

This library uses Svelte 5 runes ($state) internally, providing a clean API where you don't need to use the $ prefix to access reactive state:

<script>
  const chat = createChat({ ... })
  
  // No $ needed - these are reactive getters!
  console.log(chat.messages)
  console.log(chat.isLoading)
</script>

<!-- Reactivity works automatically in templates -->
{#each chat.messages as message}
  ...
{/each}

License

MIT

Keywords

ai

FAQs

Package last updated on 08 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts