vercel-ai-sdk

Vercel AI SDK for Remix Integration

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "vercel-ai-sdk" with this command: npx skills add toilahuongg/shopify-agents-kit/toilahuongg-shopify-agents-kit-vercel-ai-sdk

Vercel AI SDK for Remix Integration

The Vercel AI SDK is the standard for building AI UIs. It abstracts streaming, state management, and provider differences.

  1. Setup

npm install ai @ai-sdk/openai

  1. Server-side Streaming (action function)

Remix uses Response objects. The AI SDK has a helper StreamingTextResponse .

// app/routes/api.chat.ts import { streamText } from 'ai'; import { openai } from '@ai-sdk/openai'; import { ActionFunctionArgs } from "@remix-run/node";

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

const result = await streamText({ model: openai('gpt-4-turbo'), messages, });

return result.toDataStreamResponse(); };

  1. Client-side UI hooks

Use useChat to manage message state and input automatically.

// app/routes/app.assistant.tsx import { useChat } from 'ai/react';

export default function AssistantPage() { const { messages, input, handleInputChange, handleSubmit } = useChat({ api: '/api/chat', // points to the action above });

return ( <div className="chat-container"> {messages.map(m => ( <div key={m.id} className={m.role === 'user' ? 'user-msg' : 'ai-msg'}> {m.content} </div> ))}

  &#x3C;form onSubmit={handleSubmit}>
    &#x3C;input 
      value={input} 
      onChange={handleInputChange} 
      placeholder="Ask AI something..."
    />
    &#x3C;button type="submit">Send&#x3C;/button>
  &#x3C;/form>
&#x3C;/div>

); }

  1. Shopify Context Injection

You often want the AI to know about the current Store. Retrieve data in the action and inject it as a "System Message".

// app/routes/api.chat.ts const { session } = await authenticate.admin(request); // Fetch store data with Mongoose const products = await Product.find({ shop: session.shop }).limit(5).lean(); const contextInfo = JSON.stringify(products);

const result = await streamText({ model: openai('gpt-4o'), system: You are a helper for shop ${session.shop}. Here are likely relevant products: ${contextInfo}, messages, });

  1. Deployment Note (Streaming)

Streaming works out-of-the-box on Vercel, Fly.io, and VPS. If using standard Node.js adapter, ensure your server supports standard Web Streams (Node 18+).

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.

Automation

shopify-api

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

shopify-extensions

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

shopify-functions

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

shopify-metafields

No summary provided by upstream source.

Repository SourceNeeds Review