@rainfall-devkit/sdk 0.1.1

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/dist/index.js ADDED
@@ -0,0 +1,771 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ AuthenticationError: () => AuthenticationError,
24
+ NetworkError: () => NetworkError,
25
+ NotFoundError: () => NotFoundError,
26
+ Rainfall: () => Rainfall,
27
+ RainfallClient: () => RainfallClient,
28
+ RainfallError: () => RainfallError,
29
+ RateLimitError: () => RateLimitError,
30
+ ServerError: () => ServerError,
31
+ TimeoutError: () => TimeoutError,
32
+ ToolNotFoundError: () => ToolNotFoundError,
33
+ VERSION: () => VERSION,
34
+ ValidationError: () => ValidationError
35
+ });
36
+ module.exports = __toCommonJS(index_exports);
37
+
38
+ // src/errors.ts
39
+ var RainfallError = class _RainfallError extends Error {
40
+ constructor(message, code, statusCode, details) {
41
+ super(message);
42
+ this.code = code;
43
+ this.statusCode = statusCode;
44
+ this.details = details;
45
+ this.name = "RainfallError";
46
+ Object.setPrototypeOf(this, _RainfallError.prototype);
47
+ }
48
+ toJSON() {
49
+ return {
50
+ name: this.name,
51
+ code: this.code,
52
+ message: this.message,
53
+ statusCode: this.statusCode,
54
+ details: this.details
55
+ };
56
+ }
57
+ };
58
+ var AuthenticationError = class _AuthenticationError extends RainfallError {
59
+ constructor(message = "Invalid API key", details) {
60
+ super(message, "AUTHENTICATION_ERROR", 401, details);
61
+ this.name = "AuthenticationError";
62
+ Object.setPrototypeOf(this, _AuthenticationError.prototype);
63
+ }
64
+ };
65
+ var RateLimitError = class _RateLimitError extends RainfallError {
66
+ retryAfter;
67
+ limit;
68
+ remaining;
69
+ resetAt;
70
+ constructor(message = "Rate limit exceeded", retryAfter = 60, limit = 0, remaining = 0, resetAt) {
71
+ super(message, "RATE_LIMIT_ERROR", 429, { retryAfter, limit, remaining });
72
+ this.name = "RateLimitError";
73
+ this.retryAfter = retryAfter;
74
+ this.limit = limit;
75
+ this.remaining = remaining;
76
+ this.resetAt = resetAt || new Date(Date.now() + retryAfter * 1e3);
77
+ Object.setPrototypeOf(this, _RateLimitError.prototype);
78
+ }
79
+ };
80
+ var ValidationError = class _ValidationError extends RainfallError {
81
+ constructor(message, details) {
82
+ super(message, "VALIDATION_ERROR", 400, details);
83
+ this.name = "ValidationError";
84
+ Object.setPrototypeOf(this, _ValidationError.prototype);
85
+ }
86
+ };
87
+ var NotFoundError = class _NotFoundError extends RainfallError {
88
+ constructor(resource, identifier) {
89
+ super(
90
+ `${resource}${identifier ? ` '${identifier}'` : ""} not found`,
91
+ "NOT_FOUND_ERROR",
92
+ 404,
93
+ { resource, identifier }
94
+ );
95
+ this.name = "NotFoundError";
96
+ Object.setPrototypeOf(this, _NotFoundError.prototype);
97
+ }
98
+ };
99
+ var ServerError = class _ServerError extends RainfallError {
100
+ constructor(message = "Internal server error", statusCode = 500) {
101
+ super(message, "SERVER_ERROR", statusCode);
102
+ this.name = "ServerError";
103
+ Object.setPrototypeOf(this, _ServerError.prototype);
104
+ }
105
+ };
106
+ var TimeoutError = class _TimeoutError extends RainfallError {
107
+ constructor(timeoutMs) {
108
+ super(`Request timed out after ${timeoutMs}ms`, "TIMEOUT_ERROR", 408);
109
+ this.name = "TimeoutError";
110
+ Object.setPrototypeOf(this, _TimeoutError.prototype);
111
+ }
112
+ };
113
+ var NetworkError = class _NetworkError extends RainfallError {
114
+ constructor(message = "Network error", details) {
115
+ super(message, "NETWORK_ERROR", void 0, details);
116
+ this.name = "NetworkError";
117
+ Object.setPrototypeOf(this, _NetworkError.prototype);
118
+ }
119
+ };
120
+ var ToolNotFoundError = class _ToolNotFoundError extends RainfallError {
121
+ constructor(toolId) {
122
+ super(`Tool '${toolId}' not found`, "TOOL_NOT_FOUND", 404, { toolId });
123
+ this.name = "ToolNotFoundError";
124
+ Object.setPrototypeOf(this, _ToolNotFoundError.prototype);
125
+ }
126
+ };
127
+ function parseErrorResponse(response, data) {
128
+ const statusCode = response.status;
129
+ if (statusCode === 429) {
130
+ const retryAfter = parseInt(response.headers.get("retry-after") || "60", 10);
131
+ const limit = parseInt(response.headers.get("x-ratelimit-limit") || "0", 10);
132
+ const remaining = parseInt(response.headers.get("x-ratelimit-remaining") || "0", 10);
133
+ const resetHeader = response.headers.get("x-ratelimit-reset");
134
+ const resetAt = resetHeader ? new Date(parseInt(resetHeader, 10) * 1e3) : void 0;
135
+ return new RateLimitError(
136
+ typeof data === "object" && data && "message" in data ? String(data.message) : "Rate limit exceeded",
137
+ retryAfter,
138
+ limit,
139
+ remaining,
140
+ resetAt
141
+ );
142
+ }
143
+ switch (statusCode) {
144
+ case 401:
145
+ return new AuthenticationError(
146
+ typeof data === "object" && data && "message" in data ? String(data.message) : "Invalid API key"
147
+ );
148
+ case 404:
149
+ return new NotFoundError(
150
+ typeof data === "object" && data && "resource" in data ? String(data.resource) : "Resource",
151
+ typeof data === "object" && data && "identifier" in data ? String(data.identifier) : void 0
152
+ );
153
+ case 400:
154
+ return new ValidationError(
155
+ typeof data === "object" && data && "message" in data ? String(data.message) : "Invalid request",
156
+ typeof data === "object" && data && "details" in data ? data.details : void 0
157
+ );
158
+ case 500:
159
+ case 502:
160
+ case 503:
161
+ case 504:
162
+ return new ServerError(
163
+ typeof data === "object" && data && "message" in data ? String(data.message) : "Server error",
164
+ statusCode
165
+ );
166
+ default:
167
+ return new RainfallError(
168
+ typeof data === "object" && data && "message" in data ? String(data.message) : `HTTP ${statusCode}`,
169
+ "UNKNOWN_ERROR",
170
+ statusCode,
171
+ typeof data === "object" ? data : void 0
172
+ );
173
+ }
174
+ }
175
+
176
+ // src/client.ts
177
+ var DEFAULT_BASE_URL = "https://olympic-api.pragma-digital.org/v1";
178
+ var DEFAULT_TIMEOUT = 3e4;
179
+ var DEFAULT_RETRIES = 3;
180
+ var DEFAULT_RETRY_DELAY = 1e3;
181
+ var RainfallClient = class {
182
+ apiKey;
183
+ baseUrl;
184
+ defaultTimeout;
185
+ defaultRetries;
186
+ defaultRetryDelay;
187
+ lastRateLimitInfo;
188
+ constructor(config) {
189
+ this.apiKey = config.apiKey;
190
+ this.baseUrl = config.baseUrl || DEFAULT_BASE_URL;
191
+ this.defaultTimeout = config.timeout || DEFAULT_TIMEOUT;
192
+ this.defaultRetries = config.retries ?? DEFAULT_RETRIES;
193
+ this.defaultRetryDelay = config.retryDelay || DEFAULT_RETRY_DELAY;
194
+ }
195
+ /**
196
+ * Get the last rate limit info from the API
197
+ */
198
+ getRateLimitInfo() {
199
+ return this.lastRateLimitInfo;
200
+ }
201
+ /**
202
+ * Make an authenticated request to the Rainfall API
203
+ */
204
+ async request(path, options = {}, requestOptions) {
205
+ const timeout = requestOptions?.timeout ?? this.defaultTimeout;
206
+ const maxRetries = requestOptions?.retries ?? this.defaultRetries;
207
+ const retryDelay = requestOptions?.retryDelay ?? this.defaultRetryDelay;
208
+ const url = `${this.baseUrl}${path}`;
209
+ const method = options.method || "GET";
210
+ let lastError;
211
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
212
+ try {
213
+ const controller = new AbortController();
214
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
215
+ const response = await fetch(url, {
216
+ method,
217
+ headers: {
218
+ "Authorization": `Bearer ${this.apiKey}`,
219
+ "Content-Type": "application/json",
220
+ "Accept": "application/json",
221
+ "X-Rainfall-SDK-Version": "0.1.0",
222
+ ...options.headers
223
+ },
224
+ body: options.body ? JSON.stringify(options.body) : void 0,
225
+ signal: controller.signal
226
+ });
227
+ clearTimeout(timeoutId);
228
+ const limit = response.headers.get("x-ratelimit-limit");
229
+ const remaining = response.headers.get("x-ratelimit-remaining");
230
+ const reset = response.headers.get("x-ratelimit-reset");
231
+ if (limit && remaining && reset) {
232
+ this.lastRateLimitInfo = {
233
+ limit: parseInt(limit, 10),
234
+ remaining: parseInt(remaining, 10),
235
+ resetAt: new Date(parseInt(reset, 10) * 1e3)
236
+ };
237
+ }
238
+ let data;
239
+ const contentType = response.headers.get("content-type");
240
+ if (contentType?.includes("application/json")) {
241
+ data = await response.json();
242
+ } else {
243
+ data = await response.text();
244
+ }
245
+ if (!response.ok) {
246
+ throw parseErrorResponse(response, data);
247
+ }
248
+ return data;
249
+ } catch (error) {
250
+ if (error instanceof RainfallError) {
251
+ if (error.statusCode && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429) {
252
+ throw error;
253
+ }
254
+ if (error.statusCode === 401) {
255
+ throw error;
256
+ }
257
+ }
258
+ if (error instanceof Error && error.name === "AbortError") {
259
+ lastError = new TimeoutError(timeout);
260
+ } else if (error instanceof TypeError) {
261
+ lastError = new NetworkError(error.message);
262
+ } else {
263
+ lastError = error instanceof Error ? error : new Error(String(error));
264
+ }
265
+ if (attempt >= maxRetries) {
266
+ break;
267
+ }
268
+ const delay = retryDelay * Math.pow(2, attempt) + Math.random() * 1e3;
269
+ await this.sleep(delay);
270
+ }
271
+ }
272
+ throw lastError || new RainfallError("Request failed", "REQUEST_FAILED");
273
+ }
274
+ /**
275
+ * Execute a tool/node by ID
276
+ */
277
+ async executeTool(toolId, params, options) {
278
+ return this.request(`/tools/${toolId}`, {
279
+ method: "POST",
280
+ body: params
281
+ }, options);
282
+ }
283
+ /**
284
+ * List all available tools
285
+ */
286
+ async listTools() {
287
+ return this.request("/tools");
288
+ }
289
+ /**
290
+ * Get tool schema/parameters
291
+ */
292
+ async getToolSchema(toolId) {
293
+ return this.request(`/tools/${toolId}/schema`);
294
+ }
295
+ /**
296
+ * Get subscriber info
297
+ */
298
+ async getMe() {
299
+ return this.request("/me");
300
+ }
301
+ sleep(ms) {
302
+ return new Promise((resolve) => setTimeout(resolve, ms));
303
+ }
304
+ };
305
+
306
+ // src/namespaces/integrations.ts
307
+ function createIntegrations(client) {
308
+ return new IntegrationsNamespace(client);
309
+ }
310
+ var IntegrationsNamespace = class {
311
+ constructor(client) {
312
+ this.client = client;
313
+ }
314
+ get github() {
315
+ return {
316
+ issues: {
317
+ create: (params) => this.client.executeTool("github-create-issue", params),
318
+ list: (params) => this.client.executeTool("github-list-issues", params),
319
+ get: (params) => this.client.executeTool("github-get-issue", params),
320
+ update: (params) => this.client.executeTool("github-update-issue", params),
321
+ addComment: (params) => this.client.executeTool("github-add-issue-comment", params)
322
+ },
323
+ repos: {
324
+ get: (params) => this.client.executeTool("github-get-repository", params),
325
+ listBranches: (params) => this.client.executeTool("github-list-branches", params)
326
+ },
327
+ pullRequests: {
328
+ list: (params) => this.client.executeTool("github-list-pull-requests", params),
329
+ get: (params) => this.client.executeTool("github-get-pull-request", params)
330
+ }
331
+ };
332
+ }
333
+ get notion() {
334
+ return {
335
+ pages: {
336
+ create: (params) => this.client.executeTool("notion-pages-create", params),
337
+ retrieve: (params) => this.client.executeTool("notion-pages-retrieve", params),
338
+ update: (params) => this.client.executeTool("notion-pages-update", params)
339
+ },
340
+ databases: {
341
+ query: (params) => this.client.executeTool("notion-databases-query", params),
342
+ retrieve: (params) => this.client.executeTool("notion-databases-retrieve", params)
343
+ },
344
+ blocks: {
345
+ appendChildren: (params) => this.client.executeTool("notion-blocks-append-children", params),
346
+ retrieveChildren: (params) => this.client.executeTool("notion-blocks-retrieve-children", params)
347
+ }
348
+ };
349
+ }
350
+ get linear() {
351
+ return {
352
+ issues: {
353
+ create: (params) => this.client.executeTool("linear-core-issueCreate", params),
354
+ list: (params) => this.client.executeTool("linear-core-issues", params),
355
+ get: (params) => this.client.executeTool("linear-core-issue", params),
356
+ update: (params) => this.client.executeTool("linear-core-issueUpdate", params),
357
+ archive: (params) => this.client.executeTool("linear-core-issueArchive", params)
358
+ },
359
+ teams: {
360
+ list: () => this.client.executeTool("linear-core-teams", {})
361
+ }
362
+ };
363
+ }
364
+ get slack() {
365
+ return {
366
+ messages: {
367
+ send: (params) => this.client.executeTool("slack-core-postMessage", params),
368
+ list: (params) => this.client.executeTool("slack-core-listMessages", params)
369
+ },
370
+ channels: {
371
+ list: () => this.client.executeTool("slack-core-listChannels", {})
372
+ },
373
+ users: {
374
+ list: () => this.client.executeTool("slack-core-listUsers", {})
375
+ },
376
+ reactions: {
377
+ add: (params) => this.client.executeTool("slack-core-addReaction", params)
378
+ }
379
+ };
380
+ }
381
+ get figma() {
382
+ return {
383
+ files: {
384
+ get: (params) => this.client.executeTool("figma-files-getFile", { fileKey: params.fileKey }),
385
+ getNodes: (params) => this.client.executeTool("figma-files-getFileNodes", { fileKey: params.fileKey, nodeIds: params.nodeIds }),
386
+ getImages: (params) => this.client.executeTool("figma-files-getFileImage", { fileKey: params.fileKey, nodeIds: params.nodeIds, format: params.format }),
387
+ getComments: (params) => this.client.executeTool("figma-comments-getFileComments", { fileKey: params.fileKey }),
388
+ postComment: (params) => this.client.executeTool("figma-comments-postComment", { fileKey: params.fileKey, message: params.message, nodeId: params.nodeId })
389
+ },
390
+ projects: {
391
+ list: (params) => this.client.executeTool("figma-projects-getTeamProjects", { teamId: params.teamId }),
392
+ getFiles: (params) => this.client.executeTool("figma-projects-getProjectFiles", { projectId: params.projectId })
393
+ }
394
+ };
395
+ }
396
+ get stripe() {
397
+ return {
398
+ customers: {
399
+ create: (params) => this.client.executeTool("stripe-customers-create", params),
400
+ retrieve: (params) => this.client.executeTool("stripe-customers-retrieve", { customerId: params.customerId }),
401
+ update: (params) => this.client.executeTool("stripe-customers-update", params),
402
+ listPaymentMethods: (params) => this.client.executeTool("stripe-customers-list-payment-methods", { customerId: params.customerId })
403
+ },
404
+ paymentIntents: {
405
+ create: (params) => this.client.executeTool("stripe-payment-intents-create", params),
406
+ retrieve: (params) => this.client.executeTool("stripe-payment-intents-retrieve", { paymentIntentId: params.paymentIntentId }),
407
+ confirm: (params) => this.client.executeTool("stripe-payment-intents-confirm", { paymentIntentId: params.paymentIntentId })
408
+ },
409
+ subscriptions: {
410
+ create: (params) => this.client.executeTool("stripe-subscriptions-create", params),
411
+ retrieve: (params) => this.client.executeTool("stripe-subscriptions-retrieve", { subscriptionId: params.subscriptionId }),
412
+ cancel: (params) => this.client.executeTool("stripe-subscriptions-cancel", { subscriptionId: params.subscriptionId })
413
+ }
414
+ };
415
+ }
416
+ };
417
+
418
+ // src/namespaces/memory.ts
419
+ function createMemory(client) {
420
+ return {
421
+ create: (params) => client.executeTool("memory-create", params),
422
+ get: (params) => client.executeTool("memory-get", { memoryId: params.memoryId }),
423
+ recall: (params) => client.executeTool("memory-recall", params),
424
+ list: (params) => client.executeTool("memory-list", params ?? {}),
425
+ update: (params) => client.executeTool("memory-update", params),
426
+ delete: (params) => client.executeTool("memory-delete", { memoryId: params.memoryId })
427
+ };
428
+ }
429
+
430
+ // src/namespaces/articles.ts
431
+ function createArticles(client) {
432
+ return {
433
+ search: (params) => client.executeTool("article-search", params),
434
+ create: (params) => client.executeTool("article-create", params),
435
+ createFromUrl: (params) => client.executeTool("article-create-from-url", params),
436
+ fetch: (params) => client.executeTool("article-fetch", params),
437
+ recent: (params) => client.executeTool("article-recent", params ?? {}),
438
+ relevant: (params) => client.executeTool("article-relevant-news", params),
439
+ summarize: (params) => client.executeTool("article-summarize", params),
440
+ extractTopics: (params) => client.executeTool("article-topic-extractor", params)
441
+ };
442
+ }
443
+
444
+ // src/namespaces/web.ts
445
+ function createWeb(client) {
446
+ return {
447
+ search: {
448
+ exa: (params) => client.executeTool("exa-web-search", params),
449
+ perplexity: (params) => client.executeTool("perplexity-search", params)
450
+ },
451
+ fetch: (params) => client.executeTool("web-fetch", params),
452
+ htmlToMarkdown: (params) => client.executeTool("html-to-markdown-converter", params),
453
+ extractHtml: (params) => client.executeTool("extract-html-selector", params)
454
+ };
455
+ }
456
+
457
+ // src/namespaces/ai.ts
458
+ function createAI(client) {
459
+ return {
460
+ embeddings: {
461
+ document: (params) => client.executeTool("jina-document-embedding", params),
462
+ query: (params) => client.executeTool("jina-query-embedding", params),
463
+ image: (params) => client.executeTool("jina-image-embedding", { image: params.imageBase64 })
464
+ },
465
+ image: {
466
+ generate: (params) => client.executeTool("image-generation", params)
467
+ },
468
+ ocr: (params) => client.executeTool("ocr-text-extraction", { image: params.imageBase64 }),
469
+ vision: (params) => client.executeTool("llama-scout-vision", { image: params.imageBase64, prompt: params.prompt }),
470
+ chat: (params) => client.executeTool("xai-chat-completions", params),
471
+ complete: (params) => client.executeTool("fim", params),
472
+ classify: (params) => client.executeTool("jina-document-classifier", params),
473
+ segment: (params) => client.executeTool("jina-text-segmenter", params)
474
+ };
475
+ }
476
+
477
+ // src/namespaces/data.ts
478
+ function createData(client) {
479
+ return {
480
+ csv: {
481
+ query: (params) => client.executeTool("query-csv", params),
482
+ convert: (params) => client.executeTool("csv-convert", params)
483
+ },
484
+ scripts: {
485
+ create: (params) => client.executeTool("create-saved-script", params),
486
+ execute: (params) => client.executeTool("execute-saved-script", params),
487
+ list: () => client.executeTool("list-saved-scripts", {}),
488
+ update: (params) => client.executeTool("update-saved-script", params),
489
+ delete: (params) => client.executeTool("delete-saved-script", params)
490
+ },
491
+ similarity: {
492
+ search: (params) => client.executeTool("duck-db-similarity-search", params),
493
+ duckDbSearch: (params) => client.executeTool("duck-db-similarity-search", params)
494
+ }
495
+ };
496
+ }
497
+
498
+ // src/namespaces/utils.ts
499
+ function createUtils(client) {
500
+ return {
501
+ mermaid: (params) => client.executeTool("mermaid-diagram-generator", { mermaid: params.diagram }),
502
+ documentConvert: (params) => client.executeTool("document-format-converter", {
503
+ base64: `data:${params.mimeType};base64,${Buffer.from(params.document).toString("base64")}`,
504
+ format: params.format
505
+ }),
506
+ regex: {
507
+ match: (params) => client.executeTool("regex-match", params),
508
+ replace: (params) => client.executeTool("regex-replace", params)
509
+ },
510
+ jsonExtract: (params) => client.executeTool("json-extract", params),
511
+ digest: (params) => client.executeTool("digest-generator", { text: params.data }),
512
+ monteCarlo: (params) => client.executeTool("monte-carlo-simulation", params)
513
+ };
514
+ }
515
+
516
+ // src/sdk.ts
517
+ var Rainfall = class {
518
+ client;
519
+ _integrations;
520
+ _memory;
521
+ _articles;
522
+ _web;
523
+ _ai;
524
+ _data;
525
+ _utils;
526
+ constructor(config) {
527
+ this.client = new RainfallClient(config);
528
+ }
529
+ /**
530
+ * Integrations namespace - GitHub, Notion, Linear, Slack, Figma, Stripe
531
+ *
532
+ * @example
533
+ * ```typescript
534
+ * // GitHub
535
+ * await rainfall.integrations.github.issues.create({
536
+ * owner: 'facebook',
537
+ * repo: 'react',
538
+ * title: 'Bug report'
539
+ * });
540
+ *
541
+ * // Slack
542
+ * await rainfall.integrations.slack.messages.send({
543
+ * channelId: 'C123456',
544
+ * text: 'Hello team!'
545
+ * });
546
+ *
547
+ * // Linear
548
+ * const issues = await rainfall.integrations.linear.issues.list();
549
+ * ```
550
+ */
551
+ get integrations() {
552
+ if (!this._integrations) {
553
+ this._integrations = createIntegrations(this.client);
554
+ }
555
+ return this._integrations;
556
+ }
557
+ /**
558
+ * Memory namespace - Semantic memory storage and retrieval
559
+ *
560
+ * @example
561
+ * ```typescript
562
+ * // Store a memory
563
+ * await rainfall.memory.create({
564
+ * content: 'User prefers dark mode',
565
+ * keywords: ['preference', 'ui']
566
+ * });
567
+ *
568
+ * // Recall similar memories
569
+ * const memories = await rainfall.memory.recall({
570
+ * query: 'user preferences',
571
+ * topK: 5
572
+ * });
573
+ * ```
574
+ */
575
+ get memory() {
576
+ if (!this._memory) {
577
+ this._memory = createMemory(this.client);
578
+ }
579
+ return this._memory;
580
+ }
581
+ /**
582
+ * Articles namespace - News aggregation and article management
583
+ *
584
+ * @example
585
+ * ```typescript
586
+ * // Search news
587
+ * const articles = await rainfall.articles.search({
588
+ * query: 'artificial intelligence'
589
+ * });
590
+ *
591
+ * // Create from URL
592
+ * const article = await rainfall.articles.createFromUrl({
593
+ * url: 'https://example.com/article'
594
+ * });
595
+ *
596
+ * // Summarize
597
+ * const summary = await rainfall.articles.summarize({
598
+ * text: article.content
599
+ * });
600
+ * ```
601
+ */
602
+ get articles() {
603
+ if (!this._articles) {
604
+ this._articles = createArticles(this.client);
605
+ }
606
+ return this._articles;
607
+ }
608
+ /**
609
+ * Web namespace - Web search, scraping, and content extraction
610
+ *
611
+ * @example
612
+ * ```typescript
613
+ * // Search with Exa
614
+ * const results = await rainfall.web.search.exa({
615
+ * query: 'latest AI research'
616
+ * });
617
+ *
618
+ * // Fetch and convert
619
+ * const html = await rainfall.web.fetch({ url: 'https://example.com' });
620
+ * const markdown = await rainfall.web.htmlToMarkdown({ html });
621
+ *
622
+ * // Extract specific elements
623
+ * const links = await rainfall.web.extractHtml({
624
+ * html,
625
+ * selector: 'a[href]'
626
+ * });
627
+ * ```
628
+ */
629
+ get web() {
630
+ if (!this._web) {
631
+ this._web = createWeb(this.client);
632
+ }
633
+ return this._web;
634
+ }
635
+ /**
636
+ * AI namespace - Embeddings, image generation, OCR, vision, chat
637
+ *
638
+ * @example
639
+ * ```typescript
640
+ * // Generate embeddings
641
+ * const embedding = await rainfall.ai.embeddings.document({
642
+ * text: 'Hello world'
643
+ * });
644
+ *
645
+ * // Generate image
646
+ * const image = await rainfall.ai.image.generate({
647
+ * prompt: 'A serene mountain landscape'
648
+ * });
649
+ *
650
+ * // OCR
651
+ * const text = await rainfall.ai.ocr({ imageBase64: '...' });
652
+ *
653
+ * // Chat
654
+ * const response = await rainfall.ai.chat({
655
+ * messages: [{ role: 'user', content: 'Hello!' }]
656
+ * });
657
+ * ```
658
+ */
659
+ get ai() {
660
+ if (!this._ai) {
661
+ this._ai = createAI(this.client);
662
+ }
663
+ return this._ai;
664
+ }
665
+ /**
666
+ * Data namespace - CSV processing, scripts, similarity search
667
+ *
668
+ * @example
669
+ * ```typescript
670
+ * // Query CSV with SQL
671
+ * const results = await rainfall.data.csv.query({
672
+ * sql: 'SELECT * FROM data WHERE value > 100'
673
+ * });
674
+ *
675
+ * // Execute saved script
676
+ * const result = await rainfall.data.scripts.execute({
677
+ * name: 'my-script',
678
+ * params: { input: 'data' }
679
+ * });
680
+ * ```
681
+ */
682
+ get data() {
683
+ if (!this._data) {
684
+ this._data = createData(this.client);
685
+ }
686
+ return this._data;
687
+ }
688
+ /**
689
+ * Utils namespace - Mermaid diagrams, document conversion, regex, JSON extraction
690
+ *
691
+ * @example
692
+ * ```typescript
693
+ * // Generate diagram
694
+ * const diagram = await rainfall.utils.mermaid({
695
+ * diagram: 'graph TD; A-->B;'
696
+ * });
697
+ *
698
+ * // Convert document
699
+ * const pdf = await rainfall.utils.documentConvert({
700
+ * document: markdownContent,
701
+ * mimeType: 'text/markdown',
702
+ * format: 'pdf'
703
+ * });
704
+ *
705
+ * // Extract JSON from text
706
+ * const json = await rainfall.utils.jsonExtract({
707
+ * text: 'Here is some data: {"key": "value"}'
708
+ * });
709
+ * ```
710
+ */
711
+ get utils() {
712
+ if (!this._utils) {
713
+ this._utils = createUtils(this.client);
714
+ }
715
+ return this._utils;
716
+ }
717
+ /**
718
+ * Get the underlying HTTP client for advanced usage
719
+ */
720
+ getClient() {
721
+ return this.client;
722
+ }
723
+ /**
724
+ * List all available tools
725
+ */
726
+ async listTools() {
727
+ return this.client.listTools();
728
+ }
729
+ /**
730
+ * Get schema for a specific tool
731
+ */
732
+ async getToolSchema(toolId) {
733
+ return this.client.getToolSchema(toolId);
734
+ }
735
+ /**
736
+ * Execute any tool by ID (low-level access)
737
+ */
738
+ async executeTool(toolId, params) {
739
+ return this.client.executeTool(toolId, params);
740
+ }
741
+ /**
742
+ * Get current subscriber info and usage
743
+ */
744
+ async getMe() {
745
+ return this.client.getMe();
746
+ }
747
+ /**
748
+ * Get current rate limit info
749
+ */
750
+ getRateLimitInfo() {
751
+ return this.client.getRateLimitInfo();
752
+ }
753
+ };
754
+
755
+ // src/index.ts
756
+ var VERSION = "0.1.0";
757
+ // Annotate the CommonJS export names for ESM import in node:
758
+ 0 && (module.exports = {
759
+ AuthenticationError,
760
+ NetworkError,
761
+ NotFoundError,
762
+ Rainfall,
763
+ RainfallClient,
764
+ RainfallError,
765
+ RateLimitError,
766
+ ServerError,
767
+ TimeoutError,
768
+ ToolNotFoundError,
769
+ VERSION,
770
+ ValidationError
771
+ });