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
2. 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();
};
3. 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>
))}
<form onSubmit={handleSubmit}>
<input
value={input}
onChange={handleInputChange}
placeholder="Ask AI something..."
/>
<button type="submit">Send</button>
</form>
</div>
);
}
4. 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,
});
5. 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+).
More from toilahuongg/shopify-agents-kit
shopify-polaris-icons
Guide for using Shopify Polaris Icons in Shopify Apps. Covers icon usage patterns, accessibility, tone variants, and common icon categories for commerce applications.
19email-template-design
Design and build professional HTML email templates with inline CSS for broad email client compatibility. Use this skill when the user asks to create, design, or build email templates, newsletters, transactional emails (order confirmations, receipts, shipping notifications, password resets), marketing emails, welcome series, onboarding emails, abandoned cart emails, drip campaigns, or any HTML email layout. Covers responsive design, dark mode support, and compatibility with Gmail, Outlook (desktop + web), Apple Mail, Yahoo, and mobile clients.
18shopify-api
Comprehensive guide for Shopify APIs in Remix apps. Covers Admin GraphQL/REST, Storefront API, all resources (products, orders, customers, inventory, collections, discounts, fulfillments, metafields, files), bulk operations, webhooks, resource pickers, and TypeScript patterns. Use when querying/mutating Shopify data or building integrations.
14shopify-polaris-design
Design and implement Shopify Admin interfaces using the Polaris Design System. Use this skill when building Shopify Apps, Admin extensions, or any interface that needs to feel native to Shopify.
11rigorous-reasoning
Rigorous reasoning using philosophical theories and scientific methods. Use this skill when analyzing logic, evaluating arguments, constructing proofs, critiquing opinions, or solving complex problems requiring critical thinking. Triggers - debate, proof, critique, logical analysis, argument evaluation, fallacy detection, inference, argumentation, logical fallacy, critical thinking.
10docusaurus-generator
Generate end-user documentation site using Docusaurus 3.x from the current project. Use this skill when the user asks to create documentation, generate docs, build a docs site, or set up Docusaurus for their project. Supports analyzing project structure, generating markdown docs, configuring Docusaurus, and creating user guides.
10