@rainfall-devkit/sdk 0.1.3 → 0.1.4

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,731 @@
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
+ constructor(config) {
152
+ this.apiKey = config.apiKey;
153
+ this.baseUrl = config.baseUrl || DEFAULT_BASE_URL;
154
+ this.defaultTimeout = config.timeout || DEFAULT_TIMEOUT;
155
+ this.defaultRetries = config.retries ?? DEFAULT_RETRIES;
156
+ this.defaultRetryDelay = config.retryDelay || DEFAULT_RETRY_DELAY;
157
+ }
158
+ /**
159
+ * Get the last rate limit info from the API
160
+ */
161
+ getRateLimitInfo() {
162
+ return this.lastRateLimitInfo;
163
+ }
164
+ /**
165
+ * Make an authenticated request to the Rainfall API
166
+ */
167
+ async request(path, options = {}, requestOptions) {
168
+ const timeout = requestOptions?.timeout ?? this.defaultTimeout;
169
+ const maxRetries = requestOptions?.retries ?? this.defaultRetries;
170
+ const retryDelay = requestOptions?.retryDelay ?? this.defaultRetryDelay;
171
+ const url = `${this.baseUrl}${path}`;
172
+ const method = options.method || "GET";
173
+ let lastError;
174
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
175
+ try {
176
+ const controller = new AbortController();
177
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
178
+ const response = await fetch(url, {
179
+ method,
180
+ headers: {
181
+ "x-api-key": this.apiKey,
182
+ "Content-Type": "application/json",
183
+ "Accept": "application/json",
184
+ "X-Rainfall-SDK-Version": "0.1.0",
185
+ ...options.headers
186
+ },
187
+ body: options.body ? JSON.stringify(options.body) : void 0,
188
+ signal: controller.signal
189
+ });
190
+ clearTimeout(timeoutId);
191
+ const limit = response.headers.get("x-ratelimit-limit");
192
+ const remaining = response.headers.get("x-ratelimit-remaining");
193
+ const reset = response.headers.get("x-ratelimit-reset");
194
+ if (limit && remaining && reset) {
195
+ this.lastRateLimitInfo = {
196
+ limit: parseInt(limit, 10),
197
+ remaining: parseInt(remaining, 10),
198
+ resetAt: new Date(parseInt(reset, 10) * 1e3)
199
+ };
200
+ }
201
+ let data;
202
+ const contentType = response.headers.get("content-type");
203
+ if (contentType?.includes("application/json")) {
204
+ data = await response.json();
205
+ } else {
206
+ data = await response.text();
207
+ }
208
+ if (!response.ok) {
209
+ throw parseErrorResponse(response, data);
210
+ }
211
+ return data;
212
+ } catch (error) {
213
+ if (error instanceof RainfallError) {
214
+ if (error.statusCode && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429) {
215
+ throw error;
216
+ }
217
+ if (error.statusCode === 401) {
218
+ throw error;
219
+ }
220
+ }
221
+ if (error instanceof Error && error.name === "AbortError") {
222
+ lastError = new TimeoutError(timeout);
223
+ } else if (error instanceof TypeError) {
224
+ lastError = new NetworkError(error.message);
225
+ } else {
226
+ lastError = error instanceof Error ? error : new Error(String(error));
227
+ }
228
+ if (attempt >= maxRetries) {
229
+ break;
230
+ }
231
+ const delay = retryDelay * Math.pow(2, attempt) + Math.random() * 1e3;
232
+ await this.sleep(delay);
233
+ }
234
+ }
235
+ throw lastError || new RainfallError("Request failed", "REQUEST_FAILED");
236
+ }
237
+ /**
238
+ * Execute a tool/node by ID
239
+ */
240
+ async executeTool(toolId, params, options) {
241
+ return this.request(`/tools/${toolId}`, {
242
+ method: "POST",
243
+ body: params
244
+ }, options);
245
+ }
246
+ /**
247
+ * List all available tools
248
+ */
249
+ async listTools() {
250
+ return this.request("/tools");
251
+ }
252
+ /**
253
+ * Get tool schema/parameters
254
+ */
255
+ async getToolSchema(toolId) {
256
+ return this.request(`/tools/${toolId}/schema`);
257
+ }
258
+ /**
259
+ * Get subscriber info
260
+ */
261
+ async getMe() {
262
+ return this.request("/me");
263
+ }
264
+ sleep(ms) {
265
+ return new Promise((resolve) => setTimeout(resolve, ms));
266
+ }
267
+ };
268
+
269
+ // src/namespaces/integrations.ts
270
+ function createIntegrations(client) {
271
+ return new IntegrationsNamespace(client);
272
+ }
273
+ var IntegrationsNamespace = class {
274
+ constructor(client) {
275
+ this.client = client;
276
+ }
277
+ get github() {
278
+ return {
279
+ issues: {
280
+ create: (params) => this.client.executeTool("github-create-issue", params),
281
+ list: (params) => this.client.executeTool("github-list-issues", params),
282
+ get: (params) => this.client.executeTool("github-get-issue", params),
283
+ update: (params) => this.client.executeTool("github-update-issue", params),
284
+ addComment: (params) => this.client.executeTool("github-add-issue-comment", params)
285
+ },
286
+ repos: {
287
+ get: (params) => this.client.executeTool("github-get-repository", params),
288
+ listBranches: (params) => this.client.executeTool("github-list-branches", params)
289
+ },
290
+ pullRequests: {
291
+ list: (params) => this.client.executeTool("github-list-pull-requests", params),
292
+ get: (params) => this.client.executeTool("github-get-pull-request", params)
293
+ }
294
+ };
295
+ }
296
+ get notion() {
297
+ return {
298
+ pages: {
299
+ create: (params) => this.client.executeTool("notion-pages-create", params),
300
+ retrieve: (params) => this.client.executeTool("notion-pages-retrieve", params),
301
+ update: (params) => this.client.executeTool("notion-pages-update", params)
302
+ },
303
+ databases: {
304
+ query: (params) => this.client.executeTool("notion-databases-query", params),
305
+ retrieve: (params) => this.client.executeTool("notion-databases-retrieve", params)
306
+ },
307
+ blocks: {
308
+ appendChildren: (params) => this.client.executeTool("notion-blocks-append-children", params),
309
+ retrieveChildren: (params) => this.client.executeTool("notion-blocks-retrieve-children", params)
310
+ }
311
+ };
312
+ }
313
+ get linear() {
314
+ return {
315
+ issues: {
316
+ create: (params) => this.client.executeTool("linear-core-issueCreate", params),
317
+ list: (params) => this.client.executeTool("linear-core-issues", params),
318
+ get: (params) => this.client.executeTool("linear-core-issue", params),
319
+ update: (params) => this.client.executeTool("linear-core-issueUpdate", params),
320
+ archive: (params) => this.client.executeTool("linear-core-issueArchive", params)
321
+ },
322
+ teams: {
323
+ list: () => this.client.executeTool("linear-core-teams", {})
324
+ }
325
+ };
326
+ }
327
+ get slack() {
328
+ return {
329
+ messages: {
330
+ send: (params) => this.client.executeTool("slack-core-postMessage", params),
331
+ list: (params) => this.client.executeTool("slack-core-listMessages", params)
332
+ },
333
+ channels: {
334
+ list: () => this.client.executeTool("slack-core-listChannels", {})
335
+ },
336
+ users: {
337
+ list: () => this.client.executeTool("slack-core-listUsers", {})
338
+ },
339
+ reactions: {
340
+ add: (params) => this.client.executeTool("slack-core-addReaction", params)
341
+ }
342
+ };
343
+ }
344
+ get figma() {
345
+ return {
346
+ files: {
347
+ get: (params) => this.client.executeTool("figma-files-getFile", { fileKey: params.fileKey }),
348
+ getNodes: (params) => this.client.executeTool("figma-files-getFileNodes", { fileKey: params.fileKey, nodeIds: params.nodeIds }),
349
+ getImages: (params) => this.client.executeTool("figma-files-getFileImage", { fileKey: params.fileKey, nodeIds: params.nodeIds, format: params.format }),
350
+ getComments: (params) => this.client.executeTool("figma-comments-getFileComments", { fileKey: params.fileKey }),
351
+ postComment: (params) => this.client.executeTool("figma-comments-postComment", { fileKey: params.fileKey, message: params.message, nodeId: params.nodeId })
352
+ },
353
+ projects: {
354
+ list: (params) => this.client.executeTool("figma-projects-getTeamProjects", { teamId: params.teamId }),
355
+ getFiles: (params) => this.client.executeTool("figma-projects-getProjectFiles", { projectId: params.projectId })
356
+ }
357
+ };
358
+ }
359
+ get stripe() {
360
+ return {
361
+ customers: {
362
+ create: (params) => this.client.executeTool("stripe-customers-create", params),
363
+ retrieve: (params) => this.client.executeTool("stripe-customers-retrieve", { customerId: params.customerId }),
364
+ update: (params) => this.client.executeTool("stripe-customers-update", params),
365
+ listPaymentMethods: (params) => this.client.executeTool("stripe-customers-list-payment-methods", { customerId: params.customerId })
366
+ },
367
+ paymentIntents: {
368
+ create: (params) => this.client.executeTool("stripe-payment-intents-create", params),
369
+ retrieve: (params) => this.client.executeTool("stripe-payment-intents-retrieve", { paymentIntentId: params.paymentIntentId }),
370
+ confirm: (params) => this.client.executeTool("stripe-payment-intents-confirm", { paymentIntentId: params.paymentIntentId })
371
+ },
372
+ subscriptions: {
373
+ create: (params) => this.client.executeTool("stripe-subscriptions-create", params),
374
+ retrieve: (params) => this.client.executeTool("stripe-subscriptions-retrieve", { subscriptionId: params.subscriptionId }),
375
+ cancel: (params) => this.client.executeTool("stripe-subscriptions-cancel", { subscriptionId: params.subscriptionId })
376
+ }
377
+ };
378
+ }
379
+ };
380
+
381
+ // src/namespaces/memory.ts
382
+ function createMemory(client) {
383
+ return {
384
+ create: (params) => client.executeTool("memory-create", params),
385
+ get: (params) => client.executeTool("memory-get", { memoryId: params.memoryId }),
386
+ recall: (params) => client.executeTool("memory-recall", params),
387
+ list: (params) => client.executeTool("memory-list", params ?? {}),
388
+ update: (params) => client.executeTool("memory-update", params),
389
+ delete: (params) => client.executeTool("memory-delete", { memoryId: params.memoryId })
390
+ };
391
+ }
392
+
393
+ // src/namespaces/articles.ts
394
+ function createArticles(client) {
395
+ return {
396
+ search: (params) => client.executeTool("article-search", params),
397
+ create: (params) => client.executeTool("article-create", params),
398
+ createFromUrl: (params) => client.executeTool("article-create-from-url", params),
399
+ fetch: (params) => client.executeTool("article-fetch", params),
400
+ recent: (params) => client.executeTool("article-recent", params ?? {}),
401
+ relevant: (params) => client.executeTool("article-relevant-news", params),
402
+ summarize: (params) => client.executeTool("article-summarize", params),
403
+ extractTopics: (params) => client.executeTool("article-topic-extractor", params)
404
+ };
405
+ }
406
+
407
+ // src/namespaces/web.ts
408
+ function createWeb(client) {
409
+ return {
410
+ search: {
411
+ exa: (params) => client.executeTool("exa-web-search", params),
412
+ perplexity: (params) => client.executeTool("perplexity-search", params)
413
+ },
414
+ fetch: (params) => client.executeTool("web-fetch", params),
415
+ htmlToMarkdown: (params) => client.executeTool("html-to-markdown-converter", params),
416
+ extractHtml: (params) => client.executeTool("extract-html-selector", params)
417
+ };
418
+ }
419
+
420
+ // src/namespaces/ai.ts
421
+ function createAI(client) {
422
+ return {
423
+ embeddings: {
424
+ document: (params) => client.executeTool("jina-document-embedding", params),
425
+ query: (params) => client.executeTool("jina-query-embedding", params),
426
+ image: (params) => client.executeTool("jina-image-embedding", { image: params.imageBase64 })
427
+ },
428
+ image: {
429
+ generate: (params) => client.executeTool("image-generation", params)
430
+ },
431
+ ocr: (params) => client.executeTool("ocr-text-extraction", { image: params.imageBase64 }),
432
+ vision: (params) => client.executeTool("llama-scout-vision", { image: params.imageBase64, prompt: params.prompt }),
433
+ chat: (params) => client.executeTool("xai-chat-completions", params),
434
+ complete: (params) => client.executeTool("fim", params),
435
+ classify: (params) => client.executeTool("jina-document-classifier", params),
436
+ segment: (params) => client.executeTool("jina-text-segmenter", params)
437
+ };
438
+ }
439
+
440
+ // src/namespaces/data.ts
441
+ function createData(client) {
442
+ return {
443
+ csv: {
444
+ query: (params) => client.executeTool("query-csv", params),
445
+ convert: (params) => client.executeTool("csv-convert", params)
446
+ },
447
+ scripts: {
448
+ create: (params) => client.executeTool("create-saved-script", params),
449
+ execute: (params) => client.executeTool("execute-saved-script", params),
450
+ list: () => client.executeTool("list-saved-scripts", {}),
451
+ update: (params) => client.executeTool("update-saved-script", params),
452
+ delete: (params) => client.executeTool("delete-saved-script", params)
453
+ },
454
+ similarity: {
455
+ search: (params) => client.executeTool("duck-db-similarity-search", params),
456
+ duckDbSearch: (params) => client.executeTool("duck-db-similarity-search", params)
457
+ }
458
+ };
459
+ }
460
+
461
+ // src/namespaces/utils.ts
462
+ function createUtils(client) {
463
+ return {
464
+ mermaid: (params) => client.executeTool("mermaid-diagram-generator", { mermaid: params.diagram }),
465
+ documentConvert: (params) => client.executeTool("document-format-converter", {
466
+ base64: `data:${params.mimeType};base64,${Buffer.from(params.document).toString("base64")}`,
467
+ format: params.format
468
+ }),
469
+ regex: {
470
+ match: (params) => client.executeTool("regex-match", params),
471
+ replace: (params) => client.executeTool("regex-replace", params)
472
+ },
473
+ jsonExtract: (params) => client.executeTool("json-extract", params),
474
+ digest: (params) => client.executeTool("digest-generator", { text: params.data }),
475
+ monteCarlo: (params) => client.executeTool("monte-carlo-simulation", params)
476
+ };
477
+ }
478
+
479
+ // src/sdk.ts
480
+ var Rainfall = class {
481
+ client;
482
+ _integrations;
483
+ _memory;
484
+ _articles;
485
+ _web;
486
+ _ai;
487
+ _data;
488
+ _utils;
489
+ constructor(config) {
490
+ this.client = new RainfallClient(config);
491
+ }
492
+ /**
493
+ * Integrations namespace - GitHub, Notion, Linear, Slack, Figma, Stripe
494
+ *
495
+ * @example
496
+ * ```typescript
497
+ * // GitHub
498
+ * await rainfall.integrations.github.issues.create({
499
+ * owner: 'facebook',
500
+ * repo: 'react',
501
+ * title: 'Bug report'
502
+ * });
503
+ *
504
+ * // Slack
505
+ * await rainfall.integrations.slack.messages.send({
506
+ * channelId: 'C123456',
507
+ * text: 'Hello team!'
508
+ * });
509
+ *
510
+ * // Linear
511
+ * const issues = await rainfall.integrations.linear.issues.list();
512
+ * ```
513
+ */
514
+ get integrations() {
515
+ if (!this._integrations) {
516
+ this._integrations = createIntegrations(this.client);
517
+ }
518
+ return this._integrations;
519
+ }
520
+ /**
521
+ * Memory namespace - Semantic memory storage and retrieval
522
+ *
523
+ * @example
524
+ * ```typescript
525
+ * // Store a memory
526
+ * await rainfall.memory.create({
527
+ * content: 'User prefers dark mode',
528
+ * keywords: ['preference', 'ui']
529
+ * });
530
+ *
531
+ * // Recall similar memories
532
+ * const memories = await rainfall.memory.recall({
533
+ * query: 'user preferences',
534
+ * topK: 5
535
+ * });
536
+ * ```
537
+ */
538
+ get memory() {
539
+ if (!this._memory) {
540
+ this._memory = createMemory(this.client);
541
+ }
542
+ return this._memory;
543
+ }
544
+ /**
545
+ * Articles namespace - News aggregation and article management
546
+ *
547
+ * @example
548
+ * ```typescript
549
+ * // Search news
550
+ * const articles = await rainfall.articles.search({
551
+ * query: 'artificial intelligence'
552
+ * });
553
+ *
554
+ * // Create from URL
555
+ * const article = await rainfall.articles.createFromUrl({
556
+ * url: 'https://example.com/article'
557
+ * });
558
+ *
559
+ * // Summarize
560
+ * const summary = await rainfall.articles.summarize({
561
+ * text: article.content
562
+ * });
563
+ * ```
564
+ */
565
+ get articles() {
566
+ if (!this._articles) {
567
+ this._articles = createArticles(this.client);
568
+ }
569
+ return this._articles;
570
+ }
571
+ /**
572
+ * Web namespace - Web search, scraping, and content extraction
573
+ *
574
+ * @example
575
+ * ```typescript
576
+ * // Search with Exa
577
+ * const results = await rainfall.web.search.exa({
578
+ * query: 'latest AI research'
579
+ * });
580
+ *
581
+ * // Fetch and convert
582
+ * const html = await rainfall.web.fetch({ url: 'https://example.com' });
583
+ * const markdown = await rainfall.web.htmlToMarkdown({ html });
584
+ *
585
+ * // Extract specific elements
586
+ * const links = await rainfall.web.extractHtml({
587
+ * html,
588
+ * selector: 'a[href]'
589
+ * });
590
+ * ```
591
+ */
592
+ get web() {
593
+ if (!this._web) {
594
+ this._web = createWeb(this.client);
595
+ }
596
+ return this._web;
597
+ }
598
+ /**
599
+ * AI namespace - Embeddings, image generation, OCR, vision, chat
600
+ *
601
+ * @example
602
+ * ```typescript
603
+ * // Generate embeddings
604
+ * const embedding = await rainfall.ai.embeddings.document({
605
+ * text: 'Hello world'
606
+ * });
607
+ *
608
+ * // Generate image
609
+ * const image = await rainfall.ai.image.generate({
610
+ * prompt: 'A serene mountain landscape'
611
+ * });
612
+ *
613
+ * // OCR
614
+ * const text = await rainfall.ai.ocr({ imageBase64: '...' });
615
+ *
616
+ * // Chat
617
+ * const response = await rainfall.ai.chat({
618
+ * messages: [{ role: 'user', content: 'Hello!' }]
619
+ * });
620
+ * ```
621
+ */
622
+ get ai() {
623
+ if (!this._ai) {
624
+ this._ai = createAI(this.client);
625
+ }
626
+ return this._ai;
627
+ }
628
+ /**
629
+ * Data namespace - CSV processing, scripts, similarity search
630
+ *
631
+ * @example
632
+ * ```typescript
633
+ * // Query CSV with SQL
634
+ * const results = await rainfall.data.csv.query({
635
+ * sql: 'SELECT * FROM data WHERE value > 100'
636
+ * });
637
+ *
638
+ * // Execute saved script
639
+ * const result = await rainfall.data.scripts.execute({
640
+ * name: 'my-script',
641
+ * params: { input: 'data' }
642
+ * });
643
+ * ```
644
+ */
645
+ get data() {
646
+ if (!this._data) {
647
+ this._data = createData(this.client);
648
+ }
649
+ return this._data;
650
+ }
651
+ /**
652
+ * Utils namespace - Mermaid diagrams, document conversion, regex, JSON extraction
653
+ *
654
+ * @example
655
+ * ```typescript
656
+ * // Generate diagram
657
+ * const diagram = await rainfall.utils.mermaid({
658
+ * diagram: 'graph TD; A-->B;'
659
+ * });
660
+ *
661
+ * // Convert document
662
+ * const pdf = await rainfall.utils.documentConvert({
663
+ * document: markdownContent,
664
+ * mimeType: 'text/markdown',
665
+ * format: 'pdf'
666
+ * });
667
+ *
668
+ * // Extract JSON from text
669
+ * const json = await rainfall.utils.jsonExtract({
670
+ * text: 'Here is some data: {"key": "value"}'
671
+ * });
672
+ * ```
673
+ */
674
+ get utils() {
675
+ if (!this._utils) {
676
+ this._utils = createUtils(this.client);
677
+ }
678
+ return this._utils;
679
+ }
680
+ /**
681
+ * Get the underlying HTTP client for advanced usage
682
+ */
683
+ getClient() {
684
+ return this.client;
685
+ }
686
+ /**
687
+ * List all available tools
688
+ */
689
+ async listTools() {
690
+ return this.client.listTools();
691
+ }
692
+ /**
693
+ * Get schema for a specific tool
694
+ */
695
+ async getToolSchema(toolId) {
696
+ return this.client.getToolSchema(toolId);
697
+ }
698
+ /**
699
+ * Execute any tool by ID (low-level access)
700
+ */
701
+ async executeTool(toolId, params) {
702
+ return this.client.executeTool(toolId, params);
703
+ }
704
+ /**
705
+ * Get current subscriber info and usage
706
+ */
707
+ async getMe() {
708
+ return this.client.getMe();
709
+ }
710
+ /**
711
+ * Get current rate limit info
712
+ */
713
+ getRateLimitInfo() {
714
+ return this.client.getRateLimitInfo();
715
+ }
716
+ };
717
+
718
+ export {
719
+ RainfallError,
720
+ AuthenticationError,
721
+ RateLimitError,
722
+ ValidationError,
723
+ NotFoundError,
724
+ ServerError,
725
+ TimeoutError,
726
+ NetworkError,
727
+ ToolNotFoundError,
728
+ parseErrorResponse,
729
+ RainfallClient,
730
+ Rainfall
731
+ };