Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@syncagent/nextjs

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@syncagent/nextjs

SyncAgent Next.js SDK — server-safe helpers and components

latest
Source
npmnpm
Version
0.3.4
Version published
Maintainers
1
Created
Source

@syncagent/nextjs

Next.js SDK for SyncAgent — server-safe helpers that keep your database connection string out of the browser bundle.

Works with MongoDB, PostgreSQL, MySQL, SQLite, SQL Server, and Supabase.

npm version License: MIT

Get Your API Key

  • Sign up for a free account
  • Go to your DashboardNew Project → choose your database type
  • Copy your API key (starts with sa_)

Every new project gets a 14-day trial with 500 free requests — no credit card required. After the trial, you get 100 free requests/month on the Free plan.

Install

npm install @syncagent/nextjs @syncagent/js @syncagent/react

Why Use This Instead of @syncagent/react?

The @syncagent/nextjs package provides createServerConfig() which lets you safely pass your database connection string from Server Components — it never reaches the browser bundle. All config options from @syncagent/js are supported.

Quick Start

// app/dashboard/page.tsx — Server Component (no "use client")
import { createServerConfig } from "@syncagent/nextjs/server";
import { SyncAgentChat } from "@syncagent/nextjs";
import { getServerSession } from "next-auth";

export default async function DashboardPage() {
  const session = await getServerSession();

  const config = createServerConfig({
    apiKey: process.env.SYNCAGENT_KEY!,
    connectionString: process.env.DATABASE_URL!,
    filter: { organizationId: session.user.orgId },
    operations: session.user.isAdmin
      ? ["read", "create", "update", "delete"]
      : ["read"],
  });

  return (
    <SyncAgentChat
      config={config}
      persistKey={session.user.id}
      accentColor="#6366f1"
      context={{ userId: session.user.id, page: "dashboard" }}
    />
  );
}

From Environment Variables

import { createServerConfigFromEnv } from "@syncagent/nextjs/server";

// Reads SYNCAGENT_KEY and DATABASE_URL automatically
const config = createServerConfigFromEnv({
  filter: { orgId: session.user.orgId },
  language: "French",
});
# .env.local
SYNCAGENT_KEY=sa_your_api_key
DATABASE_URL=mongodb+srv://user:pass@cluster/db

All Config Options

createServerConfig accepts all SyncAgentConfig options:

OptionTypeRequiredDescription
apiKeystringYour SyncAgent API key
connectionStringstring✅*Your database URL — stays on the server. *Optional when toolsOnly: true.
filterRecord<string,any>Mandatory query filter for multi-tenancy
operationsstring[]Restrict operations for this session
toolsOnlybooleanDisables all DB tools — agent only uses custom tools
systemInstructionstringCustom agent instructions — personality, tone, rules
confirmWritesbooleanAsk for confirmation before writes
languagestringLanguage the agent responds in (e.g. "French")
maxResultsnumberDefault max records per query (default 50)
sensitiveFieldsstring[]Fields to mask in responses
autoDetectPagebooleanAuto-detect page from URL (default true)
baseUrlstringOverride API URL (dev only)

Full Example — Multi-tenant SaaS

// app/app/[orgSlug]/page.tsx — Server Component
import { createServerConfig } from "@syncagent/nextjs/server";
import { SyncAgentChat } from "@syncagent/nextjs";
import { getSession } from "@/lib/auth";
import { getOrganization } from "@/lib/db";

export default async function AppPage({ params }: { params: { orgSlug: string } }) {
  const session = await getSession();
  const org = await getOrganization(params.orgSlug);

  const config = createServerConfig({
    apiKey: process.env.SYNCAGENT_KEY!,
    connectionString: process.env.DATABASE_URL!,
    filter: { organizationId: org.id },
    operations: session.user.role === "admin"
      ? ["read", "create", "update", "delete"]
      : ["read"],
    systemInstruction: `You are the AI assistant for ${org.name}. Be professional and helpful.`,
    language: org.language || "English",
    confirmWrites: true,
    maxResults: 25,
    sensitiveFields: ["ssn", "salary", "password"],
  });

  return (
    <SyncAgentChat
      config={config}
      persistKey={`${org.id}-${session.user.id}`}
      title={`${org.name} AI`}
      accentColor={org.brandColor}
      context={{ userId: session.user.id, userRole: session.user.role, orgName: org.name }}
    />
  );
}

Tools-only Mode

// Server Component
import { createServerConfig } from "@syncagent/nextjs/server";
import { ChatWithTools } from "./chat-with-tools";

export default async function Page() {
  const config = createServerConfig({
    apiKey: process.env.SYNCAGENT_KEY!,
    toolsOnly: true,
    systemInstruction: "You are a product search assistant.",
  });
  return <ChatWithTools serverConfig={config} />;
}
// app/dashboard/chat-with-tools.tsx — "use client"
import { SyncAgentChat } from "@syncagent/nextjs";

export function ChatWithTools({ serverConfig }) {
  return (
    <SyncAgentChat
      config={{
        ...serverConfig,
        tools: {
          searchProducts: {
            description: "Search products",
            inputSchema: { query: { type: "string" } },
            execute: async ({ query }) => {
              const res = await fetch(`/api/products?q=${query}`);
              return res.json();
            },
          },
        },
      }}
    />
  );
}

Middleware Hooks (Client-side Only)

Functions like onBeforeToolCall can't be serialized from Server Components. Define them in a Client Component:

// app/components/chat.tsx — "use client"
import { SyncAgentChat } from "@syncagent/nextjs";

export function Chat({ serverConfig }) {
  return (
    <SyncAgentChat
      config={{
        ...serverConfig,
        onBeforeToolCall: (name, args) => {
          console.log(`[Audit] ${name}`, args);
          return true;
        },
      }}
    />
  );
}

Re-exported Components

All components and hooks from @syncagent/react are re-exported:

import { SyncAgentChat, SyncAgentProvider, useSyncAgent, SyncAgentClient } from "@syncagent/nextjs";

API Reference

FunctionReturnsContextDescription
createServerConfig(options)SyncAgentConfigServer onlyCreate config with all options
createServerConfigFromEnv(overrides?)SyncAgentConfigServer onlyCreate config from SYNCAGENT_KEY + DATABASE_URL env vars

Security

  • Your database connection string is never stored on SyncAgent servers
  • createServerConfig ensures the connection string stays in the server bundle
  • API keys are hashed with bcrypt — raw keys are never stored
  • Never use NEXT_PUBLIC_ prefix for your database URL

Plans & Pricing

PlanRequests/moCollectionsPrice
Free (+ 14-day trial)100 (500 during trial)5GH₵0
Starter5,00020GH₵150/mo
Pro50,000UnlimitedGH₵500/mo
EnterpriseUnlimitedUnlimitedCustom

View full pricing →

Resources

License

MIT

Keywords

syncagent

FAQs

Package last updated on 14 May 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts