xcomponent-ai 0.1.1
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/CONTRIBUTING.md +195 -0
- package/LICENSE +45 -0
- package/PERSISTENCE.md +774 -0
- package/README.md +594 -0
- package/dist/agents.d.ts +81 -0
- package/dist/agents.d.ts.map +1 -0
- package/dist/agents.js +405 -0
- package/dist/agents.js.map +1 -0
- package/dist/api.d.ts +36 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +404 -0
- package/dist/api.js.map +1 -0
- package/dist/cli.d.ts +7 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +437 -0
- package/dist/cli.js.map +1 -0
- package/dist/component-registry.d.ts +190 -0
- package/dist/component-registry.d.ts.map +1 -0
- package/dist/component-registry.js +382 -0
- package/dist/component-registry.js.map +1 -0
- package/dist/fsm-runtime.d.ts +263 -0
- package/dist/fsm-runtime.d.ts.map +1 -0
- package/dist/fsm-runtime.js +1122 -0
- package/dist/fsm-runtime.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/monitoring.d.ts +68 -0
- package/dist/monitoring.d.ts.map +1 -0
- package/dist/monitoring.js +176 -0
- package/dist/monitoring.js.map +1 -0
- package/dist/persistence.d.ts +100 -0
- package/dist/persistence.d.ts.map +1 -0
- package/dist/persistence.js +270 -0
- package/dist/persistence.js.map +1 -0
- package/dist/timer-wheel.d.ts +85 -0
- package/dist/timer-wheel.d.ts.map +1 -0
- package/dist/timer-wheel.js +181 -0
- package/dist/timer-wheel.js.map +1 -0
- package/dist/types.d.ts +404 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +40 -0
- package/dist/types.js.map +1 -0
- package/dist/websockets.d.ts +32 -0
- package/dist/websockets.d.ts.map +1 -0
- package/dist/websockets.js +117 -0
- package/dist/websockets.js.map +1 -0
- package/package.json +103 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* CLI for xcomponent-ai
|
|
5
|
+
* Command-line interface for FSM management and AI agent interactions
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
const commander_1 = require("commander");
|
|
42
|
+
const fs = __importStar(require("fs/promises"));
|
|
43
|
+
const yaml = __importStar(require("yaml"));
|
|
44
|
+
const fsm_runtime_1 = require("./fsm-runtime");
|
|
45
|
+
const agents_1 = require("./agents");
|
|
46
|
+
const monitoring_1 = require("./monitoring");
|
|
47
|
+
const program = new commander_1.Command();
|
|
48
|
+
program
|
|
49
|
+
.name('xcomponent-ai')
|
|
50
|
+
.description('Agentic FSM tool for fintech workflows')
|
|
51
|
+
.version('0.1.0');
|
|
52
|
+
/**
|
|
53
|
+
* Initialize new project
|
|
54
|
+
*/
|
|
55
|
+
program
|
|
56
|
+
.command('init <project-name>')
|
|
57
|
+
.description('Initialize new project with xcomponent-ai framework structure')
|
|
58
|
+
.option('-d, --domain <domain>', 'Domain (fintech, healthcare, ecommerce)', 'fintech')
|
|
59
|
+
.action(async (projectName, options) => {
|
|
60
|
+
try {
|
|
61
|
+
const path = require('path');
|
|
62
|
+
const projectPath = path.join(process.cwd(), projectName);
|
|
63
|
+
console.log(`🚀 Initializing xcomponent-ai project: ${projectName}\n`);
|
|
64
|
+
// Create directory structure
|
|
65
|
+
const dirs = [
|
|
66
|
+
projectPath,
|
|
67
|
+
path.join(projectPath, 'fsm'),
|
|
68
|
+
path.join(projectPath, 'src'),
|
|
69
|
+
path.join(projectPath, 'src/runtime'),
|
|
70
|
+
path.join(projectPath, 'src/api'),
|
|
71
|
+
path.join(projectPath, 'src/ui'),
|
|
72
|
+
path.join(projectPath, 'src/services'),
|
|
73
|
+
path.join(projectPath, 'tests'),
|
|
74
|
+
path.join(projectPath, 'tests/fsm'),
|
|
75
|
+
];
|
|
76
|
+
for (const dir of dirs) {
|
|
77
|
+
await fs.mkdir(dir, { recursive: true });
|
|
78
|
+
}
|
|
79
|
+
// Create README
|
|
80
|
+
const readme = `# ${projectName}
|
|
81
|
+
|
|
82
|
+
Built with [xcomponent-ai](https://github.com/fredericcarre/mayele-ai) framework.
|
|
83
|
+
|
|
84
|
+
## 🏗️ Structure
|
|
85
|
+
|
|
86
|
+
\`\`\`
|
|
87
|
+
${projectName}/
|
|
88
|
+
├── fsm/ # 🔒 SANCTUARIZED BUSINESS LOGIC
|
|
89
|
+
│ └── *.yaml # FSM definitions (immutable)
|
|
90
|
+
├── src/
|
|
91
|
+
│ ├── runtime/ # FSM runtime initialization
|
|
92
|
+
│ ├── api/ # HTTP → FSM event wrappers
|
|
93
|
+
│ ├── ui/ # Frontend components
|
|
94
|
+
│ └── services/ # External integrations
|
|
95
|
+
└── tests/fsm/ # FSM simulation tests
|
|
96
|
+
\`\`\`
|
|
97
|
+
|
|
98
|
+
## 🚀 Getting Started
|
|
99
|
+
|
|
100
|
+
1. Define your business logic in \`fsm/*.yaml\`
|
|
101
|
+
2. Initialize runtime in \`src/runtime/index.ts\`
|
|
102
|
+
3. Create API routes in \`src/api/\`
|
|
103
|
+
4. Build UI in \`src/ui/\`
|
|
104
|
+
|
|
105
|
+
## 📚 Documentation
|
|
106
|
+
|
|
107
|
+
- [xcomponent-ai Framework Guide](https://github.com/fredericcarre/mayele-ai/blob/main/LLM_FRAMEWORK_GUIDE.md)
|
|
108
|
+
- [Full Project Example](https://github.com/fredericcarre/mayele-ai/blob/main/examples/full-project-structure.md)
|
|
109
|
+
|
|
110
|
+
## 🔒 Sanctuarization Principle
|
|
111
|
+
|
|
112
|
+
Business logic lives in \`fsm/\` directory as YAML files. These are:
|
|
113
|
+
- Immutable (changes = Git commits)
|
|
114
|
+
- Version controlled
|
|
115
|
+
- Auditable by non-technical stakeholders
|
|
116
|
+
- Separate from technical implementation
|
|
117
|
+
`;
|
|
118
|
+
await fs.writeFile(path.join(projectPath, 'README.md'), readme);
|
|
119
|
+
// Create example FSM
|
|
120
|
+
const exampleFSM = `name: ${projectName.charAt(0).toUpperCase() + projectName.slice(1)}Component
|
|
121
|
+
version: 1.0.0
|
|
122
|
+
metadata:
|
|
123
|
+
domain: ${options.domain}
|
|
124
|
+
description: Main business workflow
|
|
125
|
+
compliance: []
|
|
126
|
+
|
|
127
|
+
stateMachines:
|
|
128
|
+
- name: MainWorkflow
|
|
129
|
+
initialState: Start
|
|
130
|
+
metadata:
|
|
131
|
+
description: Primary business flow
|
|
132
|
+
states:
|
|
133
|
+
- name: Start
|
|
134
|
+
type: entry
|
|
135
|
+
metadata:
|
|
136
|
+
description: Initial state
|
|
137
|
+
- name: Processing
|
|
138
|
+
type: regular
|
|
139
|
+
- name: Complete
|
|
140
|
+
type: final
|
|
141
|
+
- name: Failed
|
|
142
|
+
type: error
|
|
143
|
+
transitions:
|
|
144
|
+
- from: Start
|
|
145
|
+
to: Processing
|
|
146
|
+
event: BEGIN
|
|
147
|
+
type: triggerable
|
|
148
|
+
guards:
|
|
149
|
+
- keys: [userId]
|
|
150
|
+
- from: Processing
|
|
151
|
+
to: Complete
|
|
152
|
+
event: SUCCESS
|
|
153
|
+
type: regular
|
|
154
|
+
- from: Processing
|
|
155
|
+
to: Failed
|
|
156
|
+
event: ERROR
|
|
157
|
+
type: regular
|
|
158
|
+
`;
|
|
159
|
+
await fs.writeFile(path.join(projectPath, 'fsm', 'main-workflow.yaml'), exampleFSM);
|
|
160
|
+
// Create runtime template
|
|
161
|
+
const runtimeTemplate = `import { FSMRuntime } from 'xcomponent-ai';
|
|
162
|
+
import * as yaml from 'yaml';
|
|
163
|
+
import * as fs from 'fs';
|
|
164
|
+
|
|
165
|
+
// Load FSM from sanctuarized directory
|
|
166
|
+
const mainWorkflowFSM = yaml.parse(
|
|
167
|
+
fs.readFileSync('./fsm/main-workflow.yaml', 'utf-8')
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
export const mainRuntime = new FSMRuntime(mainWorkflowFSM);
|
|
171
|
+
|
|
172
|
+
// Setup monitoring
|
|
173
|
+
mainRuntime.on('state_change', (data) => {
|
|
174
|
+
console.log(\`[\${data.instanceId}] \${data.previousState} → \${data.newState}\`);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
mainRuntime.on('instance_error', (data) => {
|
|
178
|
+
console.error(\`[ERROR] \${data.instanceId}: \${data.error}\`);
|
|
179
|
+
});
|
|
180
|
+
`;
|
|
181
|
+
await fs.writeFile(path.join(projectPath, 'src/runtime/index.ts'), runtimeTemplate);
|
|
182
|
+
// Create package.json
|
|
183
|
+
const packageJson = {
|
|
184
|
+
name: projectName,
|
|
185
|
+
version: '1.0.0',
|
|
186
|
+
description: `${projectName} - built with xcomponent-ai`,
|
|
187
|
+
main: 'src/index.ts',
|
|
188
|
+
scripts: {
|
|
189
|
+
dev: 'ts-node src/api/server.ts',
|
|
190
|
+
test: 'jest',
|
|
191
|
+
build: 'tsc',
|
|
192
|
+
},
|
|
193
|
+
dependencies: {
|
|
194
|
+
'xcomponent-ai': '^0.1.0',
|
|
195
|
+
express: '^4.21.2',
|
|
196
|
+
'socket.io': '^4.8.1',
|
|
197
|
+
yaml: '^2.6.1',
|
|
198
|
+
},
|
|
199
|
+
devDependencies: {
|
|
200
|
+
'@types/node': '^22.10.5',
|
|
201
|
+
typescript: '^5.7.3',
|
|
202
|
+
'ts-node': '^10.9.2',
|
|
203
|
+
jest: '^29.7.0',
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
await fs.writeFile(path.join(projectPath, 'package.json'), JSON.stringify(packageJson, null, 2));
|
|
207
|
+
// Create .gitignore
|
|
208
|
+
const gitignore = `node_modules/
|
|
209
|
+
dist/
|
|
210
|
+
coverage/
|
|
211
|
+
.env
|
|
212
|
+
*.log
|
|
213
|
+
`;
|
|
214
|
+
await fs.writeFile(path.join(projectPath, '.gitignore'), gitignore);
|
|
215
|
+
console.log('✓ Project structure created');
|
|
216
|
+
console.log('✓ Example FSM: fsm/main-workflow.yaml');
|
|
217
|
+
console.log('✓ Runtime template: src/runtime/index.ts');
|
|
218
|
+
console.log('✓ README.md created\n');
|
|
219
|
+
console.log('📝 Next steps:');
|
|
220
|
+
console.log(` cd ${projectName}`);
|
|
221
|
+
console.log(' npm install');
|
|
222
|
+
console.log(' # Edit fsm/main-workflow.yaml to define your business logic');
|
|
223
|
+
console.log(' # Build API/UI that connects to FSM runtime\n');
|
|
224
|
+
console.log('📚 Resources:');
|
|
225
|
+
console.log(' LLM Guide: https://github.com/fredericcarre/mayele-ai/blob/main/LLM_FRAMEWORK_GUIDE.md');
|
|
226
|
+
console.log(' Example: https://github.com/fredericcarre/mayele-ai/blob/main/examples/full-project-structure.md');
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
console.error(`✗ Error: ${error.message}`);
|
|
230
|
+
process.exit(1);
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
/**
|
|
234
|
+
* Load component
|
|
235
|
+
*/
|
|
236
|
+
program
|
|
237
|
+
.command('load <file>')
|
|
238
|
+
.description('Load FSM component from YAML file')
|
|
239
|
+
.action(async (file) => {
|
|
240
|
+
try {
|
|
241
|
+
const content = await fs.readFile(file, 'utf-8');
|
|
242
|
+
const component = yaml.parse(content);
|
|
243
|
+
console.log(`✓ Loaded component: ${component.name}`);
|
|
244
|
+
console.log(` Machines: ${component.stateMachines.length}`);
|
|
245
|
+
component.stateMachines.forEach(machine => {
|
|
246
|
+
console.log(` - ${machine.name} (${machine.states.length} states, ${machine.transitions.length} transitions)`);
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
console.error(`✗ Error: ${error.message}`);
|
|
251
|
+
process.exit(1);
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
/**
|
|
255
|
+
* Run FSM instance
|
|
256
|
+
*/
|
|
257
|
+
program
|
|
258
|
+
.command('run <file> <machine>')
|
|
259
|
+
.description('Create and run FSM instance')
|
|
260
|
+
.option('-c, --context <json>', 'Initial context as JSON')
|
|
261
|
+
.option('-e, --events <json>', 'Events to send as JSON array')
|
|
262
|
+
.action(async (file, machine, options) => {
|
|
263
|
+
try {
|
|
264
|
+
const content = await fs.readFile(file, 'utf-8');
|
|
265
|
+
const component = yaml.parse(content);
|
|
266
|
+
const runtime = new fsm_runtime_1.FSMRuntime(component);
|
|
267
|
+
// Setup logging
|
|
268
|
+
runtime.on('state_change', (data) => {
|
|
269
|
+
console.log(` ${data.previousState} → ${data.newState} (event: ${data.event.type})`);
|
|
270
|
+
monitoring_1.monitoringService.logTransition({
|
|
271
|
+
instanceId: data.instanceId,
|
|
272
|
+
from: data.previousState,
|
|
273
|
+
to: data.newState,
|
|
274
|
+
event: data.event.type,
|
|
275
|
+
time: data.timestamp,
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
runtime.on('instance_error', (data) => {
|
|
279
|
+
console.error(` ✗ Error: ${data.error}`);
|
|
280
|
+
});
|
|
281
|
+
runtime.on('guard_failed', (data) => {
|
|
282
|
+
console.log(` ⚠ Guard failed for event: ${data.event.type}`);
|
|
283
|
+
});
|
|
284
|
+
const context = options.context ? JSON.parse(options.context) : {};
|
|
285
|
+
const instanceId = runtime.createInstance(machine, context);
|
|
286
|
+
console.log(`✓ Created instance: ${instanceId}`);
|
|
287
|
+
if (options.events) {
|
|
288
|
+
const events = JSON.parse(options.events);
|
|
289
|
+
for (const event of events) {
|
|
290
|
+
await runtime.sendEvent(instanceId, event);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
const instance = runtime.getInstance(instanceId);
|
|
294
|
+
if (instance) {
|
|
295
|
+
console.log(`\n✓ Final state: ${instance.currentState}`);
|
|
296
|
+
console.log(` Status: ${instance.status}`);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
console.error(`✗ Error: ${error.message}`);
|
|
301
|
+
process.exit(1);
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
/**
|
|
305
|
+
* Simulate FSM path
|
|
306
|
+
*/
|
|
307
|
+
program
|
|
308
|
+
.command('simulate <file> <machine>')
|
|
309
|
+
.description('Simulate FSM execution path')
|
|
310
|
+
.option('-e, --events <json>', 'Events to simulate as JSON array')
|
|
311
|
+
.action(async (file, machine, options) => {
|
|
312
|
+
try {
|
|
313
|
+
const content = await fs.readFile(file, 'utf-8');
|
|
314
|
+
const component = yaml.parse(content);
|
|
315
|
+
const runtime = new fsm_runtime_1.FSMRuntime(component);
|
|
316
|
+
const events = options.events ? JSON.parse(options.events) : [];
|
|
317
|
+
const result = runtime.simulatePath(machine, events);
|
|
318
|
+
if (result.success) {
|
|
319
|
+
console.log(`✓ Simulation successful`);
|
|
320
|
+
console.log(` Path: ${result.path.join(' → ')}`);
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
console.error(`✗ Simulation failed: ${result.error}`);
|
|
324
|
+
console.log(` Path: ${result.path.join(' → ')}`);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
catch (error) {
|
|
328
|
+
console.error(`✗ Error: ${error.message}`);
|
|
329
|
+
process.exit(1);
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
/**
|
|
333
|
+
* Create FSM with AI
|
|
334
|
+
*/
|
|
335
|
+
program
|
|
336
|
+
.command('ai-create <description>')
|
|
337
|
+
.description('Create FSM using AI from natural language description')
|
|
338
|
+
.option('-o, --output <file>', 'Output file for generated YAML')
|
|
339
|
+
.action(async (description, options) => {
|
|
340
|
+
try {
|
|
341
|
+
if (!process.env.OPENAI_API_KEY) {
|
|
342
|
+
throw new Error('OPENAI_API_KEY environment variable not set');
|
|
343
|
+
}
|
|
344
|
+
const supervisor = new agents_1.SupervisorAgent();
|
|
345
|
+
console.log('🤖 Creating FSM with AI...');
|
|
346
|
+
const result = await supervisor.getFSMAgent().createFSM(description);
|
|
347
|
+
if (result.success) {
|
|
348
|
+
console.log('✓ FSM created successfully\n');
|
|
349
|
+
console.log(result.data.yaml);
|
|
350
|
+
if (result.suggestions && result.suggestions.length > 0) {
|
|
351
|
+
console.log('\n💡 Suggestions:');
|
|
352
|
+
result.suggestions.forEach((s) => console.log(` - ${s}`));
|
|
353
|
+
}
|
|
354
|
+
if (options.output) {
|
|
355
|
+
await fs.writeFile(options.output, result.data.yaml);
|
|
356
|
+
console.log(`\n✓ Saved to: ${options.output}`);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
console.error(`✗ Error: ${result.error}`);
|
|
361
|
+
process.exit(1);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
catch (error) {
|
|
365
|
+
console.error(`✗ Error: ${error.message}`);
|
|
366
|
+
process.exit(1);
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
/**
|
|
370
|
+
* Analyze logs with AI
|
|
371
|
+
*/
|
|
372
|
+
program
|
|
373
|
+
.command('ai-analyze <component>')
|
|
374
|
+
.description('Analyze FSM logs with AI insights')
|
|
375
|
+
.action(async (component) => {
|
|
376
|
+
try {
|
|
377
|
+
if (!process.env.OPENAI_API_KEY) {
|
|
378
|
+
throw new Error('OPENAI_API_KEY environment variable not set');
|
|
379
|
+
}
|
|
380
|
+
const supervisor = new agents_1.SupervisorAgent();
|
|
381
|
+
console.log('🤖 Analyzing logs with AI...\n');
|
|
382
|
+
const result = await supervisor.getMonitoringAgent().analyzeLogs(component);
|
|
383
|
+
if (result.success) {
|
|
384
|
+
console.log('📊 Summary:');
|
|
385
|
+
console.log(result.data.summary);
|
|
386
|
+
console.log('\n🧠 AI Analysis:');
|
|
387
|
+
console.log(result.data.llmAnalysis);
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
console.error(`✗ Error: ${result.error}`);
|
|
391
|
+
process.exit(1);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
catch (error) {
|
|
395
|
+
console.error(`✗ Error: ${error.message}`);
|
|
396
|
+
process.exit(1);
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
/**
|
|
400
|
+
* Generate UI code
|
|
401
|
+
*/
|
|
402
|
+
program
|
|
403
|
+
.command('generate-ui <file>')
|
|
404
|
+
.description('Generate UI code for FSM')
|
|
405
|
+
.option('-t, --type <type>', 'UI type: api or react', 'api')
|
|
406
|
+
.option('-o, --output <file>', 'Output file')
|
|
407
|
+
.action(async (file, options) => {
|
|
408
|
+
try {
|
|
409
|
+
if (!process.env.OPENAI_API_KEY) {
|
|
410
|
+
throw new Error('OPENAI_API_KEY environment variable not set');
|
|
411
|
+
}
|
|
412
|
+
const content = await fs.readFile(file, 'utf-8');
|
|
413
|
+
const component = yaml.parse(content);
|
|
414
|
+
const supervisor = new agents_1.SupervisorAgent();
|
|
415
|
+
console.log(`🤖 Generating ${options.type} code...\n`);
|
|
416
|
+
const result = options.type === 'api'
|
|
417
|
+
? await supervisor.getUIAgent().generateAPIRoutes(component)
|
|
418
|
+
: await supervisor.getUIAgent().generateReactUI(component);
|
|
419
|
+
if (result.success) {
|
|
420
|
+
console.log(result.data.code);
|
|
421
|
+
if (options.output) {
|
|
422
|
+
await fs.writeFile(options.output, result.data.code);
|
|
423
|
+
console.log(`\n✓ Saved to: ${options.output}`);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
else {
|
|
427
|
+
console.error(`✗ Error: ${result.error}`);
|
|
428
|
+
process.exit(1);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
catch (error) {
|
|
432
|
+
console.error(`✗ Error: ${error.message}`);
|
|
433
|
+
process.exit(1);
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
program.parse();
|
|
437
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;AACA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,yCAAoC;AACpC,gDAAkC;AAClC,2CAA6B;AAC7B,+CAA2C;AAC3C,qCAA2C;AAC3C,6CAAiD;AAGjD,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,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,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component Registry for Cross-Component Communication
|
|
3
|
+
*
|
|
4
|
+
* Manages multiple FSMRuntimes (components) and enables communication
|
|
5
|
+
* between them, reproducing XComponent's cross-component messaging pattern.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Register/unregister components
|
|
9
|
+
* - Route events between components
|
|
10
|
+
* - Broadcast across components
|
|
11
|
+
* - Property-based routing across component boundaries
|
|
12
|
+
* - Instance lookup across all components
|
|
13
|
+
*/
|
|
14
|
+
import { EventEmitter } from 'events';
|
|
15
|
+
import { FSMRuntime } from './fsm-runtime';
|
|
16
|
+
import { Component, FSMEvent, FSMInstance } from './types';
|
|
17
|
+
export interface ComponentInfo {
|
|
18
|
+
name: string;
|
|
19
|
+
runtime: FSMRuntime;
|
|
20
|
+
version: string;
|
|
21
|
+
machineCount: number;
|
|
22
|
+
instanceCount: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* ComponentRegistry manages multiple components and enables cross-component communication
|
|
26
|
+
*/
|
|
27
|
+
export declare class ComponentRegistry extends EventEmitter {
|
|
28
|
+
private runtimes;
|
|
29
|
+
private components;
|
|
30
|
+
constructor();
|
|
31
|
+
/**
|
|
32
|
+
* Register a component with its runtime
|
|
33
|
+
*
|
|
34
|
+
* @param component Component definition
|
|
35
|
+
* @param runtime FSM runtime instance
|
|
36
|
+
*/
|
|
37
|
+
registerComponent(component: Component, runtime: FSMRuntime): void;
|
|
38
|
+
/**
|
|
39
|
+
* Unregister a component
|
|
40
|
+
*
|
|
41
|
+
* @param componentName Component name
|
|
42
|
+
*/
|
|
43
|
+
unregisterComponent(componentName: string): void;
|
|
44
|
+
/**
|
|
45
|
+
* Get runtime for a component
|
|
46
|
+
*
|
|
47
|
+
* @param componentName Component name
|
|
48
|
+
* @returns FSMRuntime or undefined
|
|
49
|
+
*/
|
|
50
|
+
getRuntime(componentName: string): FSMRuntime | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Get component definition
|
|
53
|
+
*
|
|
54
|
+
* @param componentName Component name
|
|
55
|
+
* @returns Component or undefined
|
|
56
|
+
*/
|
|
57
|
+
getComponent(componentName: string): Component | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Check if component is registered
|
|
60
|
+
*
|
|
61
|
+
* @param componentName Component name
|
|
62
|
+
* @returns true if registered
|
|
63
|
+
*/
|
|
64
|
+
hasComponent(componentName: string): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Get all registered component names
|
|
67
|
+
*
|
|
68
|
+
* @returns Array of component names
|
|
69
|
+
*/
|
|
70
|
+
getComponentNames(): string[];
|
|
71
|
+
/**
|
|
72
|
+
* Get component information
|
|
73
|
+
*
|
|
74
|
+
* @param componentName Component name
|
|
75
|
+
* @returns Component info or undefined
|
|
76
|
+
*/
|
|
77
|
+
getComponentInfo(componentName: string): ComponentInfo | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* Get all component information
|
|
80
|
+
*
|
|
81
|
+
* @returns Array of component info
|
|
82
|
+
*/
|
|
83
|
+
getAllComponentInfo(): ComponentInfo[];
|
|
84
|
+
/**
|
|
85
|
+
* Send event to instance in any component
|
|
86
|
+
*
|
|
87
|
+
* @param componentName Target component name
|
|
88
|
+
* @param instanceId Instance ID
|
|
89
|
+
* @param event Event to send
|
|
90
|
+
*/
|
|
91
|
+
sendEventToComponent(componentName: string, instanceId: string, event: FSMEvent): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Broadcast event to instances in a specific component
|
|
94
|
+
*
|
|
95
|
+
* @param componentName Target component name
|
|
96
|
+
* @param machineName Target machine name
|
|
97
|
+
* @param currentState Current state filter
|
|
98
|
+
* @param event Event to broadcast
|
|
99
|
+
* @returns Number of instances processed
|
|
100
|
+
*/
|
|
101
|
+
broadcastToComponent(componentName: string, machineName: string, currentState: string, event: FSMEvent): Promise<number>;
|
|
102
|
+
/**
|
|
103
|
+
* Broadcast event to all components
|
|
104
|
+
*
|
|
105
|
+
* Useful for system-wide notifications (e.g., shutdown, maintenance mode)
|
|
106
|
+
*
|
|
107
|
+
* @param machineName Target machine name
|
|
108
|
+
* @param currentState Current state filter
|
|
109
|
+
* @param event Event to broadcast
|
|
110
|
+
* @returns Total number of instances processed across all components
|
|
111
|
+
*/
|
|
112
|
+
broadcastToAll(machineName: string, currentState: string, event: FSMEvent): Promise<number>;
|
|
113
|
+
/**
|
|
114
|
+
* Create instance in a specific component
|
|
115
|
+
*
|
|
116
|
+
* @param componentName Target component name
|
|
117
|
+
* @param machineName Machine name
|
|
118
|
+
* @param initialContext Initial context
|
|
119
|
+
* @returns Instance ID
|
|
120
|
+
*/
|
|
121
|
+
createInstanceInComponent(componentName: string, machineName: string, initialContext: Record<string, any>): string;
|
|
122
|
+
/**
|
|
123
|
+
* Find instance by ID across all components
|
|
124
|
+
*
|
|
125
|
+
* @param instanceId Instance ID
|
|
126
|
+
* @returns Instance and component name, or undefined
|
|
127
|
+
*/
|
|
128
|
+
findInstance(instanceId: string): {
|
|
129
|
+
instance: FSMInstance;
|
|
130
|
+
componentName: string;
|
|
131
|
+
} | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* Get all instances across all components
|
|
134
|
+
*
|
|
135
|
+
* @returns Array of instances with component name
|
|
136
|
+
*/
|
|
137
|
+
getAllInstances(): Array<{
|
|
138
|
+
instance: FSMInstance;
|
|
139
|
+
componentName: string;
|
|
140
|
+
}>;
|
|
141
|
+
/**
|
|
142
|
+
* Get statistics across all components
|
|
143
|
+
*
|
|
144
|
+
* @returns Registry statistics
|
|
145
|
+
*/
|
|
146
|
+
getStats(): {
|
|
147
|
+
componentCount: number;
|
|
148
|
+
totalInstances: number;
|
|
149
|
+
totalMachines: number;
|
|
150
|
+
components: Array<{
|
|
151
|
+
name: string;
|
|
152
|
+
instances: number;
|
|
153
|
+
machines: number;
|
|
154
|
+
}>;
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* Trace event causality across all components
|
|
158
|
+
*
|
|
159
|
+
* Follows event chains across component boundaries to show
|
|
160
|
+
* complete system-wide workflows
|
|
161
|
+
*
|
|
162
|
+
* @param eventId Starting event ID
|
|
163
|
+
* @returns Array of persisted events showing full causality chain
|
|
164
|
+
*/
|
|
165
|
+
traceEventAcrossComponents(eventId: string): Promise<import('./types').PersistedEvent[]>;
|
|
166
|
+
/**
|
|
167
|
+
* Get all persisted events across all components
|
|
168
|
+
*
|
|
169
|
+
* Useful for system-wide analysis, debugging, and monitoring
|
|
170
|
+
*
|
|
171
|
+
* @returns Array of all persisted events from all components
|
|
172
|
+
*/
|
|
173
|
+
getAllPersistedEvents(): Promise<import('./types').PersistedEvent[]>;
|
|
174
|
+
/**
|
|
175
|
+
* Get persisted events for a specific instance across components
|
|
176
|
+
*
|
|
177
|
+
* @param instanceId Instance ID to query
|
|
178
|
+
* @returns Array of persisted events for the instance
|
|
179
|
+
*/
|
|
180
|
+
getInstanceHistory(instanceId: string): Promise<import('./types').PersistedEvent[]>;
|
|
181
|
+
/**
|
|
182
|
+
* Forward runtime events to registry
|
|
183
|
+
*/
|
|
184
|
+
private forwardRuntimeEvents;
|
|
185
|
+
/**
|
|
186
|
+
* Dispose all components and cleanup
|
|
187
|
+
*/
|
|
188
|
+
dispose(): void;
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=component-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-registry.d.ts","sourceRoot":"","sources":["../src/component-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,SAAS,CA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