@synap-core/client 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,253 @@
1
+ # @synap/client
2
+
3
+ **Type-safe Client SDK for Synap Core OS**
4
+
5
+ A hybrid 3-layer SDK that provides both high-level convenience methods and low-level RPC access.
6
+
7
+ ---
8
+
9
+ ## 🏗️ Architecture
10
+
11
+ The SDK is built on 3 layers:
12
+
13
+ 1. **Core RPC** (Auto-generated): Direct tRPC access via `client.rpc.*`
14
+ 2. **Business Facade**: High-level methods via `client.notes.*`, `client.chat.*`, etc.
15
+ 3. **Authentication**: Agnostic token management via `getToken()`
16
+
17
+ ---
18
+
19
+ ## 📦 Installation
20
+
21
+ ```bash
22
+ npm install @synap/client
23
+ # or
24
+ pnpm add @synap/client
25
+ # or
26
+ yarn add @synap/client
27
+ ```
28
+
29
+ ---
30
+
31
+ ## 🚀 Quick Start
32
+
33
+ ### Basic Usage
34
+
35
+ ```typescript
36
+ import SynapClient from '@synap/client';
37
+
38
+ const synap = new SynapClient({
39
+ url: 'http://localhost:3000',
40
+ getToken: async () => {
41
+ // Get your auth token (Better Auth, custom auth, etc.)
42
+ return await getSessionToken();
43
+ },
44
+ });
45
+
46
+ // High-level API (recommended)
47
+ await synap.notes.create({
48
+ content: '# My Note\n\nContent here',
49
+ title: 'My Note',
50
+ });
51
+
52
+ // Low-level API (for power users)
53
+ await synap.rpc.notes.create.mutate({
54
+ content: '# My Note',
55
+ });
56
+ ```
57
+
58
+ ### With Static Token
59
+
60
+ ```typescript
61
+ const synap = new SynapClient({
62
+ url: 'http://localhost:3000',
63
+ token: 'your-static-token',
64
+ });
65
+ ```
66
+
67
+ ---
68
+
69
+ ## 📚 API Reference
70
+
71
+ ### High-Level API (Business Facade)
72
+
73
+ #### Notes
74
+
75
+ ```typescript
76
+ // Create a note
77
+ await synap.notes.create({
78
+ content: '# My Note',
79
+ title: 'My Note',
80
+ tags: ['important'],
81
+ });
82
+
83
+ // List notes
84
+ const notes = await synap.notes.list({
85
+ limit: 20,
86
+ offset: 0,
87
+ });
88
+
89
+ // Get a note
90
+ const note = await synap.notes.get('note-id');
91
+ ```
92
+
93
+ #### Chat
94
+
95
+ ```typescript
96
+ // Send a message
97
+ const result = await synap.chat.sendMessage({
98
+ content: 'Create a note about AI',
99
+ threadId: 'thread-123',
100
+ });
101
+
102
+ // Get thread
103
+ const thread = await synap.chat.getThread('thread-123');
104
+
105
+ // List threads
106
+ const threads = await synap.chat.listThreads();
107
+ ```
108
+
109
+ #### Tasks
110
+
111
+ ```typescript
112
+ // Complete a task
113
+ await synap.tasks.complete('task-id');
114
+ ```
115
+
116
+ #### Capture
117
+
118
+ ```typescript
119
+ // Capture a thought
120
+ await synap.capture.thought('I need to remember to buy milk');
121
+ ```
122
+
123
+ #### System
124
+
125
+ ```typescript
126
+ // Health check
127
+ const health = await synap.system.health();
128
+
129
+ // System info
130
+ const info = await synap.system.info();
131
+ ```
132
+
133
+ ### Low-Level API (RPC)
134
+
135
+ For full control, use the RPC client directly:
136
+
137
+ ```typescript
138
+ // Direct tRPC access
139
+ await synap.rpc.notes.create.mutate({ content: '...' });
140
+ await synap.rpc.notes.list.query({ limit: 20 });
141
+ await synap.rpc.chat.sendMessage.mutate({ content: '...' });
142
+ ```
143
+
144
+ ---
145
+
146
+ ## 🔌 Real-Time (WebSocket)
147
+
148
+ ```typescript
149
+ import { SynapRealtimeClient } from '@synap/client/realtime';
150
+
151
+ const realtime = new SynapRealtimeClient({
152
+ url: synap.getRealtimeUrl('user-123'),
153
+ userId: 'user-123',
154
+ onMessage: (message) => {
155
+ console.log('Received:', message);
156
+ if (message.type === 'note.creation.completed') {
157
+ // Refresh notes list
158
+ }
159
+ },
160
+ });
161
+
162
+ realtime.connect();
163
+ ```
164
+
165
+ ---
166
+
167
+ ## ⚛️ React Integration
168
+
169
+ ```typescript
170
+ import { trpc, createSynapReactClient } from '@synap/client/react';
171
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
172
+
173
+ const queryClient = new QueryClient();
174
+ const trpcClient = createSynapReactClient({
175
+ url: 'http://localhost:3000',
176
+ getToken: async () => await getSessionToken(),
177
+ });
178
+
179
+ function App() {
180
+ return (
181
+ <trpc.Provider client={trpcClient} queryClient={queryClient}>
182
+ <MyComponent />
183
+ </trpc.Provider>
184
+ );
185
+ }
186
+
187
+ function MyComponent() {
188
+ const { data: notes } = trpc.notes.list.useQuery();
189
+ const createNote = trpc.notes.create.useMutation();
190
+
191
+ return (
192
+ <div>
193
+ {notes?.map(note => (
194
+ <div key={note.id}>{note.title}</div>
195
+ ))}
196
+ </div>
197
+ );
198
+ }
199
+ ```
200
+
201
+ ---
202
+
203
+ ## 🔐 Authentication
204
+
205
+ The SDK supports multiple authentication methods:
206
+
207
+ ### Better Auth (PostgreSQL mode)
208
+
209
+ ```typescript
210
+ const synap = new SynapClient({
211
+ url: 'http://localhost:3000',
212
+ getToken: async () => {
213
+ const session = await getSession();
214
+ return session?.token || null;
215
+ },
216
+ });
217
+ ```
218
+
219
+ ### Ory Kratos Session (PostgreSQL mode)
220
+
221
+ ```typescript
222
+ const synap = new SynapClient({
223
+ url: 'http://localhost:3000',
224
+ // Authentication handled via Ory Kratos session cookies
225
+ });
226
+ ```
227
+
228
+ ### Custom Auth
229
+
230
+ ```typescript
231
+ const synap = new SynapClient({
232
+ url: 'http://localhost:3000',
233
+ getToken: async () => {
234
+ // Your custom auth logic
235
+ return await myAuthService.getToken();
236
+ },
237
+ });
238
+ ```
239
+
240
+ ---
241
+
242
+ ## 📖 Documentation
243
+
244
+ - **[Full Documentation](../../docs/development/SDK_NPM.md)** - Complete guide
245
+ - **[Backend SDK Reference](../../docs/development/SDK_REFERENCE.md)** - Backend APIs
246
+ - **[Extensibility Guide](../../docs/development/EXTENSIBILITY.md)** - Extending the system
247
+
248
+ ---
249
+
250
+ ## 📝 License
251
+
252
+ MIT
253
+