← 返回 Skills 市场
Ainative Nextjs Sdk
作者
Toby Morning
· GitHub ↗
· v1.0.0
· MIT-0
99
总下载
0
收藏
1
当前安装
1
版本数
在 OpenClaw 中安装
/install ainative-nextjs-sdk
功能描述
Use @ainative/next-sdk to add AI chat to Next.js apps (App Router + Pages Router). Use when (1) Installing @ainative/next-sdk, (2) Setting up a streaming cha...
使用说明 (SKILL.md)
@ainative/next-sdk
Server-side AINative client for Next.js with App Router support, streaming chat, and auth middleware.
Install
npm install @ainative/next-sdk
Server Client — Chat Completions
// app/api/chat/route.ts
import { createServerClient } from '@ainative/next-sdk/server';
export async function POST(request: Request) {
const { messages } = await request.json();
const client = createServerClient({
apiKey: process.env.AINATIVE_API_KEY!,
});
// Non-streaming
const result = await client.chat.completions.create({
model: 'claude-3-5-sonnet-20241022',
messages,
max_tokens: 1024,
});
return Response.json(result);
}
Streaming Response
// app/api/chat/route.ts
import { createServerClient } from '@ainative/next-sdk/server';
export async function POST(request: Request) {
const { messages } = await request.json();
const client = createServerClient({ apiKey: process.env.AINATIVE_API_KEY! });
const stream = await client.chat.completions.create({
model: 'claude-3-5-sonnet-20241022',
messages,
stream: true,
});
return new Response(stream.body, {
headers: {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
},
});
}
Auth Middleware
// middleware.ts (repo root or src/)
import { createMiddleware } from '@ainative/next-sdk/middleware';
export const middleware = createMiddleware({
apiKey: process.env.AINATIVE_API_KEY!,
protectedPaths: ['/dashboard', '/api/protected'],
loginPath: '/login',
publicPaths: ['/', '/about', '/api/chat'],
});
export const config = {
matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
};
Client-Side (App Router)
// app/components/Chat.tsx
'use client';
import { useState } from 'react';
export function Chat() {
const [messages, setMessages] = useState\x3C{ role: string; content: string }[]>([]);
const [input, setInput] = useState('');
const send = async () => {
const newMessages = [...messages, { role: 'user', content: input }];
setMessages(newMessages);
setInput('');
const res = await fetch('/api/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ messages: newMessages }),
});
const data = await res.json();
setMessages([...newMessages, data.choices[0].message]);
};
return (
\x3Cdiv>
{messages.map((m, i) => \x3Cp key={i}>\x3Cb>{m.role}:\x3C/b> {m.content}\x3C/p>)}
\x3Cinput value={input} onChange={e => setInput(e.target.value)} />
\x3Cbutton onClick={send}>Send\x3C/button>
\x3C/div>
);
}
Pages Router (API route)
// pages/api/chat.ts
import type { NextApiRequest, NextApiResponse } from 'next';
import { createServerClient } from '@ainative/next-sdk/server';
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const client = createServerClient({ apiKey: process.env.AINATIVE_API_KEY! });
const result = await client.chat.completions.create({
model: 'claude-3-5-sonnet-20241022',
messages: req.body.messages,
});
res.json(result);
}
Environment Variables
# .env.local
AINATIVE_API_KEY=ak_your_key
Never expose AINATIVE_API_KEY to the client — only use it in server-side code (route handlers, Server Actions, getServerSideProps).
Exports
import { createServerClient } from '@ainative/next-sdk/server';
import { createMiddleware } from '@ainative/next-sdk/middleware';
References
packages/sdks/nextjs/src/server/createServerClient.ts— Server clientpackages/sdks/nextjs/src/middleware/— Auth middlewarepackages/sdks/nextjs/examples/app-router/— Example apppackages/sdks/nextjs/src/index.ts— Package exports
安全使用建议
This SKILL.md looks like legitimate usage documentation for a Next.js SDK, but the manifest fails to declare the AINATIVE_API_KEY that the examples require. Before installing or wiring this into an app: 1) Verify the package source on npm and the repository (confirm maintainer, stars, release history). 2) Confirm the exact environment variable name and required permission scope for the API key; treat the key as a secret and only set it for server-side usage. 3) Prefer installing from the official npm package (check integrity/versions) rather than blindly copying code from an unknown source. 4) If you are automating skill installation, update the manifest to explicitly declare AINATIVE_API_KEY (or ask the publisher to do so) so tooling and reviewers understand the required credential. 5) Rotate the key and limit its permissions if possible. The main actionable concern is the metadata mismatch — it may be an oversight, but verify before granting or storing secrets.
功能分析
Type: OpenClaw Skill
Name: ainative-nextjs-sdk
Version: 1.0.0
The skill bundle provides standard documentation and integration examples for the '@ainative/next-sdk' package in Next.js. The code snippets follow best practices, such as keeping API keys server-side and using middleware for route protection, with no signs of malicious intent, data exfiltration, or prompt injection.
能力评估
Purpose & Capability
The SKILL.md describes an @ainative/next-sdk for adding AI chat to Next.js apps which matches the name and description. However, the manifest lists no required environment variables or primary credential while the runtime examples consistently require an AINATIVE_API_KEY. That omission is an inconsistency between claimed metadata and actual usage.
Instruction Scope
The instructions are narrowly scoped to installing and using the Next.js SDK: creating server clients, streaming responses, middleware, and client-side usage. They explicitly warn not to expose the API key to the client and do not instruct reading unrelated files or credentials.
Install Mechanism
This is an instruction-only skill with no install spec and no code files; that reduces surface risk because nothing is written or executed by the skill itself. The SKILL.md recommends 'npm install @ainative/next-sdk' (a normal package install).
Credentials
The SDK examples require an AINATIVE_API_KEY (and show adding it to .env.local), but the skill metadata did not declare any required env vars or a primary credential. Requesting an API key for the service is reasonable for this capability, but the manifest omission is a discrepancy that could hide expected credential use or mislead automation.
Persistence & Privilege
always:false and default agent invocation settings are used. The skill does not request persistent presence or modify other skills. No privileged or permanent agent-level settings are requested.
如何使用
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install ainative-nextjs-sdk - 安装完成后,直接呼叫该 Skill 的名称或使用
/ainative-nextjs-sdk触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release of ainative-nextjs-sdk.
- Adds server-side AINative client with Next.js App Router and Pages Router support.
- Supports streaming and non-streaming AI chat completions via API routes.
- Provides AINative authentication middleware for route protection.
- Includes documentation and examples for installation, usage, and environment configuration.
- Exposes `createServerClient` and `createMiddleware` for integration.
元数据
常见问题
Ainative Nextjs Sdk 是什么?
Use @ainative/next-sdk to add AI chat to Next.js apps (App Router + Pages Router). Use when (1) Installing @ainative/next-sdk, (2) Setting up a streaming cha... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 99 次。
如何安装 Ainative Nextjs Sdk?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install ainative-nextjs-sdk」即可一键安装,无需额外配置。
Ainative Nextjs Sdk 是免费的吗?
是的,Ainative Nextjs Sdk 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
Ainative Nextjs Sdk 支持哪些平台?
Ainative Nextjs Sdk 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 Ainative Nextjs Sdk?
由 Toby Morning(@urbantech)开发并维护,当前版本 v1.0.0。
推荐 Skills