@rainfall-devkit/sdk 0.2.2 → 0.2.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.
Files changed (39) hide show
  1. package/dist/chunk-2FYYTIJQ.mjs +993 -0
  2. package/dist/chunk-6FXRLPLR.mjs +436 -0
  3. package/dist/chunk-CC4O7GSQ.mjs +978 -0
  4. package/dist/chunk-CQ5TV7CQ.mjs +989 -0
  5. package/dist/chunk-GPKQUVAV.mjs +987 -0
  6. package/dist/chunk-LJQEO3CY.mjs +150 -0
  7. package/dist/chunk-S7MOQCV4.mjs +137 -0
  8. package/dist/chunk-XHPFY5MH.mjs +132 -0
  9. package/dist/cli/index.js +1128 -49
  10. package/dist/cli/index.mjs +370 -30
  11. package/dist/daemon/index.d.mts +3 -3
  12. package/dist/daemon/index.d.ts +3 -3
  13. package/dist/daemon/index.js +416 -130
  14. package/dist/daemon/index.mjs +2 -1
  15. package/dist/display-KKJPO6UA.mjs +14 -0
  16. package/dist/errors-CY6HW2I5.mjs +24 -0
  17. package/dist/index.d.mts +66 -4
  18. package/dist/index.d.ts +66 -4
  19. package/dist/index.js +896 -113
  20. package/dist/index.mjs +18 -6
  21. package/dist/listeners-BBNBsJCk.d.ts +372 -0
  22. package/dist/listeners-BCEypw1u.d.ts +372 -0
  23. package/dist/listeners-BGdrWpkP.d.mts +372 -0
  24. package/dist/listeners-CMUKjEkb.d.mts +372 -0
  25. package/dist/listeners-CadPNUHd.d.ts +372 -0
  26. package/dist/listeners-Ckdj6D8T.d.mts +372 -0
  27. package/dist/mcp.d.mts +2 -2
  28. package/dist/mcp.d.ts +2 -2
  29. package/dist/mcp.js +410 -102
  30. package/dist/mcp.mjs +4 -2
  31. package/dist/param-parser-JVKB5FQK.mjs +12 -0
  32. package/dist/param-parser-PAKCNDBX.mjs +136 -0
  33. package/dist/sdk-BUVNdBc7.d.mts +1167 -0
  34. package/dist/sdk-BUVNdBc7.d.ts +1167 -0
  35. package/dist/sdk-Cl5Qzt4I.d.mts +1165 -0
  36. package/dist/sdk-Cl5Qzt4I.d.ts +1165 -0
  37. package/dist/sdk-DQKNbBce.d.mts +1162 -0
  38. package/dist/sdk-DQKNbBce.d.ts +1162 -0
  39. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
8
11
  var __export = (target, all) => {
9
12
  for (var name in all)
10
13
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -27,122 +30,27 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
30
  ));
28
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
32
 
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
+ // node_modules/tsup/assets/cjs_shims.js
34
+ var init_cjs_shims = __esm({
35
+ "node_modules/tsup/assets/cjs_shims.js"() {
36
+ "use strict";
37
+ }
38
+ });
39
+
40
+ // src/errors.ts
41
+ var errors_exports = {};
42
+ __export(errors_exports, {
33
43
  AuthenticationError: () => AuthenticationError,
34
- EdgeNodeSecurity: () => EdgeNodeSecurity,
35
44
  NetworkError: () => NetworkError,
36
45
  NotFoundError: () => NotFoundError,
37
- Rainfall: () => Rainfall,
38
- RainfallClient: () => RainfallClient,
39
- RainfallDaemonContext: () => RainfallDaemonContext,
40
46
  RainfallError: () => RainfallError,
41
- RainfallListenerRegistry: () => RainfallListenerRegistry,
42
- RainfallNetworkedExecutor: () => RainfallNetworkedExecutor,
43
47
  RateLimitError: () => RateLimitError,
44
- SecureEdgeClient: () => SecureEdgeClient,
45
48
  ServerError: () => ServerError,
46
49
  TimeoutError: () => TimeoutError,
47
50
  ToolNotFoundError: () => ToolNotFoundError,
48
- VERSION: () => VERSION,
49
51
  ValidationError: () => ValidationError,
50
- createCronWorkflow: () => createCronWorkflow,
51
- createEdgeNodeSecurity: () => createEdgeNodeSecurity,
52
- createFileWatcherWorkflow: () => createFileWatcherWorkflow,
53
- createSecureEdgeClient: () => createSecureEdgeClient
52
+ parseErrorResponse: () => parseErrorResponse
54
53
  });
