@rainfall-devkit/sdk 0.2.1 → 0.2.3

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.
@@ -0,0 +1,1162 @@
1
+ import { WebSocket } from 'ws';
2
+ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
3
+ import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
4
+ import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
5
+
6
+ /**
7
+ * MCP Proxy Hub - Manages external MCP clients (Chrome DevTools, etc.)
8
+ *
9
+ * This service allows the Rainfall daemon to act as a central MCP hub:
10
+ * - External MCP servers (like Chrome DevTools) connect via WebSocket or stdio
11
+ * - Their tools are exposed as native Rainfall tools with optional namespacing
12
+ * - Tool calls are proxied back to the appropriate MCP client
13
+ * - Multiple clients can connect simultaneously with unique namespaces
14
+ */
15
+
16
+ type MCPTransportType = 'stdio' | 'websocket' | 'http';
17
+ interface MCPClientConfig {
18
+ name: string;
19
+ transport: MCPTransportType;
20
+ command?: string;
21
+ args?: string[];
22
+ env?: Record<string, string>;
23
+ url?: string;
24
+ headers?: Record<string, string>;
25
+ autoConnect?: boolean;
26
+ }
27
+ interface MCPClientInfo {
28
+ name: string;
29
+ client: Client;
30
+ transport: StdioClientTransport | StreamableHTTPClientTransport | WebSocket;
31
+ transportType: MCPTransportType;
32
+ tools: MCPToolInfo[];
33
+ connectedAt: string;
34
+ lastUsed: string;
35
+ config: MCPClientConfig;
36
+ status: 'connected' | 'disconnected' | 'error';
37
+ error?: string;
38
+ }
39
+ interface MCPToolInfo {
40
+ name: string;
41
+ description: string;
42
+ inputSchema: unknown;
43
+ serverName: string;
44
+ }
45
+ interface MCPProxyOptions {
46
+ /** Enable debug logging */
47
+ debug?: boolean;
48
+ /** Auto-reconnect disconnected clients */
49
+ autoReconnect?: boolean;
50
+ /** Reconnect delay in ms */
51
+ reconnectDelay?: number;
52
+ /** Tool call timeout in ms */
53
+ toolTimeout?: number;
54
+ /** Refresh interval for tool lists in ms */
55
+ refreshInterval?: number;
56
+ }
57
+ declare class MCPProxyHub {
58
+ private clients;
59
+ private options;
60
+ private refreshTimer?;
61
+ private reconnectTimeouts;
62
+ private requestId;
63
+ constructor(options?: MCPProxyOptions);
64
+ /**
65
+ * Initialize the MCP proxy hub
66
+ */
67
+ initialize(): Promise<void>;
68
+ /**
69
+ * Shutdown the MCP proxy hub and disconnect all clients
70
+ */
71
+ shutdown(): Promise<void>;
72
+ /**
73
+ * Connect to an MCP server
74
+ */
75
+ connectClient(config: MCPClientConfig): Promise<string>;
76
+ /**
77
+ * Disconnect a specific MCP client
78
+ */
79
+ disconnectClient(name: string): Promise<void>;
80
+ /**
81
+ * Schedule a reconnection attempt
82
+ */
83
+ private scheduleReconnect;
84
+ /**
85
+ * Call a tool on the appropriate MCP client
86
+ */
87
+ callTool(toolName: string, args: Record<string, unknown>, options?: {
88
+ timeout?: number;
89
+ namespace?: string;
90
+ }): Promise<unknown>;
91
+ /**
92
+ * Format MCP tool result for consistent output
93
+ */
94
+ private formatToolResult;
95
+ /**
96
+ * Get all tools from all connected MCP clients
97
+ * Optionally with namespace prefix
98
+ */
99
+ getAllTools(options?: {
100
+ namespacePrefix?: boolean;
101
+ }): MCPToolInfo[];
102
+ /**
103
+ * Get tools from a specific client
104
+ */
105
+ getClientTools(clientName: string): MCPToolInfo[];
106
+ /**
107
+ * Get list of connected MCP clients
108
+ */
109
+ listClients(): Array<{
110
+ name: string;
111
+ status: string;
112
+ toolCount: number;
113
+ connectedAt: string;
114
+ lastUsed: string;
115
+ transportType: MCPTransportType;
116
+ }>;
117
+ /**
118
+ * Get client info by name
119
+ */
120
+ getClient(name: string): MCPClientInfo | undefined;
121
+ /**
122
+ * Refresh tool lists from all connected clients
123
+ */
124
+ refreshTools(): Promise<void>;
125
+ /**
126
+ * List resources from a specific client or all clients
127
+ */
128
+ listResources(clientName?: string): Promise<Array<{
129
+ clientName: string;
130
+ resources: unknown[];
131
+ }>>;
132
+ /**
133
+ * Read a resource from a specific client
134
+ */
135
+ readResource(uri: string, clientName?: string): Promise<unknown>;
136
+ /**
137
+ * List prompts from a specific client or all clients
138
+ */
139
+ listPrompts(clientName?: string): Promise<Array<{
140
+ clientName: string;
141
+ prompts: unknown[];
142
+ }>>;
143
+ /**
144
+ * Get a prompt from a specific client
145
+ */
146
+ getPrompt(name: string, args: Record<string, unknown>, clientName?: string): Promise<unknown>;
147
+ /**
148
+ * Health check for all connected clients
149
+ */
150
+ healthCheck(): Promise<Map<string, {
151
+ status: string;
152
+ responseTime: number;
153
+ error?: string;
154
+ }>>;
155
+ /**
156
+ * Start the automatic refresh timer
157
+ */
158
+ private startRefreshTimer;
159
+ /**
160
+ * Print available tools for a client
161
+ */
162
+ private printAvailableTools;
163
+ /**
164
+ * Debug logging
165
+ */
166
+ private log;
167
+ /**
168
+ * Get statistics about the MCP proxy hub
169
+ */
170
+ getStats(): {
171
+ totalClients: number;
172
+ totalTools: number;
173
+ clients: Array<{
174
+ name: string;
175
+ toolCount: number;
176
+ status: string;
177
+ transportType: MCPTransportType;
178
+ }>;
179
+ };
180
+ }
181
+
182
+ /**
183
+ * Core types for the Rainfall SDK
184
+ */
185
+ interface RainfallConfig {
186
+ apiKey: string;
187
+ baseUrl?: string;
188
+ timeout?: number;
189
+ retries?: number;
190
+ retryDelay?: number;
191
+ /** Pre-configured MCP clients to connect on daemon startup */
192
+ mcpClients?: MCPClientConfig[];
193
+ }
194
+ interface RequestOptions {
195
+ timeout?: number;
196
+ retries?: number;
197
+ retryDelay?: number;
198
+ }
199
+ interface ApiResponse<T = unknown> {
200
+ success: boolean;
201
+ data?: T;
202
+ error?: ApiError;
203
+ }
204
+ interface ApiError {
205
+ code: string;
206
+ message: string;
207
+ details?: Record<string, unknown>;
208
+ }
209
+ interface RateLimitInfo {
210
+ limit: number;
211
+ remaining: number;
212
+ resetAt: Date;
213
+ }
214
+ interface ToolSchema {
215
+ name: string;
216
+ description: string;
217
+ category: string;
218
+ parameters: unknown;
219
+ output: unknown;
220
+ metadata: Record<string, unknown>;
221
+ }
222
+ declare namespace Integrations {
223
+ interface GitHub {
224
+ issues: {
225
+ create(params: {
226
+ owner: string;
227
+ repo: string;
228
+ title: string;
229
+ body?: string;
230
+ }): Promise<unknown>;
231
+ list(params: {
232
+ owner: string;
233
+ repo: string;
234
+ state?: 'open' | 'closed' | 'all';
235
+ }): Promise<unknown>;
236
+ get(params: {
237
+ owner: string;
238
+ repo: string;
239
+ issue_number: number;
240
+ }): Promise<unknown>;
241
+ update(params: {
242
+ owner: string;
243
+ repo: string;
244
+ issue_number: number;
245
+ title?: string;
246
+ body?: string;
247
+ state?: 'open' | 'closed';
248
+ }): Promise<unknown>;
249
+ addComment(params: {
250
+ owner: string;
251
+ repo: string;
252
+ issue_number: number;
253
+ body: string;
254
+ }): Promise<unknown>;
255
+ };
256
+ repos: {
257
+ get(params: {
258
+ owner: string;
259
+ repo: string;
260
+ }): Promise<unknown>;
261
+ listBranches(params: {
262
+ owner: string;
263
+ repo: string;
264
+ }): Promise<unknown>;
265
+ };
266
+ pullRequests: {
267
+ list(params: {
268
+ owner: string;
269
+ repo: string;
270
+ state?: 'open' | 'closed' | 'all';
271
+ }): Promise<unknown>;
272
+ get(params: {
273
+ owner: string;
274
+ repo: string;
275
+ pullNumber: number;
276
+ }): Promise<unknown>;
277
+ };
278
+ }
279
+ interface Notion {
280
+ pages: {
281
+ create(params: {
282
+ parent: unknown;
283
+ properties: unknown;
284
+ children?: unknown[];
285
+ }): Promise<unknown>;
286
+ retrieve(params: {
287
+ pageId: string;
288
+ }): Promise<unknown>;
289
+ update(params: {
290
+ pageId: string;
291
+ properties: unknown;
292
+ }): Promise<unknown>;
293
+ };
294
+ databases: {
295
+ query(params: {
296
+ databaseId: string;
297
+ filter?: unknown;
298
+ sorts?: unknown[];
299
+ }): Promise<unknown>;
300
+ retrieve(params: {
301
+ databaseId: string;
302
+ }): Promise<unknown>;
303
+ };
304
+ blocks: {
305
+ appendChildren(params: {
306
+ blockId: string;
307
+ children: unknown[];
308
+ }): Promise<unknown>;
309
+ retrieveChildren(params: {
310
+ blockId: string;
311
+ }): Promise<unknown>;
312
+ };
313
+ }
314
+ interface Linear {
315
+ issues: {
316
+ create(params: {
317
+ title: string;
318
+ description?: string;
319
+ teamId?: string;
320
+ assigneeId?: string;
321
+ priority?: number;
322
+ labels?: string[];
323
+ }): Promise<unknown>;
324
+ list(params?: {
325
+ filter?: unknown;
326
+ orderBy?: string;
327
+ }): Promise<unknown>;
328
+ get(params: {
329
+ issueId: string;
330
+ }): Promise<unknown>;
331
+ update(params: {
332
+ issueId: string;
333
+ title?: string;
334
+ description?: string;
335
+ state?: string;
336
+ }): Promise<unknown>;
337
+ archive(params: {
338
+ issueId: string;
339
+ }): Promise<unknown>;
340
+ };
341
+ teams: {
342
+ list(): Promise<unknown>;
343
+ };
344
+ }
345
+ interface Slack {
346
+ messages: {
347
+ send(params: {
348
+ channelId: string;
349
+ text: string;
350
+ blocks?: unknown[];
351
+ }): Promise<unknown>;
352
+ list(params: {
353
+ channelId: string;
354
+ limit?: number;
355
+ }): Promise<unknown>;
356
+ };
357
+ channels: {
358
+ list(): Promise<unknown>;
359
+ };
360
+ users: {
361
+ list(): Promise<unknown>;
362
+ };
363
+ reactions: {
364
+ add(params: {
365
+ channelId: string;
366
+ timestamp: string;
367
+ reaction: string;
368
+ }): Promise<unknown>;
369
+ };
370
+ }
371
+ interface Figma {
372
+ files: {
373
+ get(params: {
374
+ fileKey: string;
375
+ }): Promise<unknown>;
376
+ getNodes(params: {
377
+ fileKey: string;
378
+ nodeIds: string[];
379
+ }): Promise<unknown>;
380
+ getImages(params: {
381
+ fileKey: string;
382
+ nodeIds: string[];
383
+ format?: 'png' | 'svg' | 'pdf';
384
+ }): Promise<unknown>;
385
+ getComments(params: {
386
+ fileKey: string;
387
+ }): Promise<unknown>;
388
+ postComment(params: {
389
+ fileKey: string;
390
+ message: string;
391
+ nodeId?: string;
392
+ }): Promise<unknown>;
393
+ };
394
+ projects: {
395
+ list(params: {
396
+ teamId: string;
397
+ }): Promise<unknown>;
398
+ getFiles(params: {
399
+ projectId: string;
400
+ }): Promise<unknown>;
401
+ };
402
+ }
403
+ interface Stripe {
404
+ customers: {
405
+ create(params: {
406
+ email: string;
407
+ name?: string;
408
+ metadata?: Record<string, string>;
409
+ }): Promise<unknown>;
410
+ retrieve(params: {
411
+ customerId: string;
412
+ }): Promise<unknown>;
413
+ update(params: {
414
+ customerId: string;
415
+ metadata?: Record<string, string>;
416
+ }): Promise<unknown>;
417
+ listPaymentMethods(params: {
418
+ customerId: string;
419
+ }): Promise<unknown>;
420
+ };
421
+ paymentIntents: {
422
+ create(params: {
423
+ amount: number;
424
+ currency: string;
425
+ customer?: string;
426
+ }): Promise<unknown>;
427
+ retrieve(params: {
428
+ paymentIntentId: string;
429
+ }): Promise<unknown>;
430
+ confirm(params: {
431
+ paymentIntentId: string;
432
+ }): Promise<unknown>;
433
+ };
434
+ subscriptions: {
435
+ create(params: {
436
+ customer: string;
437
+ items: unknown[];
438
+ }): Promise<unknown>;
439
+ retrieve(params: {
440
+ subscriptionId: string;
441
+ }): Promise<unknown>;
442
+ cancel(params: {
443
+ subscriptionId: string;
444
+ }): Promise<unknown>;
445
+ };
446
+ }
447
+ }
448
+ declare namespace Memory {
449
+ interface MemoryClient {
450
+ create(params: {
451
+ content: string;
452
+ keywords?: string[];
453
+ metadata?: Record<string, unknown>;
454
+ }): Promise<unknown>;
455
+ get(params: {
456
+ memoryId: string;
457
+ }): Promise<unknown>;
458
+ recall(params: {
459
+ query: string;
460
+ topK?: number;
461
+ threshold?: number;
462
+ }): Promise<unknown>;
463
+ list(params?: {
464
+ limit?: number;
465
+ offset?: number;
466
+ }): Promise<unknown>;
467
+ update(params: {
468
+ memoryId: string;
469
+ content?: string;
470
+ metadata?: Record<string, unknown>;
471
+ }): Promise<unknown>;
472
+ delete(params: {
473
+ memoryId: string;
474
+ }): Promise<unknown>;
475
+ }
476
+ }
477
+ declare namespace Articles {
478
+ interface ArticlesClient {
479
+ search(params: {
480
+ query: string;
481
+ limit?: number;
482
+ }): Promise<unknown>;
483
+ create(params: {
484
+ title: string;
485
+ content: string;
486
+ topics?: string[];
487
+ metadata?: Record<string, unknown>;
488
+ }): Promise<unknown>;
489
+ createFromUrl(params: {
490
+ url: string;
491
+ }): Promise<unknown>;
492
+ fetch(params: {
493
+ articleId: string;
494
+ }): Promise<unknown>;
495
+ recent(params?: {
496
+ limit?: number;
497
+ }): Promise<unknown>;
498
+ relevant(params: {
499
+ query: string;
500
+ limit?: number;
501
+ }): Promise<unknown>;
502
+ summarize(params: {
503
+ articleId?: string;
504
+ text?: string;
505
+ length?: 'short' | 'medium' | 'long';
506
+ }): Promise<unknown>;
507
+ extractTopics(params: {
508
+ text: string;
509
+ }): Promise<unknown>;
510
+ }
511
+ }
512
+ declare namespace Web {
513
+ interface WebClient {
514
+ search: {
515
+ exa(params: {
516
+ query: string;
517
+ numResults?: number;
518
+ includeDomains?: string[];
519
+ excludeDomains?: string[];
520
+ }): Promise<unknown>;
521
+ perplexity(params: {
522
+ query: string;
523
+ }): Promise<unknown>;
524
+ };
525
+ fetch(params: {
526
+ url: string;
527
+ headers?: Record<string, string>;
528
+ }): Promise<unknown>;
529
+ htmlToMarkdown(params: {
530
+ html: string;
531
+ baseUrl?: string;
532
+ }): Promise<unknown>;
533
+ extractHtml(params: {
534
+ html: string;
535
+ selector: string;
536
+ }): Promise<unknown>;
537
+ }
538
+ }
539
+ declare namespace AI {
540
+ interface AIClient {
541
+ embeddings: {
542
+ document(params: {
543
+ text: string;
544
+ }): Promise<unknown>;
545
+ query(params: {
546
+ text: string;
547
+ }): Promise<unknown>;
548
+ image(params: {
549
+ imageBase64: string;
550
+ }): Promise<unknown>;
551
+ };
552
+ image: {
553
+ generate(params: {
554
+ prompt: string;
555
+ size?: '256x256' | '512x512' | '1024x1024';
556
+ }): Promise<unknown>;
557
+ };
558
+ ocr(params: {
559
+ imageBase64: string;
560
+ }): Promise<unknown>;
561
+ vision(params: {
562
+ imageBase64: string;
563
+ prompt?: string;
564
+ }): Promise<unknown>;
565
+ chat(params: {
566
+ messages: Array<{
567
+ role: 'user' | 'assistant' | 'system';
568
+ content: string;
569
+ }>;
570
+ model?: string;
571
+ }): Promise<unknown>;
572
+ complete(params: {
573
+ prompt: string;
574
+ suffix?: string;
575
+ }): Promise<unknown>;
576
+ classify(params: {
577
+ text: string;
578
+ labels: string[];
579
+ }): Promise<unknown>;
580
+ segment(params: {
581
+ text: string;
582
+ maxLength?: number;
583
+ }): Promise<unknown[]>;
584
+ }
585
+ }
586
+ declare namespace Data {
587
+ interface DataClient {
588
+ csv: {
589
+ query(params: {
590
+ sql: string;
591
+ csvData?: string;
592
+ fileId?: string;
593
+ }): Promise<unknown>;
594
+ convert(params: {
595
+ data: string;
596
+ fromFormat: string;
597
+ toFormat: string;
598
+ }): Promise<unknown>;
599
+ };
600
+ scripts: {
601
+ create(params: {
602
+ name: string;
603
+ code: string;
604
+ language?: string;
605
+ }): Promise<unknown>;
606
+ execute(params: {
607
+ name: string;
608
+ params?: Record<string, unknown>;
609
+ }): Promise<unknown>;
610
+ list(): Promise<unknown>;
611
+ update(params: {
612
+ name: string;
613
+ code: string;
614
+ }): Promise<unknown>;
615
+ delete(params: {
616
+ name: string;
617
+ }): Promise<unknown>;
618
+ };
619
+ similarity: {
620
+ search(params: {
621
+ query: number[];
622
+ embeddings: number[][];
623
+ topK?: number;
624
+ }): Promise<unknown>;
625
+ duckDbSearch(params: {
626
+ query: number[];
627
+ tableName: string;
628
+ }): Promise<unknown>;
629
+ };
630
+ }
631
+ }
632
+ declare namespace Utils {
633
+ interface UtilsClient {
634
+ mermaid(params: {
635
+ diagram: string;
636
+ }): Promise<unknown>;
637
+ documentConvert(params: {
638
+ document: string;
639
+ mimeType: string;
640
+ format: string;
641
+ }): Promise<unknown>;
642
+ regex: {
643
+ match(params: {
644
+ text: string;
645
+ pattern: string;
646
+ flags?: string;
647
+ }): Promise<unknown>;
648
+ replace(params: {
649
+ text: string;
650
+ pattern: string;
651
+ replacement: string;
652
+ flags?: string;
653
+ }): Promise<unknown>;
654
+ };
655
+ jsonExtract(params: {
656
+ text: string;
657
+ }): Promise<unknown>;
658
+ digest(params: {
659
+ data: string;
660
+ }): Promise<string>;
661
+ monteCarlo(params: {
662
+ iterations?: number;
663
+ formula: string;
664
+ variables?: Record<string, {
665
+ mean: number;
666
+ stdDev: number;
667
+ }>;
668
+ }): Promise<unknown>;
669
+ }
670
+ }
671
+
672
+ /**
673
+ * Parameter validation for Rainfall SDK
674
+ * Fetches node schemas and validates params before execution
675
+ */
676
+
677
+ interface ParamSchema {
678
+ type: string;
679
+ description?: string;
680
+ optional?: boolean;
681
+ items?: ParamSchema;
682
+ properties?: Record<string, ParamSchema>;
683
+ [key: string]: unknown;
684
+ }
685
+ interface ToolParamsSchema {
686
+ name: string;
687
+ description: string;
688
+ category: string;
689
+ parameters: Record<string, ParamSchema>;
690
+ output?: unknown;
691
+ metadata?: Record<string, unknown>;
692
+ }
693
+ interface ValidationResult {
694
+ valid: boolean;
695
+ errors: ValidationIssue[];
696
+ }
697
+ interface ValidationIssue {
698
+ path: string;
699
+ message: string;
700
+ received?: unknown;
701
+ expected?: string;
702
+ }
703
+ /**
704
+ * Fetch and cache tool schema from the API
705
+ */
706
+ declare function fetchToolSchema(client: RainfallClient, toolId: string): Promise<ToolParamsSchema>;
707
+ /**
708
+ * Clear the schema cache (useful for testing or when schemas may have changed)
709
+ */
710
+ declare function clearSchemaCache(): void;
711
+ /**
712
+ * Validate params against a tool's schema
713
+ */
714
+ declare function validateParams(schema: ToolParamsSchema, params: Record<string, unknown> | undefined, toolId: string): ValidationResult;
715
+ /**
716
+ * Format validation errors into a readable message
717
+ */
718
+ declare function formatValidationErrors(result: ValidationResult): string;
719
+
720
+ /**
721
+ * Core HTTP client for Rainfall SDK
722
+ */
723
+
724
+ declare class RainfallClient {
725
+ private readonly apiKey;
726
+ private readonly baseUrl;
727
+ private readonly defaultTimeout;
728
+ private readonly defaultRetries;
729
+ private readonly defaultRetryDelay;
730
+ private lastRateLimitInfo?;
731
+ private subscriberId?;
732
+ constructor(config: RainfallConfig);
733
+ /**
734
+ * Get the last rate limit info from the API
735
+ */
736
+ getRateLimitInfo(): RateLimitInfo | undefined;
737
+ /**
738
+ * Make an authenticated request to the Rainfall API
739
+ */
740
+ request<T = unknown>(path: string, options?: {
741
+ method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
742
+ body?: unknown;
743
+ headers?: Record<string, string>;
744
+ }, requestOptions?: RequestOptions): Promise<T>;
745
+ /**
746
+ * Execute a tool/node by ID
747
+ *
748
+ * @param toolId - The ID of the tool/node to execute
749
+ * @param params - Parameters to pass to the tool
750
+ * @param options - Request options including skipValidation to bypass param validation
751
+ */
752
+ executeTool<T = unknown>(toolId: string, params?: Record<string, unknown>, options?: RequestOptions & {
753
+ skipValidation?: boolean;
754
+ }): Promise<T>;
755
+ /**
756
+ * Validate parameters for a tool without executing it
757
+ * Fetches the tool schema and validates the provided params
758
+ *
759
+ * @param toolId - The ID of the tool to validate params for
760
+ * @param params - Parameters to validate
761
+ * @returns Validation result with detailed error information
762
+ *
763
+ * @example
764
+ * ```typescript
765
+ * const result = await client.validateToolParams('finviz-quotes', { tickers: ['AAPL'] });
766
+ * if (!result.valid) {
767
+ * console.log('Validation errors:', result.errors);
768
+ * }
769
+ * ```
770
+ */
771
+ validateToolParams(toolId: string, params?: Record<string, unknown>): Promise<ValidationResult>;
772
+ /**
773
+ * List all available tools
774
+ */
775
+ listTools(): Promise<Array<{
776
+ id: string;
777
+ name: string;
778
+ description: string;
779
+ category: string;
780
+ }>>;
781
+ /**
782
+ * Get tool schema/parameters
783
+ *
784
+ * @param toolId - The ID of the tool to get schema for
785
+ * @returns Tool schema including parameters and output definitions
786
+ */
787
+ getToolSchema(toolId: string): Promise<ToolSchema>;
788
+ /**
789
+ * Get subscriber info
790
+ */
791
+ getMe(): Promise<{
792
+ id: string;
793
+ name: string;
794
+ email?: string;
795
+ plan?: string;
796
+ billingStatus?: string;
797
+ usage: {
798
+ callsThisMonth: number;
799
+ callsLimit: number;
800
+ };
801
+ }>;
802
+ /**
803
+ * Ensure we have a subscriber ID, fetching it if necessary
804
+ */
805
+ private ensureSubscriberId;
806
+ private sleep;
807
+ /**
808
+ * OpenAI-compatible chat completions with tool support
809
+ */
810
+ chatCompletions(params: {
811
+ subscriber_id: string;
812
+ messages: Array<{
813
+ role: string;
814
+ content: string;
815
+ name?: string;
816
+ }>;
817
+ model?: string;
818
+ stream?: boolean;
819
+ temperature?: number;
820
+ max_tokens?: number;
821
+ tools?: unknown[];
822
+ tool_choice?: string | {
823
+ type: string;
824
+ function?: {
825
+ name: string;
826
+ };
827
+ };
828
+ conversation_id?: string;
829
+ agent_name?: string;
830
+ incognito?: boolean;
831
+ tool_priority?: 'local' | 'rainfall' | 'serverside' | 'stacked';
832
+ enable_stacked?: boolean;
833
+ }): Promise<unknown>;
834
+ /**
835
+ * List available models (OpenAI-compatible format)
836
+ */
837
+ listModels(subscriberId?: string): Promise<Array<{
838
+ id: string;
839
+ [key: string]: unknown;
840
+ }>>;
841
+ }
842
+
843
+ /**
844
+ * Integrations namespace for Rainfall SDK
845
+ * GitHub, Notion, Linear, Slack, Figma, Stripe
846
+ */
847
+
848
+ declare class IntegrationsNamespace {
849
+ private client;
850
+ constructor(client: RainfallClient);
851
+ get github(): Integrations.GitHub;
852
+ get notion(): Integrations.Notion;
853
+ get linear(): Integrations.Linear;
854
+ get slack(): Integrations.Slack;
855
+ get figma(): Integrations.Figma;
856
+ get stripe(): Integrations.Stripe;
857
+ }
858
+
859
+ declare class Rainfall {
860
+ private readonly client;
861
+ private _integrations?;
862
+ private _memory?;
863
+ private _articles?;
864
+ private _web?;
865
+ private _ai?;
866
+ private _data?;
867
+ private _utils?;
868
+ constructor(config: RainfallConfig);
869
+ /**
870
+ * Integrations namespace - GitHub, Notion, Linear, Slack, Figma, Stripe
871
+ *
872
+ * @example
873
+ * ```typescript
874
+ * // GitHub
875
+ * await rainfall.integrations.github.issues.create({
876
+ * owner: 'facebook',
877
+ * repo: 'react',
878
+ * title: 'Bug report'
879
+ * });
880
+ *
881
+ * // Slack
882
+ * await rainfall.integrations.slack.messages.send({
883
+ * channelId: 'C123456',
884
+ * text: 'Hello team!'
885
+ * });
886
+ *
887
+ * // Linear
888
+ * const issues = await rainfall.integrations.linear.issues.list();
889
+ * ```
890
+ */
891
+ get integrations(): IntegrationsNamespace;
892
+ /**
893
+ * Memory namespace - Semantic memory storage and retrieval
894
+ *
895
+ * @example
896
+ * ```typescript
897
+ * // Store a memory
898
+ * await rainfall.memory.create({
899
+ * content: 'User prefers dark mode',
900
+ * keywords: ['preference', 'ui']
901
+ * });
902
+ *
903
+ * // Recall similar memories
904
+ * const memories = await rainfall.memory.recall({
905
+ * query: 'user preferences',
906
+ * topK: 5
907
+ * });
908
+ * ```
909
+ */
910
+ get memory(): Memory.MemoryClient;
911
+ /**
912
+ * Articles namespace - News aggregation and article management
913
+ *
914
+ * @example
915
+ * ```typescript
916
+ * // Search news
917
+ * const articles = await rainfall.articles.search({
918
+ * query: 'artificial intelligence'
919
+ * });
920
+ *
921
+ * // Create from URL
922
+ * const article = await rainfall.articles.createFromUrl({
923
+ * url: 'https://example.com/article'
924
+ * });
925
+ *
926
+ * // Summarize
927
+ * const summary = await rainfall.articles.summarize({
928
+ * text: article.content
929
+ * });
930
+ * ```
931
+ */
932
+ get articles(): Articles.ArticlesClient;
933
+ /**
934
+ * Web namespace - Web search, scraping, and content extraction
935
+ *
936
+ * @example
937
+ * ```typescript
938
+ * // Search with Exa
939
+ * const results = await rainfall.web.search.exa({
940
+ * query: 'latest AI research'
941
+ * });
942
+ *
943
+ * // Fetch and convert
944
+ * const html = await rainfall.web.fetch({ url: 'https://example.com' });
945
+ * const markdown = await rainfall.web.htmlToMarkdown({ html });
946
+ *
947
+ * // Extract specific elements
948
+ * const links = await rainfall.web.extractHtml({
949
+ * html,
950
+ * selector: 'a[href]'
951
+ * });
952
+ * ```
953
+ */
954
+ get web(): Web.WebClient;
955
+ /**
956
+ * AI namespace - Embeddings, image generation, OCR, vision, chat
957
+ *
958
+ * @example
959
+ * ```typescript
960
+ * // Generate embeddings
961
+ * const embedding = await rainfall.ai.embeddings.document({
962
+ * text: 'Hello world'
963
+ * });
964
+ *
965
+ * // Generate image
966
+ * const image = await rainfall.ai.image.generate({
967
+ * prompt: 'A serene mountain landscape'
968
+ * });
969
+ *
970
+ * // OCR
971
+ * const text = await rainfall.ai.ocr({ imageBase64: '...' });
972
+ *
973
+ * // Chat
974
+ * const response = await rainfall.ai.chat({
975
+ * messages: [{ role: 'user', content: 'Hello!' }]
976
+ * });
977
+ * ```
978
+ */
979
+ get ai(): AI.AIClient;
980
+ /**
981
+ * Data namespace - CSV processing, scripts, similarity search
982
+ *
983
+ * @example
984
+ * ```typescript
985
+ * // Query CSV with SQL
986
+ * const results = await rainfall.data.csv.query({
987
+ * sql: 'SELECT * FROM data WHERE value > 100'
988
+ * });
989
+ *
990
+ * // Execute saved script
991
+ * const result = await rainfall.data.scripts.execute({
992
+ * name: 'my-script',
993
+ * params: { input: 'data' }
994
+ * });
995
+ * ```
996
+ */
997
+ get data(): Data.DataClient;
998
+ /**
999
+ * Utils namespace - Mermaid diagrams, document conversion, regex, JSON extraction
1000
+ *
1001
+ * @example
1002
+ * ```typescript
1003
+ * // Generate diagram
1004
+ * const diagram = await rainfall.utils.mermaid({
1005
+ * diagram: 'graph TD; A-->B;'
1006
+ * });
1007
+ *
1008
+ * // Convert document
1009
+ * const pdf = await rainfall.utils.documentConvert({
1010
+ * document: markdownContent,
1011
+ * mimeType: 'text/markdown',
1012
+ * format: 'pdf'
1013
+ * });
1014
+ *
1015
+ * // Extract JSON from text
1016
+ * const json = await rainfall.utils.jsonExtract({
1017
+ * text: 'Here is some data: {"key": "value"}'
1018
+ * });
1019
+ * ```
1020
+ */
1021
+ get utils(): Utils.UtilsClient;
1022
+ /**
1023
+ * Get the underlying HTTP client for advanced usage
1024
+ */
1025
+ getClient(): RainfallClient;
1026
+ /**
1027
+ * List all available tools
1028
+ */
1029
+ listTools(): Promise<{
1030
+ id: string;
1031
+ name: string;
1032
+ description: string;
1033
+ category: string;
1034
+ }[]>;
1035
+ /**
1036
+ * Get schema for a specific tool
1037
+ */
1038
+ getToolSchema(toolId: string): Promise<ToolSchema>;
1039
+ /**
1040
+ * Execute any tool by ID (low-level access)
1041
+ *
1042
+ * @param toolId - The ID of the tool to execute
1043
+ * @param params - Parameters to pass to the tool
1044
+ * @param options - Execution options including skipValidation to bypass param validation
1045
+ *
1046
+ * @example
1047
+ * ```typescript
1048
+ * // Execute with validation (default)
1049
+ * const result = await rainfall.executeTool('finviz-quotes', { tickers: ['AAPL'] });
1050
+ *
1051
+ * // Execute without validation
1052
+ * const result = await rainfall.executeTool('finviz-quotes', { tickers: ['AAPL'] }, { skipValidation: true });
1053
+ * ```
1054
+ */
1055
+ executeTool<T = unknown>(toolId: string, params?: Record<string, unknown>, options?: {
1056
+ skipValidation?: boolean;
1057
+ timeout?: number;
1058
+ retries?: number;
1059
+ retryDelay?: number;
1060
+ }): Promise<T>;
1061
+ /**
1062
+ * Validate parameters for a tool without executing it
1063
+ *
1064
+ * @param toolId - The ID of the tool to validate params for
1065
+ * @param params - Parameters to validate
1066
+ * @returns Validation result with detailed error information
1067
+ *
1068
+ * @example
1069
+ * ```typescript
1070
+ * const result = await rainfall.validateToolParams('finviz-quotes', { tickers: ['AAPL'] });
1071
+ * if (!result.valid) {
1072
+ * console.log('Validation errors:', result.errors);
1073
+ * }
1074
+ * ```
1075
+ */
1076
+ validateToolParams(toolId: string, params?: Record<string, unknown>): Promise<ValidationResult>;
1077
+ /**
1078
+ * Get current subscriber info and usage
1079
+ */
1080
+ getMe(): Promise<{
1081
+ id: string;
1082
+ name: string;
1083
+ email?: string;
1084
+ plan?: string;
1085
+ billingStatus?: string;
1086
+ usage: {
1087
+ callsThisMonth: number;
1088
+ callsLimit: number;
1089
+ };
1090
+ }>;
1091
+ /**
1092
+ * Get current rate limit info
1093
+ */
1094
+ getRateLimitInfo(): RateLimitInfo | undefined;
1095
+ /**
1096
+ * OpenAI-compatible chat completions with tool support
1097
+ *
1098
+ * @example
1099
+ * ```typescript
1100
+ * // Simple chat
1101
+ * const response = await rainfall.chatCompletions({
1102
+ * subscriber_id: 'my-subscriber',
1103
+ * messages: [{ role: 'user', content: 'Hello!' }],
1104
+ * model: 'llama-3.3-70b-versatile'
1105
+ * });
1106
+ *
1107
+ * // With tools
1108
+ * const response = await rainfall.chatCompletions({
1109
+ * subscriber_id: 'my-subscriber',
1110
+ * messages: [{ role: 'user', content: 'Search for AI news' }],
1111
+ * tools: [{ type: 'function', function: { name: 'web-search' } }],
1112
+ * enable_stacked: true
1113
+ * });
1114
+ *
1115
+ * // Streaming
1116
+ * const stream = await rainfall.chatCompletions({
1117
+ * subscriber_id: 'my-subscriber',
1118
+ * messages: [{ role: 'user', content: 'Tell me a story' }],
1119
+ * stream: true
1120
+ * });
1121
+ * ```
1122
+ */
1123
+ chatCompletions(params: {
1124
+ subscriber_id: string;
1125
+ messages: Array<{
1126
+ role: string;
1127
+ content: string;
1128
+ name?: string;
1129
+ }>;
1130
+ model?: string;
1131
+ stream?: boolean;
1132
+ temperature?: number;
1133
+ max_tokens?: number;
1134
+ tools?: unknown[];
1135
+ tool_choice?: string | {
1136
+ type: string;
1137
+ function?: {
1138
+ name: string;
1139
+ };
1140
+ };
1141
+ conversation_id?: string;
1142
+ agent_name?: string;
1143
+ incognito?: boolean;
1144
+ tool_priority?: 'local' | 'rainfall' | 'serverside' | 'stacked';
1145
+ enable_stacked?: boolean;
1146
+ }): Promise<unknown>;
1147
+ /**
1148
+ * List available models (OpenAI-compatible format)
1149
+ *
1150
+ * @example
1151
+ * ```typescript
1152
+ * const models = await rainfall.listModels();
1153
+ * console.log(models); // [{ id: 'llama-3.3-70b-versatile', ... }]
1154
+ * ```
1155
+ */
1156
+ listModels(subscriberId?: string): Promise<Array<{
1157
+ id: string;
1158
+ [key: string]: unknown;
1159
+ }>>;
1160
+ }
1161
+
1162
+ export { AI as A, Data as D, Integrations as I, Memory as M, type ParamSchema as P, type RainfallConfig as R, type ToolSchema as T, Utils as U, type ValidationIssue as V, Web as W, Rainfall as a, type ApiError as b, type ApiResponse as c, Articles as d, type RateLimitInfo as e, type RequestOptions as f, type MCPClientConfig as g, MCPProxyHub as h, type MCPClientInfo as i, type MCPToolInfo as j, type MCPTransportType as k, RainfallClient as l, type ToolParamsSchema as m, type ValidationResult as n, clearSchemaCache as o, fetchToolSchema as p, formatValidationErrors as q, validateParams as v };