@rainfall-devkit/sdk 0.1.5 → 0.1.6

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