@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,777 @@
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
+ const response = await this.request(`/olympic/subscribers/${subscriberId}/nodes/${toolId}/params`);
274
+ return response.params;
275
+ }
276
+ /**
277
+ * Get subscriber info
278
+ */
279
+ async getMe() {
280
+ const result = await this.request("/olympic/subscribers/me");
281
+ if (result.subscriber?.id) {
282
+ this.subscriberId = result.subscriber.id;
283
+ }
284
+ const subscriber = result.subscriber;
285
+ return {
286
+ id: subscriber.id,
287
+ name: subscriber.name,
288
+ email: subscriber.google_id,
289
+ billingStatus: subscriber.billing_status,
290
+ plan: subscriber.billing_status,
291
+ usage: {
292
+ callsThisMonth: subscriber.metadata?.usage?.callsThisMonth ?? 0,
293
+ callsLimit: subscriber.metadata?.usage?.callsLimit ?? 5e3
294
+ }
295
+ };
296
+ }
297
+ /**
298
+ * Ensure we have a subscriber ID, fetching it if necessary
299
+ */
300
+ async ensureSubscriberId() {
301
+ if (this.subscriberId) {
302
+ return this.subscriberId;
303
+ }
304
+ const me = await this.getMe();
305
+ if (!me.id) {
306
+ throw new RainfallError("Failed to get subscriber ID", "NO_SUBSCRIBER_ID");
307
+ }
308
+ return me.id;
309
+ }
310
+ sleep(ms) {
311
+ return new Promise((resolve) => setTimeout(resolve, ms));
312
+ }
313
+ };
314
+
315
+ // src/namespaces/integrations.ts
316
+ function createIntegrations(client) {
317
+ return new IntegrationsNamespace(client);
318
+ }
319
+ var IntegrationsNamespace = class {
320
+ constructor(client) {
321
+ this.client = client;
322
+ }
323
+ get github() {
324
+ return {
325
+ issues: {
326
+ create: (params) => this.client.executeTool("github-create-issue", params),
327
+ list: (params) => this.client.executeTool("github-list-issues", params),
328
+ get: (params) => this.client.executeTool("github-get-issue", params),
329
+ update: (params) => this.client.executeTool("github-update-issue", params),
330
+ addComment: (params) => this.client.executeTool("github-add-issue-comment", params)
331
+ },
332
+ repos: {
333
+ get: (params) => this.client.executeTool("github-get-repository", params),
334
+ listBranches: (params) => this.client.executeTool("github-list-branches", params)
335
+ },
336
+ pullRequests: {
337
+ list: (params) => this.client.executeTool("github-list-pull-requests", params),
338
+ get: (params) => this.client.executeTool("github-get-pull-request", params)
339
+ }
340
+ };
341
+ }
342
+ get notion() {
343
+ return {
344
+ pages: {
345
+ create: (params) => this.client.executeTool("notion-pages-create", params),
346
+ retrieve: (params) => this.client.executeTool("notion-pages-retrieve", params),
347
+ update: (params) => this.client.executeTool("notion-pages-update", params)
348
+ },
349
+ databases: {
350
+ query: (params) => this.client.executeTool("notion-databases-query", params),
351
+ retrieve: (params) => this.client.executeTool("notion-databases-retrieve", params)
352
+ },
353
+ blocks: {
354
+ appendChildren: (params) => this.client.executeTool("notion-blocks-append-children", params),
355
+ retrieveChildren: (params) => this.client.executeTool("notion-blocks-retrieve-children", params)
356
+ }
357
+ };
358
+ }
359
+ get linear() {
360
+ return {
361
+ issues: {
362
+ create: (params) => this.client.executeTool("linear-core-issueCreate", params),
363
+ list: (params) => this.client.executeTool("linear-core-issues", params),
364
+ get: (params) => this.client.executeTool("linear-core-issue", params),
365
+ update: (params) => this.client.executeTool("linear-core-issueUpdate", params),
366
+ archive: (params) => this.client.executeTool("linear-core-issueArchive", params)
367
+ },
368
+ teams: {
369
+ list: () => this.client.executeTool("linear-core-teams", {})
370
+ }
371
+ };
372
+ }
373
+ get slack() {
374
+ return {
375
+ messages: {
376
+ send: (params) => this.client.executeTool("slack-core-postMessage", params),
377
+ list: (params) => this.client.executeTool("slack-core-listMessages", params)
378
+ },
379
+ channels: {
380
+ list: () => this.client.executeTool("slack-core-listChannels", {})
381
+ },
382
+ users: {
383
+ list: () => this.client.executeTool("slack-core-listUsers", {})
384
+ },
385
+ reactions: {
386
+ add: (params) => this.client.executeTool("slack-core-addReaction", params)
387
+ }
388
+ };
389
+ }
390
+ get figma() {
391
+ return {
392
+ files: {
393
+ get: (params) => this.client.executeTool("figma-files-getFile", { fileKey: params.fileKey }),
394
+ getNodes: (params) => this.client.executeTool("figma-files-getFileNodes", { fileKey: params.fileKey, nodeIds: params.nodeIds }),
395
+ getImages: (params) => this.client.executeTool("figma-files-getFileImage", { fileKey: params.fileKey, nodeIds: params.nodeIds, format: params.format }),
396
+ getComments: (params) => this.client.executeTool("figma-comments-getFileComments", { fileKey: params.fileKey }),
397
+ postComment: (params) => this.client.executeTool("figma-comments-postComment", { fileKey: params.fileKey, message: params.message, nodeId: params.nodeId })
398
+ },
399
+ projects: {
400
+ list: (params) => this.client.executeTool("figma-projects-getTeamProjects", { teamId: params.teamId }),
401
+ getFiles: (params) => this.client.executeTool("figma-projects-getProjectFiles", { projectId: params.projectId })
402
+ }
403
+ };
404
+ }
405
+ get stripe() {
406
+ return {
407
+ customers: {
408
+ create: (params) => this.client.executeTool("stripe-customers-create", params),
409
+ retrieve: (params) => this.client.executeTool("stripe-customers-retrieve", { customerId: params.customerId }),
410
+ update: (params) => this.client.executeTool("stripe-customers-update", params),
411
+ listPaymentMethods: (params) => this.client.executeTool("stripe-customers-list-payment-methods", { customerId: params.customerId })
412
+ },
413
+ paymentIntents: {
414
+ create: (params) => this.client.executeTool("stripe-payment-intents-create", params),
415
+ retrieve: (params) => this.client.executeTool("stripe-payment-intents-retrieve", { paymentIntentId: params.paymentIntentId }),
416
+ confirm: (params) => this.client.executeTool("stripe-payment-intents-confirm", { paymentIntentId: params.paymentIntentId })
417
+ },
418
+ subscriptions: {
419
+ create: (params) => this.client.executeTool("stripe-subscriptions-create", params),
420
+ retrieve: (params) => this.client.executeTool("stripe-subscriptions-retrieve", { subscriptionId: params.subscriptionId }),
421
+ cancel: (params) => this.client.executeTool("stripe-subscriptions-cancel", { subscriptionId: params.subscriptionId })
422
+ }
423
+ };
424
+ }
425
+ };
426
+
427
+ // src/namespaces/memory.ts
428
+ function createMemory(client) {
429
+ return {
430
+ create: (params) => client.executeTool("memory-create", params),
431
+ get: (params) => client.executeTool("memory-get", { memoryId: params.memoryId }),
432
+ recall: (params) => client.executeTool("memory-recall", params),
433
+ list: (params) => client.executeTool("memory-list", params ?? {}),
434
+ update: (params) => client.executeTool("memory-update", params),
435
+ delete: (params) => client.executeTool("memory-delete", { memoryId: params.memoryId })
436
+ };
437
+ }
438
+
439
+ // src/namespaces/articles.ts
440
+ function createArticles(client) {
441
+ return {
442
+ search: (params) => client.executeTool("article-search", params),
443
+ create: (params) => client.executeTool("article-create", params),
444
+ createFromUrl: (params) => client.executeTool("article-create-from-url", params),
445
+ fetch: (params) => client.executeTool("article-fetch", params),
446
+ recent: (params) => client.executeTool("article-recent", params ?? {}),
447
+ relevant: (params) => client.executeTool("article-relevant-news", params),
448
+ summarize: (params) => client.executeTool("article-summarize", params),
449
+ extractTopics: (params) => client.executeTool("article-topic-extractor", params)
450
+ };
451
+ }
452
+
453
+ // src/namespaces/web.ts
454
+ function createWeb(client) {
455
+ return {
456
+ search: {
457
+ exa: (params) => client.executeTool("exa-web-search", params),
458
+ perplexity: (params) => client.executeTool("perplexity-search", params)
459
+ },
460
+ fetch: (params) => client.executeTool("web-fetch", params),
461
+ htmlToMarkdown: (params) => client.executeTool("html-to-markdown-converter", params),
462
+ extractHtml: (params) => client.executeTool("extract-html-selector", params)
463
+ };
464
+ }
465
+
466
+ // src/namespaces/ai.ts
467
+ function createAI(client) {
468
+ return {
469
+ embeddings: {
470
+ document: (params) => client.executeTool("jina-document-embedding", params),
471
+ query: (params) => client.executeTool("jina-query-embedding", params),
472
+ image: (params) => client.executeTool("jina-image-embedding", { image: params.imageBase64 })
473
+ },
474
+ image: {
475
+ generate: (params) => client.executeTool("image-generation", params)
476
+ },
477
+ ocr: (params) => client.executeTool("ocr-text-extraction", { image: params.imageBase64 }),
478
+ vision: (params) => client.executeTool("llama-scout-vision", { image: params.imageBase64, prompt: params.prompt }),
479
+ chat: (params) => client.executeTool("xai-chat-completions", params),
480
+ complete: (params) => client.executeTool("fim", params),
481
+ classify: (params) => client.executeTool("jina-document-classifier", params),
482
+ segment: (params) => client.executeTool("jina-text-segmenter", params)
483
+ };
484
+ }
485
+
486
+ // src/namespaces/data.ts
487
+ function createData(client) {
488
+ return {
489
+ csv: {
490
+ query: (params) => client.executeTool("query-csv", params),
491
+ convert: (params) => client.executeTool("csv-convert", params)
492
+ },
493
+ scripts: {
494
+ create: (params) => client.executeTool("create-saved-script", params),
495
+ execute: (params) => client.executeTool("execute-saved-script", params),
496
+ list: () => client.executeTool("list-saved-scripts", {}),
497
+ update: (params) => client.executeTool("update-saved-script", params),
498
+ delete: (params) => client.executeTool("delete-saved-script", params)
499
+ },
500
+ similarity: {
501
+ search: (params) => client.executeTool("duck-db-similarity-search", params),
502
+ duckDbSearch: (params) => client.executeTool("duck-db-similarity-search", params)
503
+ }
504
+ };
505
+ }
506
+
507
+ // src/namespaces/utils.ts
508
+ function createUtils(client) {
509
+ return {
510
+ mermaid: (params) => client.executeTool("mermaid-diagram-generator", { mermaid: params.diagram }),
511
+ documentConvert: (params) => client.executeTool("document-format-converter", {
512
+ base64: `data:${params.mimeType};base64,${Buffer.from(params.document).toString("base64")}`,
513
+ format: params.format
514
+ }),
515
+ regex: {
516
+ match: (params) => client.executeTool("regex-match", params),
517
+ replace: (params) => client.executeTool("regex-replace", params)
518
+ },
519
+ jsonExtract: (params) => client.executeTool("json-extract", params),
520
+ digest: (params) => client.executeTool("digest-generator", { text: params.data }),
521
+ monteCarlo: (params) => client.executeTool("monte-carlo-simulation", params)
522
+ };
523
+ }
524
+
525
+ // src/sdk.ts
526
+ var Rainfall = class {
527
+ client;
528
+ _integrations;
529
+ _memory;
530
+ _articles;
531
+ _web;
532
+ _ai;
533
+ _data;
534
+ _utils;
535
+ constructor(config) {
536
+ this.client = new RainfallClient(config);
537
+ }
538
+ /**
539
+ * Integrations namespace - GitHub, Notion, Linear, Slack, Figma, Stripe
540
+ *
541
+ * @example
542
+ * ```typescript
543
+ * // GitHub
544
+ * await rainfall.integrations.github.issues.create({
545
+ * owner: 'facebook',
546
+ * repo: 'react',
547
+ * title: 'Bug report'
548
+ * });
549
+ *
550
+ * // Slack
551
+ * await rainfall.integrations.slack.messages.send({
552
+ * channelId: 'C123456',
553
+ * text: 'Hello team!'
554
+ * });
555
+ *
556
+ * // Linear
557
+ * const issues = await rainfall.integrations.linear.issues.list();
558
+ * ```
559
+ */
560
+ get integrations() {
561
+ if (!this._integrations) {
562
+ this._integrations = createIntegrations(this.client);
563
+ }
564
+ return this._integrations;
565
+ }
566
+ /**
567
+ * Memory namespace - Semantic memory storage and retrieval
568
+ *
569
+ * @example
570
+ * ```typescript
571
+ * // Store a memory
572
+ * await rainfall.memory.create({
573
+ * content: 'User prefers dark mode',
574
+ * keywords: ['preference', 'ui']
575
+ * });
576
+ *
577
+ * // Recall similar memories
578
+ * const memories = await rainfall.memory.recall({
579
+ * query: 'user preferences',
580
+ * topK: 5
581
+ * });
582
+ * ```
583
+ */
584
+ get memory() {
585
+ if (!this._memory) {
586
+ this._memory = createMemory(this.client);
587
+ }
588
+ return this._memory;
589
+ }
590
+ /**
591
+ * Articles namespace - News aggregation and article management
592
+ *
593
+ * @example
594
+ * ```typescript
595
+ * // Search news
596
+ * const articles = await rainfall.articles.search({
597
+ * query: 'artificial intelligence'
598
+ * });
599
+ *
600
+ * // Create from URL
601
+ * const article = await rainfall.articles.createFromUrl({
602
+ * url: 'https://example.com/article'
603
+ * });
604
+ *
605
+ * // Summarize
606
+ * const summary = await rainfall.articles.summarize({
607
+ * text: article.content
608
+ * });
609
+ * ```
610
+ */
611
+ get articles() {
612
+ if (!this._articles) {
613
+ this._articles = createArticles(this.client);
614
+ }
615
+ return this._articles;
616
+ }
617
+ /**
618
+ * Web namespace - Web search, scraping, and content extraction
619
+ *
620
+ * @example
621
+ * ```typescript
622
+ * // Search with Exa
623
+ * const results = await rainfall.web.search.exa({
624
+ * query: 'latest AI research'
625
+ * });
626
+ *
627
+ * // Fetch and convert
628
+ * const html = await rainfall.web.fetch({ url: 'https://example.com' });
629
+ * const markdown = await rainfall.web.htmlToMarkdown({ html });
630
+ *
631
+ * // Extract specific elements
632
+ * const links = await rainfall.web.extractHtml({
633
+ * html,
634
+ * selector: 'a[href]'
635
+ * });
636
+ * ```
637
+ */
638
+ get web() {
639
+ if (!this._web) {
640
+ this._web = createWeb(this.client);
641
+ }
642
+ return this._web;
643
+ }
644
+ /**
645
+ * AI namespace - Embeddings, image generation, OCR, vision, chat
646
+ *
647
+ * @example
648
+ * ```typescript
649
+ * // Generate embeddings
650
+ * const embedding = await rainfall.ai.embeddings.document({
651
+ * text: 'Hello world'
652
+ * });
653
+ *
654
+ * // Generate image
655
+ * const image = await rainfall.ai.image.generate({
656
+ * prompt: 'A serene mountain landscape'
657
+ * });
658
+ *
659
+ * // OCR
660
+ * const text = await rainfall.ai.ocr({ imageBase64: '...' });
661
+ *
662
+ * // Chat
663
+ * const response = await rainfall.ai.chat({
664
+ * messages: [{ role: 'user', content: 'Hello!' }]
665
+ * });
666
+ * ```
667
+ */
668
+ get ai() {
669
+ if (!this._ai) {
670
+ this._ai = createAI(this.client);
671
+ }
672
+ return this._ai;
673
+ }
674
+ /**
675
+ * Data namespace - CSV processing, scripts, similarity search
676
+ *
677
+ * @example
678
+ * ```typescript
679
+ * // Query CSV with SQL
680
+ * const results = await rainfall.data.csv.query({
681
+ * sql: 'SELECT * FROM data WHERE value > 100'
682
+ * });
683
+ *
684
+ * // Execute saved script
685
+ * const result = await rainfall.data.scripts.execute({
686
+ * name: 'my-script',
687
+ * params: { input: 'data' }
688
+ * });
689
+ * ```
690
+ */
691
+ get data() {
692
+ if (!this._data) {
693
+ this._data = createData(this.client);
694
+ }
695
+ return this._data;
696
+ }
697
+ /**
698
+ * Utils namespace - Mermaid diagrams, document conversion, regex, JSON extraction
699
+ *
700
+ * @example
701
+ * ```typescript
702
+ * // Generate diagram
703
+ * const diagram = await rainfall.utils.mermaid({
704
+ * diagram: 'graph TD; A-->B;'
705
+ * });
706
+ *
707
+ * // Convert document
708
+ * const pdf = await rainfall.utils.documentConvert({
709
+ * document: markdownContent,
710
+ * mimeType: 'text/markdown',
711
+ * format: 'pdf'
712
+ * });
713
+ *
714
+ * // Extract JSON from text
715
+ * const json = await rainfall.utils.jsonExtract({
716
+ * text: 'Here is some data: {"key": "value"}'
717
+ * });
718
+ * ```
719
+ */
720
+ get utils() {
721
+ if (!this._utils) {
722
+ this._utils = createUtils(this.client);
723
+ }
724
+ return this._utils;
725
+ }
726
+ /**
727
+ * Get the underlying HTTP client for advanced usage
728
+ */
729
+ getClient() {
730
+ return this.client;
731
+ }
732
+ /**
733
+ * List all available tools
734
+ */
735
+ async listTools() {
736
+ return this.client.listTools();
737
+ }
738
+ /**
739
+ * Get schema for a specific tool
740
+ */
741
+ async getToolSchema(toolId) {
742
+ return this.client.getToolSchema(toolId);
743
+ }
744
+ /**
745
+ * Execute any tool by ID (low-level access)
746
+ */
747
+ async executeTool(toolId, params) {
748
+ return this.client.executeTool(toolId, params);
749
+ }
750
+ /**
751
+ * Get current subscriber info and usage
752
+ */
753
+ async getMe() {
754
+ return this.client.getMe();
755
+ }
756
+ /**
757
+ * Get current rate limit info
758
+ */
759
+ getRateLimitInfo() {
760
+ return this.client.getRateLimitInfo();
761
+ }
762
+ };
763
+
764
+ export {
765
+ RainfallError,
766
+ AuthenticationError,
767
+ RateLimitError,
768
+ ValidationError,
769
+ NotFoundError,
770
+ ServerError,
771
+ TimeoutError,
772
+ NetworkError,
773
+ ToolNotFoundError,
774
+ parseErrorResponse,
775
+ RainfallClient,
776
+ Rainfall
777
+ };