modulex-js 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ModuleX
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,364 @@
1
+ # modulex-js
2
+
3
+ [![CI](https://github.com/ModuleXAI/modulex-js/actions/workflows/ci.yml/badge.svg)](https://github.com/ModuleXAI/modulex-js/actions/workflows/ci.yml)
4
+ [![npm version](https://img.shields.io/npm/v/modulex-js.svg)](https://www.npmjs.com/package/modulex-js)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
+ [![Node.js](https://img.shields.io/node/v/modulex-js.svg)](https://nodejs.org)
7
+
8
+ Official JavaScript/TypeScript SDK for the [ModuleX](https://modulex.dev) AI workflow orchestration platform.
9
+
10
+ - Zero runtime dependencies
11
+ - Full TypeScript support with exported types
12
+ - Dual ESM + CommonJS build
13
+ - SSE streaming for real-time workflow events
14
+ - Automatic retries with exponential backoff
15
+ - 122 API endpoints covered
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install modulex-js
21
+ # or
22
+ pnpm add modulex-js
23
+ # or
24
+ yarn add modulex-js
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ```typescript
30
+ import { Modulex } from 'modulex-js';
31
+
32
+ const client = new Modulex({
33
+ apiKey: 'mx_live_...',
34
+ organizationId: 'your-org-id',
35
+ });
36
+
37
+ // Get current user
38
+ const me = await client.auth.me();
39
+ console.log(me.email);
40
+
41
+ // List workflows
42
+ const { workflows } = await client.workflows.list({ status: 'active' });
43
+ ```
44
+
45
+ ### JavaScript (CommonJS)
46
+
47
+ ```javascript
48
+ const { Modulex } = require('modulex-js');
49
+
50
+ const client = new Modulex({
51
+ apiKey: process.env.MODULEX_API_KEY,
52
+ organizationId: process.env.MODULEX_ORG_ID,
53
+ });
54
+ ```
55
+
56
+ ## Authentication
57
+
58
+ Create an API key from the [ModuleX dashboard](https://app.modulex.dev). API keys use the `mx_live_` prefix.
59
+
60
+ ```typescript
61
+ const client = new Modulex({
62
+ apiKey: process.env.MODULEX_API_KEY,
63
+ });
64
+ ```
65
+
66
+ The `organizationId` can be set at the client level (applied to all requests) or overridden per-request:
67
+
68
+ ```typescript
69
+ // Client-level default
70
+ const client = new Modulex({
71
+ apiKey: 'mx_live_...',
72
+ organizationId: 'default-org-id',
73
+ });
74
+
75
+ // Per-request override
76
+ const workflows = await client.workflows.list({}, {
77
+ organizationId: 'other-org-id',
78
+ });
79
+ ```
80
+
81
+ ## Configuration
82
+
83
+ ```typescript
84
+ const client = new Modulex({
85
+ apiKey: 'mx_live_...', // Required
86
+ organizationId: 'org-uuid', // Default org for all requests
87
+ baseUrl: 'https://api.modulex.dev', // API base URL (default)
88
+ timeout: 30_000, // Request timeout in ms (default: 30000)
89
+ maxRetries: 3, // Retry count for transient errors (default: 3)
90
+ fetch: customFetch, // Custom fetch implementation
91
+ });
92
+ ```
93
+
94
+ ## Resources
95
+
96
+ ### Workflows
97
+
98
+ ```typescript
99
+ // List workflows
100
+ const result = await client.workflows.list({ status: 'active', page: 1, pageSize: 20 });
101
+
102
+ // Auto-paginate all workflows
103
+ for await (const workflow of client.workflows.listAll({ status: 'active' })) {
104
+ console.log(workflow.name);
105
+ }
106
+
107
+ // Get a single workflow
108
+ const workflow = await client.workflows.get('workflow-uuid');
109
+
110
+ // Create a workflow
111
+ const created = await client.workflows.create({
112
+ workflowSchema: { metadata: { name: 'My Workflow', version: '1.0' }, config: {}, state_schema: { fields: {} }, nodes: [], edges: [], entry_point: 'start' },
113
+ name: 'My Workflow',
114
+ status: 'draft',
115
+ });
116
+
117
+ // Update / Delete
118
+ await client.workflows.update('workflow-uuid', { name: 'New Name', status: 'active' });
119
+ await client.workflows.delete('workflow-uuid');
120
+ ```
121
+
122
+ ### Workflow Execution
123
+
124
+ ```typescript
125
+ // Run a workflow
126
+ const run = await client.executions.run({
127
+ workflowId: 'workflow-uuid',
128
+ input: { messages: [{ role: 'user', content: 'Hello' }] },
129
+ stream: true,
130
+ });
131
+
132
+ // Get execution state
133
+ const state = await client.executions.getState(run.thread_id);
134
+
135
+ // Resume after interrupt
136
+ await client.executions.resume({
137
+ workflowId: 'workflow-uuid',
138
+ runId: run.run_id,
139
+ resumeValue: 'user input',
140
+ });
141
+
142
+ // Cancel execution
143
+ await client.executions.cancel(run.run_id, { reason: 'No longer needed' });
144
+ ```
145
+
146
+ ### SSE Streaming
147
+
148
+ ```typescript
149
+ const run = await client.executions.run({
150
+ workflowId: 'workflow-uuid',
151
+ input: { messages: [{ role: 'user', content: 'Hello' }] },
152
+ stream: true,
153
+ });
154
+
155
+ for await (const event of client.executions.listen(run.run_id)) {
156
+ switch (event.event) {
157
+ case 'node_update':
158
+ console.log(`Node ${event.data.node_id}: ${event.data.status}`);
159
+ break;
160
+ case 'done':
161
+ console.log(`Completed in ${event.data.total_execution_time_ms}ms`);
162
+ break;
163
+ case 'error':
164
+ console.error(event.data.error_message);
165
+ break;
166
+ }
167
+ }
168
+ ```
169
+
170
+ ### Credentials
171
+
172
+ ```typescript
173
+ // List credentials
174
+ const creds = await client.credentials.list({ integrationName: 'openai' });
175
+
176
+ // Create a credential
177
+ await client.credentials.create({
178
+ integrationName: 'openai',
179
+ authData: { api_key: 'sk-...' },
180
+ displayName: 'My OpenAI Key',
181
+ });
182
+
183
+ // Test a credential
184
+ const result = await client.credentials.test('credential-uuid');
185
+ console.log(result.is_valid);
186
+ ```
187
+
188
+ ### Knowledge Bases
189
+
190
+ ```typescript
191
+ // Create a knowledge base
192
+ const kb = await client.knowledge.create({
193
+ name: 'Docs',
194
+ embeddingConfig: { provider: 'openai', model: 'text-embedding-3-small', dimension: 1536 },
195
+ });
196
+
197
+ // Upload a document
198
+ const doc = await client.knowledge.uploadDocument(kb.id, {
199
+ file: new Blob([buffer], { type: 'application/pdf' }),
200
+ filename: 'guide.pdf',
201
+ });
202
+
203
+ // Search
204
+ const results = await client.knowledge.search(kb.id, {
205
+ query: 'How does X work?',
206
+ topK: 5,
207
+ });
208
+ ```
209
+
210
+ ### Schedules
211
+
212
+ ```typescript
213
+ // Create a schedule
214
+ const schedule = await client.schedules.create({
215
+ workflowId: 'workflow-uuid',
216
+ name: 'Daily Report',
217
+ scheduleType: 'cron',
218
+ cronExpression: '0 9 * * 1-5',
219
+ timezone: 'America/New_York',
220
+ });
221
+
222
+ // Pause / Resume
223
+ await client.schedules.pause(schedule.id);
224
+ await client.schedules.resume(schedule.id);
225
+ ```
226
+
227
+ ### Templates
228
+
229
+ ```typescript
230
+ const templates = await client.templates.list();
231
+ const template = await client.templates.get('template-uuid');
232
+ const used = await client.templates.use('template-uuid');
233
+ ```
234
+
235
+ ### Deployments
236
+
237
+ ```typescript
238
+ const deployment = await client.deployments.create('workflow-uuid', {
239
+ deploymentNote: 'v2.0 release',
240
+ });
241
+ await client.deployments.activate('workflow-uuid', deployment.id);
242
+ ```
243
+
244
+ ### Composer
245
+
246
+ ```typescript
247
+ const session = await client.composer.chat({
248
+ workflowId: 'workflow-uuid',
249
+ message: 'Add an LLM node that summarizes the input',
250
+ });
251
+
252
+ for await (const event of client.composer.listen(session.composer_chat_id, session.run_id)) {
253
+ console.log(event.event, event.data);
254
+ }
255
+
256
+ await client.composer.save(session.composer_chat_id);
257
+ ```
258
+
259
+ ### Dashboard & Analytics
260
+
261
+ ```typescript
262
+ const logs = await client.dashboard.logs({ limit: 50, category: 'CREDENTIALS' });
263
+ const overview = await client.dashboard.analyticsOverview();
264
+ const users = await client.dashboard.users({ search: 'john' });
265
+ ```
266
+
267
+ ### Subscriptions
268
+
269
+ ```typescript
270
+ const plans = await client.subscriptions.organizationPlans();
271
+ const billing = await client.subscriptions.billing();
272
+ const checkout = await client.subscriptions.checkoutLink({ planId: 'plan-uuid', interval: 'month' });
273
+ ```
274
+
275
+ ### System
276
+
277
+ ```typescript
278
+ const health = await client.system.health();
279
+ const timezones = await client.system.timezones();
280
+ ```
281
+
282
+ ## Error Handling
283
+
284
+ ```typescript
285
+ import {
286
+ Modulex,
287
+ NotFoundError,
288
+ RateLimitError,
289
+ AuthenticationError,
290
+ ValidationError,
291
+ } from 'modulex-js';
292
+
293
+ try {
294
+ const workflow = await client.workflows.get('invalid-id');
295
+ } catch (error) {
296
+ if (error instanceof NotFoundError) {
297
+ console.log('Workflow not found');
298
+ } else if (error instanceof RateLimitError) {
299
+ console.log(`Rate limited. Retry after ${error.retryAfter}s`);
300
+ } else if (error instanceof AuthenticationError) {
301
+ console.log('Invalid API key');
302
+ } else if (error instanceof ValidationError) {
303
+ console.log('Validation error:', error.body);
304
+ }
305
+ }
306
+ ```
307
+
308
+ The SDK automatically retries requests on transient errors (429, 500, 502, 503) with exponential backoff.
309
+
310
+ ## Cancellation
311
+
312
+ Use `AbortController` to cancel any request or stream:
313
+
314
+ ```typescript
315
+ const controller = new AbortController();
316
+
317
+ // Cancel after 10 seconds
318
+ setTimeout(() => controller.abort(), 10_000);
319
+
320
+ for await (const event of client.executions.listen(runId, {
321
+ signal: controller.signal,
322
+ })) {
323
+ console.log(event);
324
+ }
325
+ ```
326
+
327
+ ## TypeScript
328
+
329
+ The SDK is written in TypeScript and exports all types:
330
+
331
+ ```typescript
332
+ import type {
333
+ WorkflowDefinition,
334
+ NodeDefinition,
335
+ WorkflowRunParams,
336
+ WorkflowSSEEvent,
337
+ SSEEvent,
338
+ } from 'modulex-js';
339
+ ```
340
+
341
+ ## Browser Support
342
+
343
+ The SDK works in modern browsers that support `fetch`, `ReadableStream`, and `AbortController`. No Node.js-specific APIs are required for the core SDK.
344
+
345
+ ## Requirements
346
+
347
+ - Node.js 18+ or modern browser
348
+ - TypeScript 5.0+ (for type definitions)
349
+
350
+ ## Documentation
351
+
352
+ Full API documentation is available at [docs.modulex.dev](https://docs.modulex.dev).
353
+
354
+ ## Contributing
355
+
356
+ Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, coding guidelines, and the PR process.
357
+
358
+ ## Security
359
+
360
+ To report security vulnerabilities, please see [SECURITY.md](SECURITY.md). Do **not** use public GitHub issues for security reports.
361
+
362
+ ## License
363
+
364
+ [MIT](LICENSE) © [ModuleX](https://modulex.dev)