@realtimex/sdk 2.0.17 → 2.0.19

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 CHANGED
@@ -1,382 +1,19 @@
1
- # RealtimeX Local App SDK
1
+ # @realtimex/sdk
2
2
 
3
- TypeScript/JavaScript SDK for building Local Apps that integrate with RealtimeX.
3
+ Runtime SDK and agent skill assets for RealtimeX.
4
4
 
5
- ## Installation
5
+ ## Node Usage
6
6
 
7
- ```bash
8
- npm install @realtimex/sdk
9
- ```
10
-
11
- ## Prerequisites
12
-
13
- Before using this SDK, ensure your Supabase database is set up:
14
-
15
- 1. Open **RealtimeX Main App** → **Local Apps** → Your App → **Configure**
16
- 2. Enter your Supabase **URL** and **Anon Key**
17
- 3. Select **Compatible Mode** and click **Login to Supabase**
18
- 4. Click **Auto-Setup Schema** to create the required tables and functions
19
-
20
- > **Note:** Schema setup is handled entirely by the Main App. You don't need to run any SQL manually.
21
-
22
- ## Quick Start
23
-
24
- ```typescript
25
- import { RealtimeXSDK } from '@realtimex/sdk';
26
-
27
- const sdk = new RealtimeXSDK({
28
- // Development Mode: Use API key for full access
29
- realtimex: { apiKey: 'sk-abc123...' },
30
- // OR Production Mode: Declare permissions
31
- permissions: ['activities.read', 'activities.write', 'webhook.trigger']
32
- });
33
-
34
- // Insert activity
35
- const activity = await sdk.activities.insert({
36
- type: 'new_lead',
37
- email: 'user@example.com',
38
- });
39
-
40
- // Trigger agent (optional - for auto-processing)
41
- await sdk.webhook.triggerAgent({
42
- raw_data: activity,
43
- auto_run: true,
44
- agent_name: 'processor',
45
- workspace_slug: 'sales',
46
- thread_slug: 'general', //create_new for new thread
47
- prompt: 'Process this lead',//optional
48
- });
49
- ```
50
-
51
- ## How It Works
52
-
53
- When you start your Local App from the RealtimeX Main App:
54
-
55
- 1. Environment variables `RTX_APP_ID` and `RTX_APP_NAME` are automatically set
56
- 2. The SDK auto-detects these - no manual configuration needed
57
- 3. All operations go through the Main App's proxy endpoints
58
-
59
- ## Configuration (Optional)
60
-
61
- ```typescript
62
- const sdk = new RealtimeXSDK({
63
- realtimex: {
64
- url: 'http://custom-host:3001', // Default: localhost:3001
65
- apiKey: 'sk-abc123...', // Development mode
66
- appId: 'custom-id', // Production mode (override)
67
- appName: 'My App', // Optional
68
- }
69
- });
70
- ```
71
-
72
- ## API Reference
73
-
74
- ### Activities CRUD
75
-
76
- ```typescript
77
- // Insert
78
- const activity = await sdk.activities.insert({ type: 'order', amount: 100 });
79
-
80
- // List
81
- const pending = await sdk.activities.list({ status: 'pending', limit: 50 });
82
-
83
- // Get
84
- const item = await sdk.activities.get('activity-uuid');
85
-
86
- // Update
87
- await sdk.activities.update('activity-uuid', { status: 'processed' });
88
-
89
- // Delete
90
- await sdk.activities.delete('activity-uuid');
91
- ```
92
-
93
- ### Webhook - Trigger Agent
94
-
95
- ```typescript
96
- // Manual mode (creates calendar event only)
97
- await sdk.webhook.triggerAgent({
98
- raw_data: { email: 'customer@example.com' },
99
- });
100
-
101
- // Auto-run mode (creates event and triggers agent immediately)
102
- await sdk.webhook.triggerAgent({
103
- raw_data: activity,
104
- auto_run: true,
105
- agent_name: 'processor',
106
- workspace_slug: 'sales',
107
- thread_slug: 'optional-thread', // Optional: specific thread
108
- });
109
- ```
110
-
111
- ### Contract Discovery
112
-
113
- ```typescript
114
- // Read canonical contract metadata published by Main App
115
- const contract = await sdk.contract.getLocalAppV1();
116
-
117
- console.log(contract.version); // local-app-contract/v1
118
- console.log(contract.supported_events); // task.trigger, task.claimed, ...
119
- console.log(contract.callback?.signature_header); // x-rtx-contract-signature
120
- ```
121
-
122
- ### Worker Callback Lifecycle
123
-
124
- Use this when your worker receives `task_uuid`, `attempt_id`, and callback metadata from RealtimeX task context.
125
-
126
- ```typescript
127
- sdk.task.configureContract({
128
- callbackSecret: process.env.RTX_CONTRACT_CALLBACK_SECRET,
129
- signCallbacksByDefault: true,
130
- });
131
-
132
- await sdk.task.claim(taskUuid, {
133
- callbackUrl,
134
- machineId,
135
- attemptId,
136
- userEmail,
137
- });
138
-
139
- await sdk.task.start(taskUuid, {
140
- callbackUrl,
141
- machineId,
142
- attemptId,
143
- });
144
-
145
- await sdk.task.progress(taskUuid, { percent: 50, message: 'Halfway done' }, {
146
- callbackUrl,
147
- machineId,
148
- attemptId,
149
- });
150
-
151
- await sdk.task.complete(taskUuid, { summary: 'Done' }, {
152
- callbackUrl,
153
- machineId,
154
- attemptId,
155
- });
156
- ```
157
-
158
- `TaskModule` auto-populates:
159
- - `event_id` for idempotency
160
- - canonical `event` names
161
- - optional HMAC signature header (`x-rtx-contract-signature`) when signing is enabled
162
- - legacy `action` alongside canonical `event` for compatibility when posting to callback URLs
163
-
164
- ### Contract Compatibility Check
7
+ ```js
8
+ const { createRealtimeXClient } = require("@realtimex/sdk");
165
9
 
166
- Run the cross-language harness (Main App endpoint + TypeScript SDK + Python SDK):
167
-
168
- ```bash
169
- RTX_API_KEY=sk-... RTX_CONTRACT_VERIFY_BASE_URL=http://127.0.0.1:3001 npm run contract:verify
170
- ```
171
-
172
- ### Public APIs
173
-
174
- ```typescript
175
- // Get available agents in a workspace
176
- const agents = await sdk.api.getAgents();
177
-
178
- // Get all workspaces
179
- const workspaces = await sdk.api.getWorkspaces();
180
-
181
- // Get threads in a workspace
182
- const threads = await sdk.api.getThreads('sales');
183
-
184
- // Get task status
185
- const task = await sdk.api.getTask('task-uuid');
186
- ```
187
-
188
- ### LLM Module
189
-
190
- Access AI capabilities through the RealtimeX proxy:
191
-
192
- ```typescript
193
- const sdk = new RealtimeXSDK({
194
- permissions: ['llm.chat', 'llm.embed', 'llm.providers', 'vectors.write', 'vectors.read']
195
- });
196
- ```
197
-
198
- #### List Providers & Models
199
-
200
- ```typescript
201
-
202
-
203
- // Get only configured Chat providers (recommended)
204
- const chatRes = await sdk.llm.chatProviders();
205
- // chatRes.providers: Array of chat providers with models
206
-
207
- // Get only configured Embedding providers (recommended)
208
- const embedRes = await sdk.llm.embedProviders();
209
- // embedRes.providers: Array of embedding providers with models
210
- ```
211
-
212
-
213
- #### Chat Completion
214
-
215
- ```typescript
216
- // Sync Chat
217
- const response = await sdk.llm.chat(
218
- [
219
- { role: 'system', content: 'You are a helpful assistant.' },
220
- { role: 'user', content: 'What is RealtimeX?' }
221
- ],
222
- {
223
- model: 'gpt-4o', // Optional: specific model
224
- provider: 'openai', // Optional: specific provider
225
- temperature: 0.7, // Optional: 0.0-2.0
226
- max_tokens: 1000 // Optional: max response tokens
227
- }
228
- );
229
- console.log(response.response?.content);
230
-
231
- // Multimodal Chat (text + file/image blocks)
232
- const multimodal = await sdk.llm.chat([
233
- {
234
- role: 'user',
235
- content: [
236
- { type: 'text', text: 'Summarize the attached document' },
237
- { type: 'input_file', file_url: 'https://example.com/report.pdf' },
238
- { type: 'input_image', image_url: 'https://example.com/chart.png' }
239
- ]
240
- }
241
- ]);
242
- console.log(multimodal.response?.content);
243
-
244
- // Streaming Chat
245
- for await (const chunk of sdk.llm.chatStream(messages, options)) {
246
- process.stdout.write(chunk.textResponse || '');
247
- }
248
- ```
249
-
250
- #### Generate Embeddings
251
-
252
- ```typescript
253
- const { embeddings, dimensions, provider, model } = await sdk.llm.embed(
254
- ['Hello world', 'Goodbye'],
255
- { provider: 'openai', model: 'text-embedding-3-small' } // Optional
256
- );
257
- // embeddings: number[][] - vector arrays
258
- // dimensions: number - vector dimension (e.g., 1536)
259
- ```
260
-
261
- #### Vector Store Operations
262
-
263
- ```typescript
264
- // Upsert vectors with metadata
265
- await sdk.llm.vectors.upsert([
266
- {
267
- id: 'chunk-1',
268
- vector: embeddings[0],
269
- metadata: {
270
- text: 'Hello world', // Original text (for retrieval)
271
- documentId: 'doc-1', // Logical grouping
272
- customField: 'any value' // Any custom metadata
273
- }
274
- }
275
- ], {
276
- workspaceId: 'ws-123' // Optional: physical namespace isolation
277
- });
278
-
279
- // Query similar vectors
280
- const results = await sdk.llm.vectors.query(queryVector, {
281
- topK: 5, // Number of results
282
- workspaceId: 'ws-123', // Optional: search in specific workspace
283
- filter: { documentId: 'doc-1' } // Optional: filter by document
284
- });
285
- // returns: { success, results: [{ id, score, metadata }] }
286
-
287
- // List all workspaces for this app
288
- const { workspaces } = await sdk.llm.vectors.listWorkspaces();
289
- // returns: { success, workspaces: ['ws-123', 'default', ...] }
290
-
291
- // Delete all vectors in a workspace
292
- await sdk.llm.vectors.delete({
293
- deleteAll: true,
294
- workspaceId: 'ws-123'
10
+ const client = createRealtimeXClient({
11
+ baseUrl: process.env.REALTIMEX_BASE_URL,
12
+ appIdAuth: process.env.REALTIMEX_APP_ID_AUTH,
295
13
  });
296
- ```
297
-
298
- #### High-Level Helpers
299
-
300
- These combine multiple operations for common RAG patterns:
301
14
 
302
- ```typescript
303
- // embedAndStore: Text → Embed → Store (one call)
304
- await sdk.llm.embedAndStore(
305
- ['Document text 1', 'Document text 2'], // texts to embed
306
- {
307
- documentId: 'doc-123', // Optional: logical grouping
308
- workspaceId: 'ws-456', // Optional: physical isolation
309
- provider: 'openai', // Optional: embedding provider
310
- model: 'text-embedding-3-small' // Optional: embedding model
311
- }
312
- );
313
-
314
- // search: Query → Embed → Search (one call)
315
- const searchResults = await sdk.llm.search(
316
- 'What is RealtimeX?', // search query (text, not vector)
317
- {
318
- topK: 5, // Number of results
319
- workspaceId: 'ws-123', // Optional: search in workspace
320
- documentId: 'doc-1', // Optional: filter by document
321
- provider: 'openai', // Optional: embedding provider
322
- model: 'text-embedding-3-small' // Optional: embedding model
323
- }
324
- );
325
- // returns: [{ id, score, metadata: { text, documentId, ... } }]
15
+ const workspaces = await client.request("listWorkspaces");
326
16
  ```
327
17
 
328
- > **Note on Isolation:**
329
- > - `workspaceId`: Creates **physical namespace** (`sdk_{appId}_{wsId}`) - data completely isolated
330
- > - `documentId`: Stored as **metadata**, filtered after search (post-filter)
331
-
332
- ### Error Handling
333
-
334
- The SDK provides specific error classes for handling LLM-related issues:
335
-
336
- ```typescript
337
- import { LLMPermissionError, LLMProviderError } from '@realtimex/sdk';
338
-
339
- try {
340
- for await (const chunk of sdk.llm.chatStream(messages)) {
341
- process.stdout.write(chunk.textResponse || '');
342
- }
343
- } catch (error) {
344
- if (error instanceof LLMPermissionError) {
345
- // Permission not granted: 'llm.chat' etc.
346
- console.error(`Permission required: ${error.permission}`);
347
- } else if (error instanceof LLMProviderError) {
348
- // Provider errors: rate limit, timeout, model unavailable, etc.
349
- console.error(`Provider error: ${error.message} (code: ${error.code})`);
350
- // Common codes: LLM_STREAM_ERROR, RATE_LIMIT, PROVIDER_UNAVAILABLE
351
- }
352
- }
353
- ```
354
-
355
- | Error Class | Common Codes | Description |
356
- |-------------|--------------|-------------|
357
- | `LLMPermissionError` | `PERMISSION_REQUIRED` | Missing or denied permission |
358
- | `LLMProviderError` | `LLM_STREAM_ERROR`, `RATE_LIMIT`, `PROVIDER_UNAVAILABLE` | AI provider issues |
359
-
360
- ## Environment Variables
361
-
362
- | Variable | Description |
363
- |----------|-------------|
364
- | `RTX_APP_ID` | Auto-set by Main App when starting your app |
365
- | `RTX_APP_NAME` | Auto-set by Main App when starting your app |
366
-
367
- ## Architecture
368
-
369
- ```
370
- ┌─────────────────┐ ┌──────────────────┐ ┌─────────────┐
371
- │ Your App │────▶│ RealtimeX Main │────▶│ Supabase │
372
- │ (SDK) │ │ App (Proxy) │ │ Database │
373
- └─────────────────┘ └──────────────────┘ └─────────────┘
374
- ```
375
-
376
- - Your app uses the SDK to communicate with the Main App
377
- - Main App proxies all database operations to Supabase
378
- - Schema is managed by Main App (no direct database access needed)
379
-
380
- ## License
381
-
382
- MIT
18
+ The package also publishes generated skill assets under
19
+ `skills/realtimex-moderator-sdk`.