npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@frankma4529/pi-ai-brain-agent-sdk

v0.1.0

Published

Pi AI Brain 数据库 Agent SDK(PostgreSQL/MySQL,安全/自愈/缓存/Schema 扫描,6 个工具)

Readme

Pi AI Brain Agent SDK (MVP)

独立的数据库 Agent SDK,复用 Pi AI Brain 后端的核心能力:连接池管理、SQL 安全/预处理/自愈、Schema 扫描与缓存、6 个数据库工具(PostgreSQL/MySQL)。

安装

npm install @frankma4529/pi-ai-brain-agent-sdk
# 由使用方提供数据库驱动
npm install pg mysql2 ioredis

快速开始

import { PiAgentSDK } from '@frankma4529/pi-ai-brain-agent-sdk';

const sdk = new PiAgentSDK({
  security: { allowWrite: false, allowedSchemas: ['public'] },
  cache: { fallbackToMemory: true }, // 可传入 redisClient
});

await sdk.dataSources.register({
  id: 'ds1',
  name: 'Demo PG',
  type: 'postgres',
  tenantId: 't1',
  connectionString: 'postgresql://user:pass@localhost:5432/db',
  configJson: { schemas: ['public'] },
  testConnection: true,
});

const result = await sdk.tools.execute(
  'execute_sql',
  { datasource_id: 'ds1', sql: 'SELECT 1 as num' },
  { tenantId: 't1' },
);
console.log(result.data?.rows);

核心能力

  • 连接池管理:Pg/MySQL 动态池,空闲/过期清理。
  • SQL 安全与自愈:只读/DDL 限制、危险关键字校验,方言预处理+自愈。
  • Schema 扫描与缓存:信息模式扫描,Redis/内存缓存,快照持久化接口。
  • 工具层:execute_sql、list_tables、search_tables、get_table_schema、analyze_table、analyze_schema。
  • 默认实现:内存 DataSource/Schema Store、Console 审计、内存指标、Env KeyManager(ENCRYPTION_KEY >= 32 字符)。

目录结构

  • src/sdk.ts:SDK 入口。
  • src/core/*:连接池、缓存、Schema、SQL 安全、预处理、自愈。
  • src/tools/database-tool-provider.ts:6 个工具。
  • src/stores/*:内存持久化默认实现。
  • src/monitoring/*:审计与指标默认实现。

注意

  • 需要 ENCRYPTION_KEY 环境变量(>=32 字符)或自定义 keyManager
  • Redis 可选,未配置时自动降级到内存缓存。
  • 当前版本不包含 MSSQL、Prisma 适配器、MCP 适配器(计划版本)。

pi-ai-brain-agent-sdk