@recursorsdk/sdk 1.0.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/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ MIT License
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,412 @@
1
+ # Recursor SDK (Node.js)
2
+
3
+ Complete Node.js SDK for interacting with the Recursor API. Provides authentication, project management, real-time updates via WebSocket, and full access to all platform features.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @recursor/sdk
9
+ ```
10
+
11
+ Or build from source:
12
+
13
+ ```bash
14
+ cd sdk/node
15
+ npm install
16
+ npm run build
17
+ npm pack
18
+ ```
19
+
20
+ ## Quick Start
21
+
22
+ ### Basic Usage
23
+
24
+ ```typescript
25
+ import { RecursorSDK } from "@recursor/sdk";
26
+
27
+ const sdk = new RecursorSDK({
28
+ baseUrl: "https://api.recursor.dev/api/v1",
29
+ });
30
+
31
+ // Check health
32
+ const healthy = await sdk.checkHealth();
33
+ console.log("API is healthy:", healthy);
34
+ ```
35
+
36
+ ### Authentication
37
+
38
+ ```typescript
39
+ // Register a new user
40
+ const user = await sdk.register({
41
+ email: "user@example.com",
42
+ password: "SecurePass123",
43
+ username: "johndoe",
44
+ full_name: "John Doe",
45
+ });
46
+
47
+ // Login
48
+ const { access_token } = await sdk.login({
49
+ email: "user@example.com",
50
+ password: "SecurePass123",
51
+ });
52
+ // Access token is automatically set for future requests
53
+
54
+ // Get user profile
55
+ const profile = await sdk.getProfile();
56
+ console.log("User:", profile.email);
57
+
58
+ // Update profile
59
+ const updated = await sdk.updateProfile({
60
+ full_name: "John Smith",
61
+ });
62
+
63
+ // Change password
64
+ await sdk.changePassword({
65
+ current_password: "SecurePass123",
66
+ new_password: "NewSecurePass456",
67
+ });
68
+ ```
69
+
70
+ ### Project Management
71
+
72
+ ```typescript
73
+ // Create a project
74
+ const project = await sdk.createProject({
75
+ name: "My Project",
76
+ organization_id: "org-123",
77
+ description: "Project description",
78
+ });
79
+
80
+ // Get project
81
+ const projectDetails = await sdk.getProject(project.id);
82
+
83
+ // List projects
84
+ const projects = await sdk.listProjects("org-123");
85
+
86
+ // Get MCP configuration
87
+ const mcpConfig = await sdk.getMcpConfig(project.id);
88
+ console.log("MCP Config:", mcpConfig);
89
+
90
+ // Regenerate API key
91
+ const { api_key } = await sdk.regenerateProjectApiKey(project.id);
92
+
93
+ // Update project
94
+ const updated = await sdk.updateProject(project.id, {
95
+ name: "Updated Project Name",
96
+ description: "New description",
97
+ });
98
+
99
+ // Delete project
100
+ await sdk.deleteProject(project.id);
101
+ ```
102
+
103
+ ### Organizations & Teams
104
+
105
+ ```typescript
106
+ // Create organization
107
+ const org = await sdk.createOrganization({
108
+ name: "My Organization",
109
+ description: "Organization description",
110
+ });
111
+
112
+ // List organizations
113
+ const orgs = await sdk.listOrganizations();
114
+
115
+ // Add member
116
+ await sdk.addMemberToOrganization(org.id, "user-123");
117
+
118
+ // Remove member
119
+ await sdk.removeMemberFromOrganization(org.id, "user-123");
120
+ ```
121
+
122
+ ### Corrections
123
+
124
+ ```typescript
125
+ // Create correction
126
+ const correction = await sdk.createCorrection({
127
+ input_text: "incorrect code",
128
+ output_text: "correct code",
129
+ expected_output: "correct code",
130
+ context: { explanation: "Fix bug" },
131
+ correction_type: "bug",
132
+ });
133
+
134
+ // List corrections
135
+ const { corrections, total } = await sdk.listCorrections({
136
+ page: 1,
137
+ page_size: 50,
138
+ });
139
+
140
+ // Search corrections
141
+ const results = await sdk.searchCorrections("authentication", 10);
142
+
143
+ // Get correction
144
+ const correctionDetails = await sdk.getCorrection(correction.id);
145
+
146
+ // Update correction
147
+ const updated = await sdk.updateCorrection(correction.id, {
148
+ context: { explanation: "Updated explanation" },
149
+ });
150
+
151
+ // Get statistics
152
+ const stats = await sdk.getCorrectionStats();
153
+ ```
154
+
155
+ ### Code Intelligence
156
+
157
+ ```typescript
158
+ // Detect intent
159
+ const intent = await sdk.detectIntent({
160
+ user_request: "Add error handling to login",
161
+ current_file: "auth.ts",
162
+ tags: ["error-handling"],
163
+ });
164
+
165
+ // Get intent history
166
+ const history = await sdk.getIntentHistory(50);
167
+
168
+ // Correct code
169
+ const result = await sdk.correctCode(
170
+ "def func(): pass",
171
+ "python"
172
+ );
173
+
174
+ // Get analytics
175
+ const dashboard = await sdk.getAnalyticsDashboard("user-123", "30d");
176
+ const timeSaved = await sdk.getTimeSaved("user-123", "30d");
177
+ const quality = await sdk.getQualityMetrics("user-123", "30d");
178
+ ```
179
+
180
+ ### Billing & Usage
181
+
182
+ ```typescript
183
+ // Get current usage
184
+ const usage = await sdk.getUsage();
185
+ console.log("API Calls:", usage.api_calls.used, "/", usage.api_calls.limit);
186
+
187
+ // Get usage history
188
+ const history = await sdk.getUsageHistory(30, "api_call");
189
+
190
+ // List billing plans
191
+ const plans = await sdk.listBillingPlans();
192
+
193
+ // Get subscription
194
+ const subscription = await sdk.getSubscription();
195
+ ```
196
+
197
+ ### Notifications
198
+
199
+ ```typescript
200
+ // List notifications
201
+ const notifications = await sdk.listNotifications();
202
+
203
+ // Mark as read
204
+ await sdk.markNotificationAsRead("notification-123");
205
+
206
+ // Mark all as read
207
+ await sdk.markAllNotificationsAsRead();
208
+
209
+ // Delete notification
210
+ await sdk.deleteNotification("notification-123");
211
+ ```
212
+
213
+ ### Settings
214
+
215
+ ```typescript
216
+ // Get settings
217
+ const settings = await sdk.getSettings();
218
+
219
+ // Update account
220
+ await sdk.updateAccount({
221
+ full_name: "John Smith",
222
+ email: "newemail@example.com",
223
+ });
224
+
225
+ // Update preferences
226
+ await sdk.updatePreferences({
227
+ theme: "dark",
228
+ notifications: true,
229
+ });
230
+
231
+ // Get guidelines
232
+ const guidelines = await sdk.getGuidelines();
233
+ ```
234
+
235
+ ### WebSocket (Real-time Updates)
236
+
237
+ ```typescript
238
+ import { RecursorSDK, RecursorWebSocket } from "@recursor/sdk";
239
+
240
+ // Login first to get access token
241
+ await sdk.login({ email: "user@example.com", password: "password" });
242
+
243
+ // Create WebSocket connection
244
+ const ws = await sdk.connectWebSocket();
245
+
246
+ // Subscribe to events
247
+ ws.on("connected", (data) => {
248
+ console.log("WebSocket connected:", data);
249
+ });
250
+
251
+ ws.on("notification.new", (notification) => {
252
+ console.log("New notification:", notification);
253
+ });
254
+
255
+ ws.on("usage.updated", (usage) => {
256
+ console.log("Usage updated:", usage);
257
+ });
258
+
259
+ ws.on("activity.new", (activity) => {
260
+ console.log("New activity:", activity);
261
+ });
262
+
263
+ // Send ping (automatic, but can be manual)
264
+ ws.send({ type: "ping" });
265
+
266
+ // Disconnect when done
267
+ sdk.disconnectWebSocket();
268
+ ```
269
+
270
+ ### Gateway Endpoints
271
+
272
+ ```typescript
273
+ // LLM Gateway
274
+ const policy = await sdk.getLLMGatewayPolicy();
275
+ const chatResponse = await sdk.gatewayChat({
276
+ provider: "openai",
277
+ model: "gpt-4",
278
+ messages: [
279
+ { role: "user", content: "Hello!" }
280
+ ],
281
+ call_provider: true,
282
+ });
283
+
284
+ // Robotics Gateway
285
+ const roboticsPolicy = await sdk.getRoboticsGatewayPolicy();
286
+ const roboticsResult = await sdk.roboticsGatewayObserve({
287
+ state: { position: [0, 0, 0] },
288
+ command: { action: "move" },
289
+ });
290
+
291
+ // AV Gateway
292
+ const avPolicy = await sdk.getAvGatewayPolicy();
293
+ const avResult = await sdk.avGatewayObserve({
294
+ sensors: { camera: "data" },
295
+ state: { speed: 60 },
296
+ action: { brake: false },
297
+ timestamp: Date.now(),
298
+ vehicle_id: "vehicle-123",
299
+ });
300
+ ```
301
+
302
+ ## Environment Variables
303
+
304
+ - `RECURSOR_API_URL` - API base URL (default: `http://localhost:8000/api/v1`)
305
+ - `RECURSOR_API_KEY` - API key for authentication
306
+ - `RECURSOR_ACCESS_TOKEN` - Access token for authentication
307
+
308
+ ## API Reference
309
+
310
+ ### Authentication Methods
311
+ - `register(userData)` - Register new user
312
+ - `login(credentials)` - Login and get access token
313
+ - `logout()` - Logout current user
314
+ - `refreshToken(refreshToken)` - Refresh access token
315
+ - `getProfile()` - Get user profile
316
+ - `updateProfile(updates)` - Update user profile
317
+ - `changePassword(passwordChange)` - Change password
318
+ - `generateApiKey()` - Generate API key
319
+ - `revokeApiKey()` - Revoke API key
320
+ - `getPasswordRequirements()` - Get password requirements
321
+
322
+ ### Project Methods
323
+ - `createProject(projectData)` - Create project
324
+ - `getProject(projectId)` - Get project
325
+ - `listProjects(organizationId?)` - List projects
326
+ - `updateProject(projectId, updates)` - Update project
327
+ - `deleteProject(projectId)` - Delete project
328
+ - `regenerateProjectApiKey(projectId)` - Regenerate API key
329
+ - `getMcpConfig(projectId)` - Get MCP configuration
330
+ - `getMcpStats(projectId)` - Get MCP statistics
331
+
332
+ ### Organization Methods
333
+ - `createOrganization(orgData)` - Create organization
334
+ - `listOrganizations()` - List organizations
335
+ - `getOrganization(orgId)` - Get organization
336
+ - `updateOrganization(orgId, updates)` - Update organization
337
+ - `addMemberToOrganization(orgId, userId)` - Add member
338
+ - `removeMemberFromOrganization(orgId, userId)` - Remove member
339
+
340
+ ### Correction Methods
341
+ - `createCorrection(correctionData)` - Create correction
342
+ - `listCorrections(options?)` - List corrections
343
+ - `searchCorrections(query, limit, organizationId?)` - Search corrections
344
+ - `getCorrection(correctionId)` - Get correction
345
+ - `updateCorrection(correctionId, updates)` - Update correction
346
+ - `getCorrectionStats()` - Get statistics
347
+
348
+ ### Code Intelligence Methods
349
+ - `detectIntent(args)` - Detect intent
350
+ - `getIntentHistory(limit, projectId?)` - Get intent history
351
+ - `correctCode(code, language, projectProfile?)` - Correct code
352
+ - `correctConfig(config, configType)` - Correct config
353
+ - `correctDocumentation(markdown, docType)` - Correct documentation
354
+ - `applyAutoCorrections(userId, modelName, corrections)` - Apply auto corrections
355
+ - `getTrustScore(userId, modelName)` - Get trust score
356
+ - `submitFeedback(predictionId, accepted)` - Submit feedback
357
+ - `getAutoCorrectStats(userId)` - Get auto correction stats
358
+ - `getPatterns(userId?)` - Get patterns
359
+ - `getAnalyticsDashboard(userId, period, projectId?)` - Get analytics dashboard
360
+ - `getTimeSaved(userId, period, projectId?)` - Get time saved metrics
361
+ - `getQualityMetrics(userId, period, projectId?)` - Get quality metrics
362
+ - `getAIAgentMetrics(userId, projectId?)` - Get AI agent metrics
363
+
364
+ ### Billing Methods
365
+ - `getUsage()` - Get current usage
366
+ - `getUsageHistory(days, resourceType?)` - Get usage history
367
+ - `listBillingPlans()` - List billing plans
368
+ - `getSubscription()` - Get subscription
369
+
370
+ ### Notification Methods
371
+ - `listNotifications()` - List notifications
372
+ - `markNotificationAsRead(notificationId)` - Mark as read
373
+ - `markAllNotificationsAsRead()` - Mark all as read
374
+ - `deleteNotification(notificationId)` - Delete notification
375
+
376
+ ### Settings Methods
377
+ - `getSettings()` - Get settings
378
+ - `updateAccount(updates)` - Update account
379
+ - `updatePreferences(preferences)` - Update preferences
380
+ - `getGuidelines()` - Get guidelines
381
+ - `changePasswordViaSettings(passwordChange)` - Change password
382
+ - `deleteAccount(confirm)` - Delete account
383
+
384
+ ### Activity Methods
385
+ - `listActivityLogs(page, pageSize)` - List activity logs
386
+ - `exportActivityLogs()` - Export activity logs
387
+
388
+ ### WebSocket Methods
389
+ - `createWebSocket()` - Create WebSocket client
390
+ - `connectWebSocket()` - Connect WebSocket
391
+ - `disconnectWebSocket()` - Disconnect WebSocket
392
+
393
+ ## Error Handling
394
+
395
+ The SDK throws errors for failed requests:
396
+
397
+ ```typescript
398
+ try {
399
+ await sdk.login({ email: "wrong", password: "wrong" });
400
+ } catch (error) {
401
+ console.error("Login failed:", error.message);
402
+ // Error: HTTP 401: Incorrect email or password
403
+ }
404
+ ```
405
+
406
+ ## TypeScript Support
407
+
408
+ Full TypeScript support with type definitions included. All methods are typed with proper interfaces.
409
+
410
+ ## License
411
+
412
+ MIT License. See `LICENSE` file.