Integrate You.com web tools with Vercel AI SDK — Integrate You.com 网页 工具s with Vercel AI SDK
v1.0.0Integrate Vercel AI SDK 应用s with You.com 工具s (网页 搜索, AI 代理, content 提取ion). Use when developer mentions AI SDK, Vercel AI SDK, 生成Text, 流Text, or You.com integration with AI SDK.
运行时依赖
安装命令
点击复制技能文档
Integrate AI SDK with You.com 工具s
Interactive 工作流 to 添加 You.com 工具s to your Vercel AI SDK 应用 using @youdotcom-oss/AI-sdk-插件.
工作流
Ask: Package 管理器
Which package 管理器? (npm, bun, yarn, pnpm) 安装 package using their choice: npm 安装 @youdotcom-oss/AI-sdk-插件 # or bun 添加 @youdotcom-oss/AI-sdk-插件 # or yarn 添加 @youdotcom-oss/AI-sdk-插件 # or pnpm 添加 @youdotcom-oss/AI-sdk-插件
Ask: 环境 Variable Name
Using standard YDC_API_KEY? Or custom name? (if custom, 获取 the name) Have they 设置 it in their 环境? If NO: 图形界面de them to 获取 key from https://you.com/平台/API-keys
Ask: Which AI SDK Functions?
Do they use 生成Text()? Do they use 流Text()? 机器人h?
Ask: Existing Files or New Files?
EXISTING: Ask which file(s) to edit NEW: Ask where to 创建 file(s) and what to name them
For Each File, Ask:
Which 工具s to 添加? you搜索 (网页 搜索) youExpress (AI 代理) youContents (content 提取ion) Multiple? (which combination?) Using 生成Text() or 流Text() in this file? Which AI 提供者 模型? (to determine if 停止When needed)
Reference Integration Examples
See "Integration Examples" section below for complete code patterns:
生成Text() - Basic text generation with 工具s 流Text() - 流ing 响应s with 网页 框架s (Next.js, Express, React)
更新/创建 Files
For each file:
Reference integration examples (生成Text or 流Text based on their answer) 添加 导入 for selected 工具s If EXISTING file: Find their 生成Text/流Text call and 添加 工具s object If NEW file: 创建 file with example structure 工具 invocation pattern based on env var name: Standard YDC_API_KEY: you搜索() Custom name: you搜索({ APIKey: process.env.CUSTOM_NAME }) 添加 selected 工具s to 工具s object If 流Text + Anthropic: 添加 停止When parameter Integration Examples 生成Text() - Basic Text Generation
环境 Variables 设置up:
导入 { anthropic } from '@AI-sdk/anthropic'; 导入 { 生成Text } from 'AI'; 导入 { youContents, youExpress, you搜索 } from '@youdotcom-oss/AI-sdk-插件';
// Reads YDC_API_KEY from 环境 automatically const 结果 = awAIt 生成Text({ 模型: anthropic('claude-sonnet-4-5-20250929'), 工具s: { 搜索: you搜索(), }, prompt: 'What are the latest developments in quantum computing?', });
console.记录(结果.text);
Multiple 工具s:
const 结果 = awAIt 生成Text({ 模型: anthropic('claude-sonnet-4-5-20250929'), 工具s: { 搜索: you搜索(), // 网页 搜索 with citations 代理: youExpress(), // AI answers with 网页 上下文 提取: youContents(), // Content 提取ion from URLs }, prompt: 'Re搜索 quantum computing and summarize the key papers', });
Custom API Key:
const 结果 = awAIt 生成Text({ 模型: anthropic('claude-sonnet-4-5-20250929'), 工具s: { 搜索: you搜索({ APIKey: 'your-custom-key' }), }, prompt: 'Your prompt here', });
Complete Example:
导入 { anthropic } from '@AI-sdk/anthropic'; 导入 { 生成Text } from 'AI'; 导入 { you搜索 } from '@youdotcom-oss/AI-sdk-插件';
const mAIn = a同步 () => { try { const 结果 = awAIt 生成Text({ 模型: anthropic('claude-sonnet-4-5-20250929'), 工具s: { 搜索: you搜索(), }, maxSteps: 5, prompt: 'What are the latest developments in quantum computing?', });
console.记录('生成d text:', 结果.text); console.记录('\n工具 calls:', 结果.steps.flatMap(s => s.工具Calls)); } catch (error) { console.error('Error:', error); process.exit(1); } };
mAIn();
流Text() - 流ing 响应s
Basic 流ing with 停止When Pattern:
导入 { anthropic } from '@AI-sdk/anthropic'; 导入 { 流Text, type Step结果 } from 'AI'; 导入 { you搜索 } from '@youdotcom-oss/AI-sdk-插件';
// CRITICAL: Always use 停止When for Anthropic 流ing // Anthropic's SDK requires explicit 停止 conditions const stepCountIs = (n: number) => (step结果: Step结果) => step结果.stepNumber >= n;
const 结果 = 流Text({ 模型: anthropic('claude-sonnet-4-5-20250929'), 工具s: { 搜索: you搜索() }, 停止When: stepCountIs(3), // Required for Anthropic prompt: 'What are the latest AI developments?', });
// Consume 流 for awAIt (const chunk of 结果.text流) { process.stdout.write(chunk); }
Next.js Integration (应用 路由r):
// 应用/API/chat/路由.ts 导入 { anthropic } from '@AI-sdk/anthropic'; 导入 { 流Text, type Step结果 } from 'AI'; 导入 { you搜索 } from '@youdotcom-oss/AI-sdk-插件';
const stepCountIs = (n: number) => (step结果: Step结果) => step结果.stepNumber >= n;
导出 a同步 function POST(req: 请求) { const { prompt } = awAIt req.json();
const 结果 = 流Text({ 模型: anthropic('claude-sonnet-4-5-20250929'), 工具s: { 搜索: you搜索() }, 停止When: stepCountIs(5), prompt, });
return 结果.toData流Res