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