Ai sdk

From InugamiDev/ultrathink-oss · View interactive version

Ai sdk is an AI agent skill from the GitHub repository InugamiDev/ultrathink-oss. > Unified TypeScript SDK for building AI-powered apps — streaming, structured output, tool calling, multi-provider.

How to use this skill

Skill file

Vercel AI SDK

Unified TypeScript SDK for building AI-powered apps — streaming, structured output, tool calling, multi-provider.

When to Use

Core Patterns

generateText / streamText

import { generateText, streamText } from "ai";
import { openai } from "@ai-sdk/openai";

// One-shot generation
const { text } = await generateText({
  model: openai("gpt-4o"),
  system: "You are a helpful assistant.",
  prompt: "Explain quantum computing in 2 sentences.",
});

// Streaming (API route)
export async function POST(req: Request) {
  const { messages } = await req.json();
  const result = streamText({
    model: openai("gpt-4o"),
    messages,
    onError: ({ error }) => console.error(error),
  });
  return result.toDataStreamResponse();
}

Structured Output with generateObject

import { generateObject } from "ai";
import { z } from "zod";

const { object } = await generateObject({
  model: openai("gpt-4o"),
  schema: z.object({
    recipe: z.string(),
    ingredients: z.array(z.object({ name: z.string(), amount: z.string() })),
  }),
  prompt: "Generate a pasta recipe.",
});
// object is fully typed — { recipe: string; ingredients: { name, amount }[] }

Tool Calling

const result = await generateText({
  model: openai("gpt-4o"),
  tools: {
    weather: { description: "Get weather for a city", parameters: z.object({ city: z.string() }),
      execute: async ({ city }) => fetchWeather(city),
    },
  },
  maxSteps: 5, // Allow multi-step tool use
  prompt: "What's the weather in Tokyo?",
});

React Hooks (useChat / useCompletion)

"use client";
import { useChat } from "@ai-sdk/react";

export function Chat() {
  const { messages, input, handleInputChange, handleSubmit, isLoading } = useChat();
  return (
    <form onSubmit={handleSubmit}>
      {messages.map((m) => <div key={m.id}>{m.role}: {m.content}</div>)}
      <input value={input} onChange={handleInputChange} disabled={isLoading} />
    </form>
  );
}
// useChat() calls POST /api/chat by default — pair with streamText route

Key Features

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.