@pgagent/sdk
v0.0.5
Published
TypeScript SDK for [pgagent](https://github.com/niradler/pgagent) — the Postgres-centric AI app builder.
Readme
@pgagent/sdk
TypeScript SDK for pgagent — the Postgres-centric AI app builder.
Install
npm install @pgagent/sdk
# or
bun add @pgagent/sdkUsage
import { createClient, graphql } from "@pgagent/sdk";
const client = createClient({
endpoint: "http://localhost:31847",
token: "<jwt>",
});
// Typed GraphQL queries via gql.tada
const Q = graphql(`
query Me {
viewer {
id
email
}
}
`);
const { viewer } = await client.web.request(Q);
// ^? { id: string; email: string }Subpath exports
| Import path | What you get |
| -------------------- | -------------------------------------------- |
| @pgagent/sdk | createClient, graphql, all types |
| @pgagent/sdk/web | WebClient — typed GraphQL over pg_graphql |
| @pgagent/sdk/admin | AdminClient — MCP tool calls (server-side) |
| @pgagent/sdk/agent | AgentClient — SSE chat with a named agent |
| @pgagent/sdk/auth | AuthFlows — sign-up, sign-in, refresh |
| @pgagent/sdk/types | Shared types only (no runtime code) |
Auth flows
import { createClient } from "@pgagent/sdk";
const client = createClient({ endpoint: "http://localhost:31847" });
const { token } = await client.auth.signIn({
email: "[email protected]",
password: "secret",
});
// token is a JWT — pass it back as `token` to createClient for subsequent callsAdmin / MCP tools
import { createClient } from "@pgagent/sdk";
const admin = createClient({
endpoint: "http://localhost:31847",
token: serviceRoleJwt,
});
// compile-time checked tool name + input
await admin.call("entity.define", {
name: "todos",
columns: [
{ name: "title", type: "text", nullable: false },
{ name: "done", type: "boolean", default: "false" },
],
});Agent chat (SSE)
import { createClient } from "@pgagent/sdk";
const client = createClient({ endpoint: "http://localhost:31847", token });
for await (const event of client.agent("default").chat("build me a todo app")) {
if (event.type === "text-delta") process.stdout.write(event.delta);
}Schema refresh
Run this whenever the agent changes the database schema so gql.tada types stay in sync:
bun run sdk:generateLicense
MIT