55
- module.exports = __toCommonJS(index_exports);
56
-
57
- // src/errors.ts
58
- var RainfallError = class _RainfallError extends Error {
59
- constructor(message, code, statusCode, details) {
60
- super(message);
61
- this.code = code;
62
- this.statusCode = statusCode;
63
- this.details = details;
64
- this.name = "RainfallError";
65
- Object.setPrototypeOf(this, _RainfallError.prototype);
66
- }
67
- toJSON() {
68
- return {
69
- name: this.name,
70
- code: this.code,
71
- message: this.message,
72
- statusCode: this.statusCode,
73
- details: this.details
74
- };
75
- }
76
- };
77
- var AuthenticationError = class _AuthenticationError extends RainfallError {
78
- constructor(message = "Invalid API key", details) {
79
- super(message, "AUTHENTICATION_ERROR", 401, details);
80
- this.name = "AuthenticationError";
81
- Object.setPrototypeOf(this, _AuthenticationError.prototype);
82
- }
83
- };
84
- var RateLimitError = class _RateLimitError extends RainfallError {
85
- retryAfter;
86
- limit;
87
- remaining;
88
- resetAt;
89
- constructor(message = "Rate limit exceeded", retryAfter = 60, limit = 0, remaining = 0, resetAt) {
90
- super(message, "RATE_LIMIT_ERROR", 429, { retryAfter, limit, remaining });
91
- this.name = "RateLimitError";
92
- this.retryAfter = retryAfter;
93
- this.limit = limit;
94
- this.remaining = remaining;
95
- this.resetAt = resetAt || new Date(Date.now() + retryAfter * 1e3);
96
- Object.setPrototypeOf(this, _RateLimitError.prototype);
97
- }
98
- };
99
- var ValidationError = class _ValidationError extends RainfallError {
100
- constructor(message, details) {
101
- super(message, "VALIDATION_ERROR", 400, details);
102
- this.name = "ValidationError";
103
- Object.setPrototypeOf(this, _ValidationError.prototype);
104
- }
105
- };
106
- var NotFoundError = class _NotFoundError extends RainfallError {
107
- constructor(resource, identifier) {
108
- super(
109
- `${resource}${identifier ? ` '${identifier}'` : ""} not found`,
110
- "NOT_FOUND_ERROR",
111
- 404,
112
- { resource, identifier }
113
- );
114
- this.name = "NotFoundError";
115
- Object.setPrototypeOf(this, _NotFoundError.prototype);
116
- }
117
- };
118
- var ServerError = class _ServerError extends RainfallError {
119
- constructor(message = "Internal server error", statusCode = 500) {
120
- super(message, "SERVER_ERROR", statusCode);
121
- this.name = "ServerError";
122
- Object.setPrototypeOf(this, _ServerError.prototype);
123
- }
124
- };
125
- var TimeoutError = class _TimeoutError extends RainfallError {
126
- constructor(timeoutMs) {
127
- super(`Request timed out after ${timeoutMs}ms`, "TIMEOUT_ERROR", 408);
128
- this.name = "TimeoutError";
129
- Object.setPrototypeOf(this, _TimeoutError.prototype);
130
- }
131
- };
132
- var NetworkError = class _NetworkError extends RainfallError {
133
- constructor(message = "Network error", details) {
134
- super(message, "NETWORK_ERROR", void 0, details);
135
- this.name = "NetworkError";
136
- Object.setPrototypeOf(this, _NetworkError.prototype);
137
- }
138
- };
139
- var ToolNotFoundError = class _ToolNotFoundError extends RainfallError {
140
- constructor(toolId) {
141
- super(`Tool '${toolId}' not found`, "TOOL_NOT_FOUND", 404, { toolId });
142
- this.name = "ToolNotFoundError";
143
- Object.setPrototypeOf(this, _ToolNotFoundError.prototype);
144
- }
145
- };
146
54
  function parseErrorResponse(response, data) {
147
55
  const statusCode = response.status;
148
56
  if (statusCode === 429) {
@@ -191,6 +99,586 @@ function parseErrorResponse(response, data) {
191
99
  );
192
100
  }
193
101
  }
