Type-safe client SDK for Synap Core OS
npm install @synap-core/clientType-safe Client SDK for Synap Core OS
A hybrid 3-layer SDK that provides both high-level convenience methods and low-level RPC access.
---
The SDK is built on 3 layers:
1. Core RPC (Auto-generated): Direct tRPC access via client.rpc.*
2. Business Facade: High-level methods via client.notes., client.chat., etc.
3. Authentication: Agnostic token management via getToken()
---
``bash`
npm install @synap/clientor
pnpm add @synap/clientor
yarn add @synap/client
---
`typescript
import SynapClient from '@synap/client';
const synap = new SynapClient({
url: 'http://localhost:3000',
getToken: async () => {
// Get your auth token (Better Auth, custom auth, etc.)
return await getSessionToken();
},
});
// High-level API (recommended)
await synap.notes.create({
content: '# My Note\n\nContent here',
title: 'My Note',
});
// Low-level API (for power users)
await synap.rpc.notes.create.mutate({
content: '# My Note',
});
`
`typescript`
const synap = new SynapClient({
url: 'http://localhost:3000',
token: 'your-static-token',
});
---
#### Notes
`typescript
// Create a note
await synap.notes.create({
content: '# My Note',
title: 'My Note',
tags: ['important'],
});
// List notes
const notes = await synap.notes.list({
limit: 20,
offset: 0,
});
// Get a note
const note = await synap.notes.get('note-id');
`
#### Chat
`typescript
// Send a message
const result = await synap.chat.sendMessage({
content: 'Create a note about AI',
threadId: 'thread-123',
});
// Get thread
const thread = await synap.chat.getThread('thread-123');
// List threads
const threads = await synap.chat.listThreads();
`
#### Tasks
`typescript`
// Complete a task
await synap.tasks.complete('task-id');
#### Capture
`typescript`
// Capture a thought
await synap.capture.thought('I need to remember to buy milk');
#### System
`typescript
// Health check
const health = await synap.system.health();
// System info
const info = await synap.system.info();
`
For full control, use the RPC client directly:
`typescript`
// Direct tRPC access
await synap.rpc.notes.create.mutate({ content: '...' });
await synap.rpc.notes.list.query({ limit: 20 });
await synap.rpc.chat.sendMessage.mutate({ content: '...' });
---
`typescript
import { SynapRealtimeClient } from '@synap/client/realtime';
const realtime = new SynapRealtimeClient({
url: synap.getRealtimeUrl('user-123'),
userId: 'user-123',
onMessage: (message) => {
console.log('Received:', message);
if (message.type === 'note.creation.completed') {
// Refresh notes list
}
},
});
realtime.connect();
`
---
`typescript
import { trpc, createSynapReactClient } from '@synap/client/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
const queryClient = new QueryClient();
const trpcClient = createSynapReactClient({
url: 'http://localhost:3000',
getToken: async () => await getSessionToken(),
});
function App() {
return (
);
}
function MyComponent() {
const { data: notes } = trpc.notes.list.useQuery();
const createNote = trpc.notes.create.useMutation();
return (
---
🔐 Authentication
The SDK supports multiple authentication methods:
$3
`typescript
const synap = new SynapClient({
url: 'http://localhost:3000',
getToken: async () => {
const session = await getSession();
return session?.token || null;
},
});
`$3
`typescript
const synap = new SynapClient({
url: 'http://localhost:3000',
// Authentication handled via Ory Kratos session cookies
});
`$3
`typescript
const synap = new SynapClient({
url: 'http://localhost:3000',
getToken: async () => {
// Your custom auth logic
return await myAuthService.getToken();
},
});
``---
- Full Documentation - Complete guide
- Backend SDK Reference - Backend APIs
- Extensibility Guide - Extending the system
---
MIT