ainative-svelte-sdk

Use @ainative/svelte-sdk to add AI chat to Svelte/SvelteKit apps. Use when (1) Installing @ainative/svelte-sdk, (2) Using Svelte stores for chat state, (3) Configuring AINative in a Svelte app, (4) Displaying chat messages reactively, (5) Handling loading and error states with Svelte stores. Published npm package v1.0.0.

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "ainative-svelte-sdk" with this command: npx skills add urbantech/ainative-svelte-sdk

@ainative/svelte-sdk

Svelte stores and utilities for AINative chat completions.

Install

npm install @ainative/svelte-sdk

Configure

// src/lib/ainative.ts
import { setAINativeConfig } from '@ainative/svelte-sdk';

setAINativeConfig({
  apiKey: import.meta.env.VITE_AINATIVE_API_KEY,
  baseUrl: 'https://api.ainative.studio',
});

Call this once in your app root (+layout.svelte or App.svelte).

createChatStore

<!-- src/lib/Chat.svelte -->
<script lang="ts">
  import { createChatStore } from '@ainative/svelte-sdk';

  const chat = createChatStore({
    model: 'claude-3-5-sonnet-20241022',
  });

  let input = '';

  async function send() {
    if (!input.trim()) return;
    const userMsg = { role: 'user' as const, content: input };
    input = '';
    await chat.sendMessage([...$chat.messages, userMsg]);
  }
</script>

{#each $chat.messages as msg}
  <div class="message {msg.role}">
    <strong>{msg.role}:</strong> {msg.content}
  </div>
{/each}

{#if $chat.isLoading}
  <p>Thinking...</p>
{/if}

{#if $chat.error}
  <p class="error">Error: {$chat.error.message}</p>
{/if}

<input bind:value={input} on:keydown={(e) => e.key === 'Enter' && send()} />
<button on:click={send} disabled={$chat.isLoading}>Send</button>

Store Shape

$chat is a reactive store with this shape:

FieldTypeDescription
messagesMessage[]Full conversation history
isLoadingbooleanTrue while request in flight
errorAINativeError | nullLast error

createChatStore Options

OptionTypeDefaultDescription
modelstringModel ID
initialMessagesMessage[][]Seed conversation

SvelteKit — Server Route

For server-side calls, use the raw API directly (no browser auth exposure):

// src/routes/api/chat/+server.ts
import { AINATIVE_API_KEY } from '$env/static/private';
import type { RequestHandler } from './$types';

export const POST: RequestHandler = async ({ request }) => {
  const { messages } = await request.json();

  const resp = await fetch('https://api.ainative.studio/v1/public/chat/completions', {
    method: 'POST',
    headers: {
      'X-API-Key': AINATIVE_API_KEY,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      model: 'claude-3-5-sonnet-20241022',
      messages,
    }),
  });

  return new Response(resp.body, {
    headers: { 'Content-Type': 'application/json' },
  });
};

Environment Variables

# .env
VITE_AINATIVE_API_KEY=ak_your_key         # Client-safe (public key only)
AINATIVE_API_KEY=ak_your_key              # Server-side (SvelteKit $env/static/private)

Use server routes for production — never expose API keys in client bundles.

Exports

import {
  createChatStore,
  setAINativeConfig,
  ainativeConfig,
  type Message,
  type ChatState,
  type AINativeError,
} from '@ainative/svelte-sdk';

References

  • packages/sdks/svelte/src/stores/chat.ts — Chat store implementation
  • packages/sdks/svelte/src/stores/config.ts — Config store
  • packages/sdks/svelte/src/index.ts — Package exports

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

通义晓蜜 - 智能外呼

触发阿里云晓蜜外呼机器人任务,自动批量拨打电话。适用于批量外呼、客户回访、满意度调查、简历筛查约面试等场景。可从前置工具或节点获取外呼名单。

Registry SourceRecently Updated
General

Letterboxd Watchlist

Scrape a public Letterboxd user's watchlist into a CSV/JSONL list of titles and film URLs without logging in. Use when a user asks to export, scrape, or mirror a Letterboxd watchlist, or to build watch-next queues.

Registry SourceRecently Updated
General

Seedance Video Generation

Generate AI videos using ByteDance Seedance. Use when the user wants to: (1) generate videos from text prompts, (2) generate videos from images (first frame, first+last frame, reference images), or (3) query/manage video generation tasks. Supports Seedance 1.5 Pro (with audio), 1.0 Pro, 1.0 Pro Fast, and 1.0 Lite models.

Registry SourceRecently Updated
4.2K17jackycser
General

Universal Skills Manager

The master coordinator for AI skills. Discovers skills from multiple sources (SkillsMP.com, SkillHub, and ClawHub), manages installation, and synchronization...

Registry SourceRecently Updated