102
+ var RainfallError, AuthenticationError, RateLimitError, ValidationError, NotFoundError, ServerError, TimeoutError, NetworkError, ToolNotFoundError;
103
+ var init_errors = __esm({
104
+ "src/errors.ts"() {
105
+ "use strict";
106
+ init_cjs_shims();
107
+ RainfallError = class _RainfallError extends Error {
108
+ constructor(message, code, statusCode, details) {
109
+ super(message);
110
+ this.code = code;
111
+ this.statusCode = statusCode;
112
+ this.details = details;
113
+ this.name = "RainfallError";
114
+ Object.setPrototypeOf(this, _RainfallError.prototype);
115
+ }
116
+ toJSON() {
117
+ return {
118
+ name: this.name,
119
+ code: this.code,
120
+ message: this.message,
121
+ statusCode: this.statusCode,
122
+ details: this.details
123
+ };
124
+ }
125
+ };
126
+ AuthenticationError = class _AuthenticationError extends RainfallError {
127
+ constructor(message = "Invalid API key", details) {
128
+ super(message, "AUTHENTICATION_ERROR", 401, details);
129
+ this.name = "AuthenticationError";
130
+ Object.setPrototypeOf(this, _AuthenticationError.prototype);
131
+ }
132
+ };
133
+ RateLimitError = class _RateLimitError extends RainfallError {
134
+ retryAfter;
135
+ limit;
136
+ remaining;
137
+ resetAt;
138
+ constructor(message = "Rate limit exceeded", retryAfter = 60, limit = 0, remaining = 0, resetAt) {
139
+ super(message, "RATE_LIMIT_ERROR", 429, { retryAfter, limit, remaining });
140
+ this.name = "RateLimitError";
141
+ this.retryAfter = retryAfter;
142
+ this.limit = limit;
143
+ this.remaining = remaining;
144
+ this.resetAt = resetAt || new Date(Date.now() + retryAfter * 1e3);
145
+ Object.setPrototypeOf(this, _RateLimitError.prototype);
146
+ }
147
+ };
148
+ ValidationError = class _ValidationError extends RainfallError {
149
+ constructor(message, details) {
150
+ super(message, "VALIDATION_ERROR", 400, details);
151
+ this.name = "ValidationError";
152
+ Object.setPrototypeOf(this, _ValidationError.prototype);
153
+ }
154
+ };
155
+ NotFoundError = class _NotFoundError extends RainfallError {
156
+ constructor(resource, identifier) {
157
+ super(
158
+ `${resource}${identifier ? ` '${identifier}'` : ""} not found`,
159
+ "NOT_FOUND_ERROR",
160
+ 404,
161
+ { resource, identifier }
162
+ );
163
+ this.name = "NotFoundError";
164
+ Object.setPrototypeOf(this, _NotFoundError.prototype);
165
+ }
166
+ };
167
+ ServerError = class _ServerError extends RainfallError {
168
+ constructor(message = "Internal server error", statusCode = 500) {
169
+ super(message, "SERVER_ERROR", statusCode);
170
+ this.name = "ServerError";
171
+ Object.setPrototypeOf(this, _ServerError.prototype);
172
+ }
173
+ };
174
+ TimeoutError = class _TimeoutError extends RainfallError {
175
+ constructor(timeoutMs) {
176
+ super(`Request timed out after ${timeoutMs}ms`, "TIMEOUT_ERROR", 408);
177
+ this.name = "TimeoutError";
178
+ Object.setPrototypeOf(this, _TimeoutError.prototype);
179
+ }
180
+ };
181
+ NetworkError = class _NetworkError extends RainfallError {
182
+ constructor(message = "Network error", details) {
183
+ super(message, "NETWORK_ERROR", void 0, details);
184
+ this.name = "NetworkError";
185
+ Object.setPrototypeOf(this, _NetworkError.prototype);
186
+ }
187
+ };
188
+ ToolNotFoundError = class _ToolNotFoundError extends RainfallError {
189
+ constructor(toolId) {
190
+ super(`Tool '${toolId}' not found`, "TOOL_NOT_FOUND", 404, { toolId });
191
+ this.name = "ToolNotFoundError";
192
+ Object.setPrototypeOf(this, _ToolNotFoundError.prototype);
193
+ }
194
+ };
195
+ }
196
+ });
197
+
198
+ // src/cli/core/display.ts
199
+ var display_exports = {};
200
+ __export(display_exports, {
201
+ detectImageData: () => detectImageData,
202
+ detectImageSupport: () => detectImageSupport,
203
+ displayImage: () => displayImage,
204
+ formatAsTable: () => formatAsTable,
205
+ formatResult: () => formatResult
206
+ });
207
+ function detectImageSupport() {
208
+ if (process.env.TERM_PROGRAM === "iTerm.app") {
209
+ return { supported: true, command: "imgcat" };
210
+ }
211
+ if (process.env.KITTY_WINDOW_ID) {
212
+ return { supported: true, command: "kitty +kitten icat" };
213
+ }
214
+ try {
215
+ return { supported: true, command: "xan" };
216
+ } catch {
217
+ }
218
+ try {
219
+ return { supported: true, command: "catimg" };
220
+ } catch {
221
+ }
222
+ return { supported: false };
223
+ }
224
+ async function displayImage(imageData, options = {}) {
225
+ const imageCommand = options.imageCommand || detectImageSupport().command;
226
+ if (!imageCommand) {
227
+ const { writeFileSync } = await import("fs");
228
+ const { tmpdir } = await import("os");
229
+ const { join: join2 } = await import("path");
230
+ const tempPath = join2(tmpdir(), `rainfall-image-${Date.now()}.png`);
231
+ const buffer = typeof imageData === "string" ? Buffer.from(imageData, "base64") : imageData;
232
+ writeFileSync(tempPath, buffer);
233
+ console.log(`Image saved to: ${tempPath}`);
234
+ return;
235
+ }
236
+ return new Promise((resolve, reject) => {
237
+ const buffer = typeof imageData === "string" ? Buffer.from(imageData, "base64") : imageData;
238
+ const child = (0, import_child_process.spawn)(imageCommand, [], {
239
+ stdio: ["pipe", "inherit", "inherit"],
240
+ shell: true
241
+ });
242
+ child.stdin.write(buffer);
243
+ child.stdin.end();
244
+ child.on("close", (code) => {
245
+ if (code === 0) {
246
+ resolve();
247
+ } else {
248
+ reject(new Error(`Image display failed with code ${code}`));
249
+ }
250
+ });
251
+ child.on("error", reject);
252
+ });
253
+ }
254
+ function formatAsTable(data, columns) {
255
+ if (!Array.isArray(data) || data.length === 0) {
256
+ return "No data";
257
+ }
258
+ const cols = columns || Object.keys(data[0]);
259
+ const widths = {};
260
+ for (const col of cols) {
261
+ widths[col] = Math.max(
262
+ col.length,
263
+ ...data.map((row) => {
264
+ const val = row?.[col];
265
+ return String(val ?? "").slice(0, 50).length;
266
+ })
267
+ );
268
+ }
269
+ const lines = [];
270
+ const header = cols.map((col) => col.padEnd(widths[col])).join(" ");
271
+ lines.push(header);
272
+ lines.push(cols.map((col) => "-".repeat(widths[col])).join(" "));
273
+ for (const row of data) {
274
+ const line = cols.map((col) => {
275
+ const val = row?.[col];
276
+ const str = String(val ?? "").slice(0, 50);
277
+ return str.padEnd(widths[col]);
278
+ }).join(" ");
279
+ lines.push(line);
280
+ }
281
+ return lines.join("\n");
282
+ }
283
+ async function formatResult(result, options = {}) {
284
+ const mode = options.mode || "pretty";
285
+ switch (mode) {
286
+ case "raw":
287
+ return JSON.stringify(result);
288
+ case "pretty":
289
+ return JSON.stringify(result, null, 2);
290
+ case "table":
291
+ if (Array.isArray(result)) {
292
+ return formatAsTable(result, options.columns);
293
+ }
294
+ return JSON.stringify(result, null, 2);
295
+ case "terminal":
296
+ if (typeof result === "string") {
297
+ return result;
298
+ }
299
+ if (Array.isArray(result) && result.every((r) => typeof r === "string")) {
300
+ return result.join("\n");
301
+ }
302
+ return JSON.stringify(result);
303
+ default:
304
+ return JSON.stringify(result, null, 2);
305
+ }
306
+ }
307
+ function detectImageData(result) {
308
+ if (!result || typeof result !== "object") {
309
+ return { hasImage: false };
310
+ }
311
+ const obj = result;
312
+ const imageFields = ["image", "imageData", "imageBase64", "png", "jpeg", "data"];
313
+ for (const field of imageFields) {
314
+ if (obj[field] && typeof obj[field] === "string") {
315
+ const value = obj[field];
316
+ if (value.startsWith("data:image/") || value.length > 100) {
317
+ return {
318
+ hasImage: true,
319
+ imageData: value.startsWith("data:image/") ? value.split(",")[1] : value
320
+ };
321
+ }
322
+ }
323
+ }
324
+ if (obj.url && typeof obj.url === "string" && (obj.url.endsWith(".png") || obj.url.endsWith(".jpg") || obj.url.endsWith(".jpeg"))) {
325
+ return { hasImage: true, imagePath: obj.url };
326
+ }
327
+ return { hasImage: false };
328
+ }
329
+ var import_child_process;
330
+ var init_display = __esm({
331
+ "src/cli/core/display.ts"() {
332
+ "use strict";
333
+ init_cjs_shims();
334
+ import_child_process = require("child_process");
335
+ }
336
+ });
337
+
338
+ // src/cli/core/param-parser.ts
339
+ var param_parser_exports = {};
340
+ __export(param_parser_exports, {
341
+ formatValueForDisplay: () => formatValueForDisplay,
342
+ generateParamExample: () => generateParamExample,
343
+ parseCliArgs: () => parseCliArgs,
344
+ parseValue: () => parseValue
345
+ });
346
+ function parseValue(value, schema, options = {}) {
347
+ const opts = { ...DEFAULT_OPTIONS, ...options };
348
+ if (!schema) {
349
+ try {
350
+ return JSON.parse(value);
351
+ } catch {
352
+ return value;
353
+ }
354
+ }
355
+ const expectedType = schema.type;
356
+ switch (expectedType) {
357
+ case "array":
358
+ return parseArrayValue(value, schema, opts);
359
+ case "number":
360
+ return parseNumberValue(value, opts);
361
+ case "boolean":
362
+ return parseBooleanValue(value, opts);
363
+ case "string":
364
+ return value;
365
+ case "object":
366
+ try {
367
+ return JSON.parse(value);
368
+ } catch {
369
+ return value;
370
+ }
371
+ default:
372
+ try {
373
+ return JSON.parse(value);
374
+ } catch {
375
+ return value;
376
+ }
377
+ }
378
+ }
379
+ function parseArrayValue(value, schema, options) {
380
+ if (value.startsWith("[") && value.endsWith("]")) {
381
+ try {
382
+ return JSON.parse(value);
383
+ } catch {
384
+ }
385
+ }
386
+ if (options.arrayInterpolation && value.includes(options.arraySeparator)) {
387
+ const items = value.split(options.arraySeparator).map((s) => s.trim()).filter(Boolean);
388
+ if (schema.items) {
389
+ return items.map((item) => parseValue(item, schema.items, { ...options, arrayInterpolation: false }));
390
+ }
391
+ return items;
392
+ }
393
+ if (schema.items) {
394
+ return [parseValue(value, schema.items, { ...options, arrayInterpolation: false })];
395
+ }
396
+ return [value];
397
+ }
398
+ function parseNumberValue(value, options) {
399
+ if (!options.numberParsing) {
400
+ return value;
401
+ }
402
+ const num = Number(value);
403
+ if (!isNaN(num) && isFinite(num)) {
404
+ return num;
405
+ }
406
+ return value;
407
+ }
408
+ function parseBooleanValue(value, options) {
409
+ if (!options.booleanParsing) {
410
+ return value;
411
+ }
412
+ const lower = value.toLowerCase();
413
+ if (lower === "true" || lower === "yes" || lower === "1" || lower === "on") {
414
+ return true;
415
+ }
416
+ if (lower === "false" || lower === "no" || lower === "0" || lower === "off") {
417
+ return false;
418
+ }
419
+ return value;
420
+ }
421
+ function parseCliArgs(args, schema, options = {}) {
422
+ const params = {};
423
+ const opts = { ...DEFAULT_OPTIONS, ...options };
424
+ const parameters = schema?.parameters || {};
425
+ for (let i = 0; i < args.length; i++) {
426
+ const arg = args[i];
427
+ if (arg.startsWith("--")) {
428
+ const key = arg.slice(2);
429
+ const value = args[++i];
430
+ if (value === void 0) {
431
+ params[key] = true;
432
+ continue;
433
+ }
434
+ const paramSchema = parameters[key];
435
+ params[key] = parseValue(value, paramSchema, opts);
436
+ }
437
+ }
438
+ return params;
439
+ }
440
+ function formatValueForDisplay(value) {
441
+ if (value === null) return "null";
442
+ if (value === void 0) return "undefined";
443
+ if (typeof value === "string") return value;
444
+ if (typeof value === "number") return String(value);
445
+ if (typeof value === "boolean") return String(value);
446
+ if (Array.isArray(value)) {
447
+ return value.map(formatValueForDisplay).join(",");
448
+ }
449
+ return JSON.stringify(value);
450
+ }
451
+ function generateParamExample(key, schema) {
452
+ const type = schema.type || "string";
453
+ switch (type) {
454
+ case "array":
455
+ if (schema.items?.type === "string") {
456
+ return `--${key} item1,item2,item3`;
457
+ }
458
+ return `--${key} '["item1", "item2"]'`;
459
+ case "number":
460
+ return `--${key} 42`;
461
+ case "boolean":
462
+ return `--${key} true`;
463
+ case "object":
464
+ return `--${key} '{"key": "value"}'`;
465
+ default:
466
+ return `--${key} "value"`;
467
+ }
468
+ }
469
+ var DEFAULT_OPTIONS;
470
+ var init_param_parser = __esm({
471
+ "src/cli/core/param-parser.ts"() {
472
+ "use strict";
473
+ init_cjs_shims();
474
+ DEFAULT_OPTIONS = {
475
+ arrayInterpolation: true,
476
+ numberParsing: true,
477
+ booleanParsing: true,
478
+ arraySeparator: ","
479
+ };
480
+ }
481
+ });
482
+
483
+ // src/index.ts
484
+ var index_exports = {};
485
+ __export(index_exports, {
486
+ AuthenticationError: () => AuthenticationError,
487
+ EdgeNodeSecurity: () => EdgeNodeSecurity,
488
+ NetworkError: () => NetworkError,
489
+ NotFoundError: () => NotFoundError,
490
+ Rainfall: () => Rainfall,
491
+ RainfallClient: () => RainfallClient,
492
+ RainfallDaemonContext: () => RainfallDaemonContext,
493
+ RainfallError: () => RainfallError,
494
+ RainfallListenerRegistry: () => RainfallListenerRegistry,
495
+ RainfallNetworkedExecutor: () => RainfallNetworkedExecutor,
496
+ RateLimitError: () => RateLimitError,
497
+ SecureEdgeClient: () => SecureEdgeClient,
498
+ ServerError: () => ServerError,
499
+ TimeoutError: () => TimeoutError,
500
+ ToolNotFoundError: () => ToolNotFoundError,
501
+ VERSION: () => VERSION,
502
+ ValidationError: () => ValidationError,
503
+ clearSchemaCache: () => clearSchemaCache,
504
+ createCronWorkflow: () => createCronWorkflow,
505
+ createEdgeNodeSecurity: () => createEdgeNodeSecurity,
506
+ createFileWatcherWorkflow: () => createFileWatcherWorkflow,
507
+ createSecureEdgeClient: () => createSecureEdgeClient,
508
+ fetchToolSchema: () => fetchToolSchema,
509
+ formatValidationErrors: () => formatValidationErrors,
510
+ globalHandlerRegistry: () => globalHandlerRegistry,
511
+ validateParams: () => validateParams
512
+ });
513
+ module.exports = __toCommonJS(index_exports);
514
+ init_cjs_shims();
515
+
516
+ // src/client.ts
517
+ init_cjs_shims();
518
+ init_errors();
519
+
520
+ // src/validation.ts
521
+ init_cjs_shims();
522
+ init_errors();
523
+ var schemaCache = /* @__PURE__ */ new Map();
524
+ var CACHE_TTL_MS = 5 * 60 * 1e3;
525
+ async function fetchToolSchema(client, toolId) {
526
+ const cached = schemaCache.get(toolId);
527
+ if (cached && Date.now() - cached.timestamp < CACHE_TTL_MS) {
528
+ return cached.schema;
529
+ }
530
+ const response = await client.request(
531
+ `/olympic/subscribers/me/nodes/${toolId}/params`
532
+ );
533
+ if (!response.success || !response.params) {
534
+ throw new ValidationError(`Failed to fetch schema for tool '${toolId}'`);
535
+ }
536
+ schemaCache.set(toolId, { schema: response.params, timestamp: Date.now() });
537
+ return response.params;
538
+ }
539
+ function clearSchemaCache() {
540
+ schemaCache.clear();
541
+ }
542
+ function validateParams(schema, params, toolId) {
543
+ const errors = [];
544
+ const parameters = schema.parameters || {};
545
+ for (const [key, paramSchema] of Object.entries(parameters)) {
546
+ if (paramSchema.optional !== true && !(key in (params || {}))) {
547
+ errors.push({
548
+ path: key,
549
+ message: `Missing required parameter '${key}'`,
550
+ expected: paramSchema.type
551
+ });
552
+ }
553
+ }
554
+ if (params) {
555
+ for (const [key, value] of Object.entries(params)) {
556
+ const paramSchema = parameters[key];
557
+ if (!paramSchema) {
558
+ errors.push({
559
+ path: key,
560
+ message: `Unknown parameter '${key}'`,
561
+ received: value
562
+ });
563
+ continue;
564
+ }
565
+ const typeError = validateType(key, value, paramSchema);
566
+ if (typeError) {
567
+ errors.push(typeError);
568
+ }
569
+ }
570
+ }
571
+ return {
572
+ valid: errors.length === 0,
573
+ errors
574
+ };
575
+ }
576
+ function validateType(path, value, schema) {
577
+ if (value === null || value === void 0) {
578
+ if (schema.optional === true) {
579
+ return null;
580
+ }
581
+ return {
582
+ path,
583
+ message: `Parameter '${path}' is required but received ${value}`,
584
+ received: value,
585
+ expected: schema.type
586
+ };
587
+ }
588
+ const expectedType = schema.type;
589
+ const actualType = getJsType(value);
590
+ switch (expectedType) {
591
+ case "string":
592
+ if (typeof value !== "string") {
593
+ return {
594
+ path,
595
+ message: `Parameter '${path}' must be a string, received ${actualType}`,
596
+ received: value,
597
+ expected: "string"
598
+ };
599
+ }
600
+ break;
601
+ case "number":
602
+ if (typeof value !== "number" || isNaN(value)) {
603
+ return {
604
+ path,
605
+ message: `Parameter '${path}' must be a number, received ${actualType}`,
606
+ received: value,
607
+ expected: "number"
608
+ };
609
+ }
610
+ break;
611
+ case "boolean":
612
+ if (typeof value !== "boolean") {
613
+ return {
614
+ path,
615
+ message: `Parameter '${path}' must be a boolean, received ${actualType}`,
616
+ received: value,
617
+ expected: "boolean"
618
+ };
619
+ }
620
+ break;
621
+ case "array":
622
+ if (!Array.isArray(value)) {
623
+ return {
624
+ path,
625
+ message: `Parameter '${path}' must be an array, received ${actualType}`,
626
+ received: value,
627
+ expected: "array"
628
+ };
629
+ }
630
+ if (schema.items) {
631
+ for (let i = 0; i < value.length; i++) {
632
+ const itemError = validateType(`${path}[${i}]`, value[i], schema.items);
633
+ if (itemError) {
634
+ return itemError;
635
+ }
636
+ }
637
+ }
638
+ break;
639
+ case "object":
640
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
641
+ return {
642
+ path,
643
+ message: `Parameter '${path}' must be an object, received ${actualType}`,
644
+ received: value,
645
+ expected: "object"
646
+ };
647
+ }
648
+ if (schema.properties) {
649
+ const objValue = value;
650
+ for (const [propKey, propSchema] of Object.entries(schema.properties)) {
651
+ if (objValue[propKey] !== void 0) {
652
+ const propError = validateType(`${path}.${propKey}`, objValue[propKey], propSchema);
653
+ if (propError) {
654
+ return propError;
655
+ }
656
+ }
657
+ }
658
+ }
659
+ break;
660
+ default:
661
+ break;
662
+ }
663
+ return null;
664
+ }
665
+ function getJsType(value) {
666
+ if (value === null) return "null";
667
+ if (Array.isArray(value)) return "array";
668
+ return typeof value;
669
+ }
670
+ function formatValidationErrors(result) {
671
+ if (result.valid) return "No validation errors";
672
+ const lines = result.errors.map((err) => {
673
+ let line = ` - ${err.message}`;
674
+ if (err.received !== void 0) {
675
+ line += ` (received: ${JSON.stringify(err.received).slice(0, 50)})`;
676
+ }
677
+ return line;
678
+ });
679
+ return `Validation failed with ${result.errors.length} error(s):
680
+ ${lines.join("\n")}`;
681
+ }
194
682
 
195
683
  // src/client.ts
196
684
  var DEFAULT_BASE_URL = "https://olympic-api.pragma-digital.org/v1";
@@ -203,6 +691,7 @@ var RainfallClient = class {
203
691
  defaultTimeout;
204
692
  defaultRetries;
205
693
  defaultRetryDelay;
694
+ disableValidation;
206
695
  lastRateLimitInfo;
207
696
  subscriberId;
208
697
  constructor(config) {
@@ -211,6 +700,7 @@ var RainfallClient = class {
211
700
  this.defaultTimeout = config.timeout || DEFAULT_TIMEOUT;
212
701
  this.defaultRetries = config.retries ?? DEFAULT_RETRIES;
213
702
  this.defaultRetryDelay = config.retryDelay || DEFAULT_RETRY_DELAY;
703
+ this.disableValidation = config.disableValidation ?? false;
214
704
  }
215
705
  /**
216
706
  * Get the last rate limit info from the API
@@ -293,15 +783,72 @@ var RainfallClient = class {
293
783
  }
294
784
  /**
295
785
  * Execute a tool/node by ID
786
+ *
787
+ * @param toolId - The ID of the tool/node to execute
788
+ * @param params - Parameters to pass to the tool
789
+ * @param options - Request options including skipValidation to bypass param validation
296
790
  */
297
791
  async executeTool(toolId, params, options) {
792
+ if (!this.disableValidation && !options?.skipValidation) {
793
+ const validation = await this.validateToolParams(toolId, params);
794
+ if (!validation.valid) {
795
+ const { ValidationError: ValidationError2 } = await Promise.resolve().then(() => (init_errors(), errors_exports));
796
+ throw new ValidationError2(
797
+ `Parameter validation failed for tool '${toolId}': ${formatValidationErrors(validation)}`,
798
+ { toolId, errors: validation.errors }
799
+ );
800
+ }
801
+ }
298
802
  const subscriberId = await this.ensureSubscriberId();
803
+ const body = params || {};
804
+ if (options?.targetEdge) {
805
+ body._targetEdge = options.targetEdge;
806
+ }
299
807
  const response = await this.request(`/olympic/subscribers/${subscriberId}/nodes/${toolId}`, {
300
808
  method: "POST",
301
- body: params || {}
809
+ body
302
810
  }, options);
811
+ if (response.success === false) {
812
+ const errorMessage = typeof response.error === "string" ? response.error : JSON.stringify(response.error);
813
+ throw new RainfallError(
814
+ `Tool execution failed: ${errorMessage}`,
815
+ "TOOL_EXECUTION_ERROR",
816
+ 400,
817
+ { toolId, error: response.error }
818
+ );
819
+ }
303
820
  return response.result;
304
821
  }
822
+ /**
823
+ * Validate parameters for a tool without executing it
824
+ * Fetches the tool schema and validates the provided params
825
+ *
826
+ * @param toolId - The ID of the tool to validate params for
827
+ * @param params - Parameters to validate
828
+ * @returns Validation result with detailed error information
829
+ *
830
+ * @example
831
+ * ```typescript
832
+ * const result = await client.validateToolParams('finviz-quotes', { tickers: ['AAPL'] });
833
+ * if (!result.valid) {
834
+ * console.log('Validation errors:', result.errors);
835
+ * }
836
+ * ```
837
+ */
838
+ async validateToolParams(toolId, params) {
839
+ try {
840
+ const schema = await fetchToolSchema(this, toolId);
841
+ return validateParams(schema, params, toolId);
842
+ } catch (error) {
843
+ if (error instanceof RainfallError && error.statusCode === 404) {
844
+ return {
845
+ valid: false,
846
+ errors: [{ path: toolId, message: `Tool '${toolId}' not found` }]
847
+ };
848
+ }
849
+ return { valid: true, errors: [] };
850
+ }
851
+ }
305
852
  /**
306
853
  * List all available tools
307
854
  */
@@ -324,11 +871,20 @@ var RainfallClient = class {
324
871
  }
325
872
  /**
326
873
  * Get tool schema/parameters
874
+ *
875
+ * @param toolId - The ID of the tool to get schema for
876
+ * @returns Tool schema including parameters and output definitions
327
877
  */
328
878
  async getToolSchema(toolId) {
329
- const subscriberId = await this.ensureSubscriberId();
330
- const response = await this.request(`/olympic/subscribers/${subscriberId}/nodes/${toolId}/params`);
331
- return response.params;
879
+ const schema = await fetchToolSchema(this, toolId);
880
+ return {
881
+ name: schema.name,
882
+ description: schema.description,
883
+ category: schema.category,
884
+ parameters: schema.parameters,
885
+ output: schema.output,
886
+ metadata: schema.metadata || {}
887
+ };
332
888
  }
333
889
  /**
334
890
  * Get subscriber info
@@ -412,7 +968,11 @@ var RainfallClient = class {
412
968
  }
413
969
  };
414
970
 
971
+ // src/sdk.ts
972
+ init_cjs_shims();
973
+
415
974
  // src/namespaces/integrations.ts
975
+ init_cjs_shims();
416
976
  function createIntegrations(client) {
417
977
  return new IntegrationsNamespace(client);
418
978
  }
@@ -525,6 +1085,7 @@ var IntegrationsNamespace = class {
525
1085
  };
526
1086
 
527
1087
  // src/namespaces/memory.ts
1088
+ init_cjs_shims();
528
1089
  function createMemory(client) {
529
1090
  return {
530
1091
  create: (params) => client.executeTool("memory-create", params),
@@ -537,6 +1098,7 @@ function createMemory(client) {
537
1098
  }
538
1099
 
539
1100
  // src/namespaces/articles.ts
1101
+ init_cjs_shims();
540
1102
  function createArticles(client) {
541
1103
  return {
542
1104
  search: (params) => client.executeTool("article-search", params),
@@ -551,6 +1113,7 @@ function createArticles(client) {
551
1113
  }
552
1114
 
553
1115
  // src/namespaces/web.ts
1116
+ init_cjs_shims();
554
1117
  function createWeb(client) {
555
1118
  return {
556
1119
  search: {
@@ -564,6 +1127,7 @@ function createWeb(client) {
564
1127
  }
565
1128
 
566
1129
  // src/namespaces/ai.ts
1130
+ init_cjs_shims();
567
1131
  function createAI(client) {
568
1132
  return {
569
1133
  embeddings: {
@@ -589,6 +1153,7 @@ function createAI(client) {
589
1153
  }
590
1154
 
591
1155
  // src/namespaces/data.ts
1156
+ init_cjs_shims();
592
1157
  function createData(client) {
593
1158
  return {
594
1159
  csv: {
@@ -610,6 +1175,7 @@ function createData(client) {
610
1175
  }
611
1176
 
612
1177
  // src/namespaces/utils.ts
1178
+ init_cjs_shims();
613
1179
  function createUtils(client) {
614
1180
  return {
615
1181
  mermaid: (params) => client.executeTool("mermaid-diagram-generator", { mermaid: params.diagram }),
@@ -848,9 +1414,40 @@ var Rainfall = class {
848
1414
  }
849
1415
  /**
850
1416
  * Execute any tool by ID (low-level access)
1417
+ *
1418
+ * @param toolId - The ID of the tool to execute
1419
+ * @param params - Parameters to pass to the tool
1420
+ * @param options - Execution options including skipValidation to bypass param validation
1421
+ *
1422
+ * @example
1423
+ * ```typescript
1424
+ * // Execute with validation (default)
1425
+ * const result = await rainfall.executeTool('finviz-quotes', { tickers: ['AAPL'] });
1426
+ *
1427
+ * // Execute without validation
1428
+ * const result = await rainfall.executeTool('finviz-quotes', { tickers: ['AAPL'] }, { skipValidation: true });
1429
+ * ```
851
1430
  */
852
- async executeTool(toolId, params) {
853
- return this.client.executeTool(toolId, params);
1431
+ async executeTool(toolId, params, options) {
1432
+ return this.client.executeTool(toolId, params, options);
1433
+ }
1434
+ /**
1435
+ * Validate parameters for a tool without executing it
1436
+ *
1437
+ * @param toolId - The ID of the tool to validate params for
1438
+ * @param params - Parameters to validate
1439
+ * @returns Validation result with detailed error information
1440
+ *
1441
+ * @example
1442
+ * ```typescript
1443
+ * const result = await rainfall.validateToolParams('finviz-quotes', { tickers: ['AAPL'] });
1444
+ * if (!result.valid) {
1445
+ * console.log('Validation errors:', result.errors);
1446
+ * }
1447
+ * ```
1448
+ */
1449
+ async validateToolParams(toolId, params) {
1450
+ return this.client.validateToolParams(toolId, params);
854
1451
  }
855
1452
  /**
856
1453
  * Get current subscriber info and usage
@@ -909,7 +1506,11 @@ var Rainfall = class {
909
1506
  }
910
1507
  };
911
1508
 
1509
+ // src/index.ts
1510
+ init_errors();
1511
+
912
1512
  // src/services/networked.ts
1513
+ init_cjs_shims();
913
1514
  var RainfallNetworkedExecutor = class {
914
1515
  rainfall;
915
1516
  options;
@@ -1101,6 +1702,7 @@ var RainfallNetworkedExecutor = class {
1101
1702
  };
1102
1703
 
1103
1704
  // src/services/context.ts
1705
+ init_cjs_shims();
1104
1706
  var RainfallDaemonContext = class {
1105
1707
  rainfall;
1106
1708
  options;
@@ -1354,6 +1956,7 @@ var RainfallDaemonContext = class {
1354
1956
  };
1355
1957
 
1356
1958
  // src/services/listeners.ts
1959
+ init_cjs_shims();
1357
1960
  var RainfallListenerRegistry = class {
1358
1961
  rainfall;
1359
1962
  context;
@@ -1564,7 +2167,11 @@ function createCronWorkflow(name, cron, workflow) {
1564
2167
  };
1565
2168
  }
1566
2169
 
2170
+ // src/security/index.ts
2171
+ init_cjs_shims();
2172
+
1567
2173
  // src/security/edge-node.ts
2174
+ init_cjs_shims();
1568
2175
  var import_libsodium_wrappers_sumo = __toESM(require("libsodium-wrappers-sumo"));
1569
2176
  var EdgeNodeSecurity = class {
1570
2177
  sodiumReady;
@@ -1830,6 +2437,7 @@ async function createEdgeNodeSecurity(options = {}) {
1830
2437
  }
1831
2438
 
1832
2439
  // src/security/edge-client.ts
2440
+ init_cjs_shims();
1833
2441
  var import_fs = require("fs");
1834
2442
  var import_path = require("path");
1835
2443
  var SecureEdgeClient = class {
@@ -2034,6 +2642,176 @@ async function createSecureEdgeClient(client, options) {
2034
2642
  return secureClient;
2035
2643
  }
2036
2644
 
2645
+ // src/cli/handlers/_registry.ts
2646
+ init_cjs_shims();
2647
+
2648
+ // src/cli/core/types.ts
2649
+ init_cjs_shims();
2650
+ var ToolHandlerRegistry = class {
2651
+ handlers = [];
2652
+ register(handler) {
2653
+ this.handlers.push(handler);
2654
+ }
2655
+ findHandler(toolId) {
2656
+ return this.handlers.find((h) => {
2657
+ if (typeof h.toolId === "string") {
2658
+ return h.toolId === toolId;
2659
+ }
2660
+ return h.toolId.test(toolId);
2661
+ });
2662
+ }
2663
+ getAllHandlers() {
2664
+ return [...this.handlers];
2665
+ }
2666
+ };
2667
+ var globalHandlerRegistry = new ToolHandlerRegistry();
2668
+
2669
+ // src/cli/handlers/_registry.ts
2670
+ var imageGenerationHandler = {
2671
+ toolId: /image-generation|generate-image/,
2672
+ async display(context) {
2673
+ const { detectImageData: detectImageData2, displayImage: displayImage2 } = await Promise.resolve().then(() => (init_display(), display_exports));
2674
+ const { result, flags } = context;
2675
+ const imageInfo = detectImageData2(result);
2676
+ if (imageInfo.hasImage && !flags.raw) {
2677
+ try {
2678
+ if (imageInfo.imageData) {
2679
+ await displayImage2(imageInfo.imageData);
2680
+ return true;
2681
+ }
2682
+ } catch (error) {
2683
+ console.warn("Failed to display image:", error instanceof Error ? error.message : error);
2684
+ }
2685
+ }
2686
+ return false;
2687
+ }
2688
+ };
2689
+ var finvizQuotesHandler = {
2690
+ toolId: "finviz-quotes",
2691
+ async preflight(context) {
2692
+ const { parseValue: parseValue2 } = await Promise.resolve().then(() => (init_param_parser(), param_parser_exports));
2693
+ const params = { ...context.params };
2694
+ if (params.tickers && typeof params.tickers === "string") {
2695
+ params.tickers = parseValue2(params.tickers, { type: "array", items: { type: "string" } });
2696
+ }
2697
+ return { params };
2698
+ },
2699
+ async display(context) {
2700
+ const { result, flags } = context;
2701
+ if (flags.raw) {
2702
+ return false;
2703
+ }
2704
+ const obj = result;
2705
+ const quotes = obj?.quotes;
2706
+ if (Array.isArray(quotes) && quotes.length > 0) {
2707
+ const { formatAsTable: formatAsTable2 } = await Promise.resolve().then(() => (init_display(), display_exports));
2708
+ const tableData = quotes.map((q) => {
2709
+ const quote = q;
2710
+ const data = quote.data || {};
2711
+ return {
2712
+ Ticker: quote.ticker || data.Ticker || "-",
2713
+ Price: data.Price || data.Close || "-",
2714
+ Change: data.Change || "-",
2715
+ Volume: data.Volume || "-",
2716
+ "Market Cap": data.MarketCap || "-"
2717
+ };
2718
+ });
2719
+ console.log(formatAsTable2(tableData));
2720
+ const summary = obj?.summary;
2721
+ if (summary && typeof summary === "string") {
2722
+ console.log(`
2723
+ ${summary}`);
2724
+ }
2725
+ return true;
2726
+ }
2727
+ return false;
2728
+ }
2729
+ };
2730
+ var csvQueryHandler = {
2731
+ toolId: /query-csv|csv-query/,
2732
+ async display(context) {
2733
+ const { result, flags } = context;
2734
+ if (flags.raw) {
2735
+ return false;
2736
+ }
2737
+ if (Array.isArray(result) && result.length > 0) {
2738
+ const { formatAsTable: formatAsTable2 } = await Promise.resolve().then(() => (init_display(), display_exports));
2739
+ console.log(formatAsTable2(result));
2740
+ return true;
2741
+ }
2742
+ return false;
2743
+ }
2744
+ };
2745
+ var webSearchHandler = {
2746
+ toolId: /web-search|exa-web-search|perplexity/,
2747
+ async display(context) {
2748
+ const { result, flags } = context;
2749
+ if (flags.raw) {
2750
+ return false;
2751
+ }
2752
+ const obj = result;
2753
+ if (obj.results && typeof obj.results === "string") {
2754
+ console.log(obj.results);
2755
+ return true;
2756
+ }
2757
+ if (obj.answer || obj.summary) {
2758
+ console.log(obj.answer || obj.summary);
2759
+ if (obj.sources && Array.isArray(obj.sources)) {
2760
+ console.log("\n--- Sources ---");
2761
+ obj.sources.forEach((source, i) => {
2762
+ if (typeof source === "string") {
2763
+ console.log(` ${i + 1}. ${source}`);
2764
+ } else if (source && typeof source === "object") {
2765
+ const s = source;
2766
+ console.log(` ${i + 1}. ${s.title || s.url || JSON.stringify(source)}`);
2767
+ }
2768
+ });
2769
+ }
2770
+ return true;
2771
+ }
2772
+ return false;
2773
+ }
2774
+ };
2775
+ var memoryRecallHandler = {
2776
+ toolId: /memory-recall|recall/,
2777
+ async display(context) {
2778
+ const { result, flags } = context;
2779
+ if (flags.raw) {
2780
+ return false;
2781
+ }
2782
+ if (Array.isArray(result)) {
2783
+ if (result.length === 0) {
2784
+ console.log("No memories found.");
2785
+ return true;
2786
+ }
2787
+ console.log(`Found ${result.length} memory(s):
2788
+ `);
2789
+ result.forEach((mem, i) => {
2790
+ const memory = mem;
2791
+ console.log(`\u2500`.repeat(60));
2792
+ console.log(` ${i + 1}. ${memory.content || memory.text || JSON.stringify(memory).slice(0, 100)}`);
2793
+ if (memory.similarity) {
2794
+ console.log(` Similarity: ${(Number(memory.similarity) * 100).toFixed(1)}%`);
2795
+ }
2796
+ if (memory.keywords && Array.isArray(memory.keywords)) {
2797
+ console.log(` Keywords: ${memory.keywords.join(", ")}`);
2798
+ }
2799
+ console.log();
2800
+ });
2801
+ return true;
2802
+ }
2803
+ return false;
2804
+ }
2805
+ };
2806
+ function registerBuiltInHandlers(registry = globalHandlerRegistry) {
2807
+ registry.register(imageGenerationHandler);
2808
+ registry.register(finvizQuotesHandler);
2809
+ registry.register(csvQueryHandler);
2810
+ registry.register(webSearchHandler);
2811
+ registry.register(memoryRecallHandler);
2812
+ }
2813
+ registerBuiltInHandlers();
2814
+
2037
2815
  // src/index.ts
2038
2816
  var VERSION = "0.1.0";
2039
2817
  // Annotate the CommonJS export names for ESM import in node:
@@ -2055,8 +2833,13 @@ var VERSION = "0.1.0";
2055
2833
  ToolNotFoundError,
2056
2834
  VERSION,
2057
2835
  ValidationError,
2836
+ clearSchemaCache,
2058
2837
  createCronWorkflow,
2059
2838
  createEdgeNodeSecurity,
2060
2839
  createFileWatcherWorkflow,
2061
- createSecureEdgeClient
2840
+ createSecureEdgeClient,
2841
+ fetchToolSchema,
2842
+ formatValidationErrors,
2843
+ globalHandlerRegistry,
2844
+ validateParams
2062
2845
  });