@auto-engineer/cli 0.8.1 → 0.8.3
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/CHANGELOG.md +16 -0
- package/dist/src/server/command-registry.d.ts +32 -0
- package/dist/src/server/command-registry.d.ts.map +1 -0
- package/dist/src/server/command-registry.js +68 -0
- package/dist/src/server/command-registry.js.map +1 -0
- package/dist/src/server/event-processor.d.ts +29 -0
- package/dist/src/server/event-processor.d.ts.map +1 -0
- package/dist/src/server/event-processor.js +165 -0
- package/dist/src/server/event-processor.js.map +1 -0
- package/dist/src/server/http-routes.d.ts +26 -0
- package/dist/src/server/http-routes.d.ts.map +1 -0
- package/dist/src/server/http-routes.js +126 -0
- package/dist/src/server/http-routes.js.map +1 -0
- package/dist/src/server/server.d.ts +2 -19
- package/dist/src/server/server.d.ts.map +1 -1
- package/dist/src/server/server.js +25 -321
- package/dist/src/server/server.js.map +1 -1
- package/dist/src/server/websocket-handler.d.ts +5 -0
- package/dist/src/server/websocket-handler.d.ts.map +1 -0
- package/dist/src/server/websocket-handler.js +40 -0
- package/dist/src/server/websocket-handler.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @auto-engineer/cli
|
|
2
2
|
|
|
3
|
+
## 0.8.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3aff24e: bump version up
|
|
8
|
+
- version bump
|
|
9
|
+
- Updated dependencies [3aff24e]
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
- @auto-engineer/message-bus@0.8.3
|
|
12
|
+
|
|
13
|
+
## 0.8.2
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- @auto-engineer/message-bus@0.8.2
|
|
18
|
+
|
|
3
19
|
## 0.8.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { MessageBus } from '@auto-engineer/message-bus';
|
|
2
|
+
import type { FoldRegistration } from '../dsl/types';
|
|
3
|
+
import type { StateManager, FoldFunction } from './state-manager';
|
|
4
|
+
export declare class CommandRegistry {
|
|
5
|
+
private messageBus;
|
|
6
|
+
private stateManager;
|
|
7
|
+
private commandHandlerNames;
|
|
8
|
+
private commandMetadata;
|
|
9
|
+
private foldRegistry;
|
|
10
|
+
constructor(messageBus: MessageBus, stateManager: StateManager<Record<string, unknown>>);
|
|
11
|
+
registerCommandHandlers(handlers: unknown[]): void;
|
|
12
|
+
private processCommandHandler;
|
|
13
|
+
private extractUnifiedHandlerMetadata;
|
|
14
|
+
setCommandMetadata(commandName: string, metadata: {
|
|
15
|
+
alias: string;
|
|
16
|
+
description: string;
|
|
17
|
+
package: string;
|
|
18
|
+
version?: string;
|
|
19
|
+
category?: string;
|
|
20
|
+
}): void;
|
|
21
|
+
registerFold(registration: FoldRegistration): void;
|
|
22
|
+
getCommandHandlerNames(): string[];
|
|
23
|
+
getCommandMetadata(): Map<string, {
|
|
24
|
+
alias: string;
|
|
25
|
+
description: string;
|
|
26
|
+
package: string;
|
|
27
|
+
version?: string;
|
|
28
|
+
category?: string;
|
|
29
|
+
}>;
|
|
30
|
+
getFoldRegistry(): Map<string, FoldFunction<Record<string, unknown>>>;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=command-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-registry.d.ts","sourceRoot":"","sources":["../../../src/server/command-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,4BAA4B,CAAC;AACpG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAKlE,qBAAa,eAAe;IASxB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,YAAY;IATtB,OAAO,CAAC,mBAAmB,CAAgB;IAC3C,OAAO,CAAC,eAAe,CAGT;IACd,OAAO,CAAC,YAAY,CAAiE;gBAG3E,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAG7D,uBAAuB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI;IAWlD,OAAO,CAAC,qBAAqB;IAmB7B,OAAO,CAAC,6BAA6B;IAerC,kBAAkB,CAChB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GACrG,IAAI;IAKP,YAAY,CAAC,YAAY,EAAE,gBAAgB,GAAG,IAAI;IAOlD,sBAAsB,IAAI,MAAM,EAAE;IAIlC,kBAAkB,IAAI,GAAG,CACvB,MAAM,EACN;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAC7F;IAID,eAAe,IAAI,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAGtE"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import createDebug from 'debug';
|
|
2
|
+
const debugBus = createDebug('auto-engineer:server:bus');
|
|
3
|
+
export class CommandRegistry {
|
|
4
|
+
constructor(messageBus, stateManager) {
|
|
5
|
+
this.messageBus = messageBus;
|
|
6
|
+
this.stateManager = stateManager;
|
|
7
|
+
this.commandHandlerNames = [];
|
|
8
|
+
this.commandMetadata = new Map();
|
|
9
|
+
this.foldRegistry = new Map();
|
|
10
|
+
}
|
|
11
|
+
registerCommandHandlers(handlers) {
|
|
12
|
+
debugBus('registerCommandHandlers called with', handlers.length, 'handlers');
|
|
13
|
+
debugBus('Current commandHandlerNames:', this.commandHandlerNames);
|
|
14
|
+
for (const handler of handlers) {
|
|
15
|
+
this.processCommandHandler(handler);
|
|
16
|
+
}
|
|
17
|
+
debugBus('After registration, commandHandlerNames:', this.commandHandlerNames);
|
|
18
|
+
}
|
|
19
|
+
processCommandHandler(handler) {
|
|
20
|
+
if (handler !== null &&
|
|
21
|
+
handler !== undefined &&
|
|
22
|
+
typeof handler === 'object' &&
|
|
23
|
+
'name' in handler &&
|
|
24
|
+
'handle' in handler) {
|
|
25
|
+
const cmdHandler = handler;
|
|
26
|
+
debugBus('Registering command handler:', cmdHandler.name);
|
|
27
|
+
this.messageBus.registerCommandHandler(cmdHandler);
|
|
28
|
+
this.commandHandlerNames.push(cmdHandler.name);
|
|
29
|
+
this.extractUnifiedHandlerMetadata(handler, cmdHandler.name);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
debugBus('Skipping invalid handler:', handler);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
extractUnifiedHandlerMetadata(handler, commandName) {
|
|
36
|
+
if (typeof handler === 'object' && handler !== null && 'alias' in handler && 'description' in handler) {
|
|
37
|
+
const unifiedHandler = handler;
|
|
38
|
+
debugBus('Extracting metadata from UnifiedCommandHandler:', commandName);
|
|
39
|
+
this.setCommandMetadata(commandName, {
|
|
40
|
+
alias: unifiedHandler.alias,
|
|
41
|
+
description: unifiedHandler.description,
|
|
42
|
+
package: unifiedHandler.package?.name ?? 'unknown',
|
|
43
|
+
version: unifiedHandler.package?.version,
|
|
44
|
+
category: unifiedHandler.category,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
setCommandMetadata(commandName, metadata) {
|
|
49
|
+
this.commandMetadata.set(commandName, metadata);
|
|
50
|
+
debugBus('Set metadata for command:', commandName, metadata);
|
|
51
|
+
}
|
|
52
|
+
registerFold(registration) {
|
|
53
|
+
debugBus('Registering fold for:', registration.eventType);
|
|
54
|
+
const foldFn = registration.reducer;
|
|
55
|
+
this.stateManager.registerFold(registration.eventType, foldFn);
|
|
56
|
+
this.foldRegistry.set(registration.eventType, foldFn);
|
|
57
|
+
}
|
|
58
|
+
getCommandHandlerNames() {
|
|
59
|
+
return this.commandHandlerNames;
|
|
60
|
+
}
|
|
61
|
+
getCommandMetadata() {
|
|
62
|
+
return this.commandMetadata;
|
|
63
|
+
}
|
|
64
|
+
getFoldRegistry() {
|
|
65
|
+
return this.foldRegistry;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=command-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-registry.js","sourceRoot":"","sources":["../../../src/server/command-registry.ts"],"names":[],"mappings":"AAGA,OAAO,WAAW,MAAM,OAAO,CAAC;AAEhC,MAAM,QAAQ,GAAG,WAAW,CAAC,0BAA0B,CAAC,CAAC;AAEzD,MAAM,OAAO,eAAe;IAQ1B,YACU,UAAsB,EACtB,YAAmD;QADnD,eAAU,GAAV,UAAU,CAAY;QACtB,iBAAY,GAAZ,YAAY,CAAuC;QATrD,wBAAmB,GAAa,EAAE,CAAC;QACnC,oBAAe,GAGnB,IAAI,GAAG,EAAE,CAAC;QACN,iBAAY,GAAuD,IAAI,GAAG,EAAE,CAAC;IAKlF,CAAC;IAEJ,uBAAuB,CAAC,QAAmB;QACzC,QAAQ,CAAC,qCAAqC,EAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAC7E,QAAQ,CAAC,8BAA8B,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAEnE,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,IAAI,CAAC,qBAAqB,CAAC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,CAAC;QACL,CAAC;IACH,CAAC;IAED,kBAAkB,CAChB,WAAmB,EACnB,QAAsG;QAEtG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QAChD,QAAQ,CAAC,2BAA2B,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;IAC/D,CAAC;IAED,YAAY,CAAC,YAA8B;QACzC,QAAQ,CAAC,uBAAuB,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;QAC1D,MAAM,MAAM,GAAG,YAAY,CAAC,OAAgD,CAAC;QAC7E,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAC/D,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;IAED,sBAAsB;QACpB,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;IAED,kBAAkB;QAIhB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED,eAAe;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;CACF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { MessageBus, Event } from '@auto-engineer/message-bus';
|
|
2
|
+
import type { StateManager } from './state-manager';
|
|
3
|
+
import type { EventRegistration } from '../dsl/types';
|
|
4
|
+
export declare class EventProcessor {
|
|
5
|
+
private messageBus;
|
|
6
|
+
private stateManager;
|
|
7
|
+
private onEventBroadcast;
|
|
8
|
+
private eventHandlers;
|
|
9
|
+
private eventHistory;
|
|
10
|
+
private readonly maxEventHistory;
|
|
11
|
+
constructor(messageBus: MessageBus, stateManager: StateManager<Record<string, unknown>>, onEventBroadcast: (event: Event) => void);
|
|
12
|
+
setupGlobalEventListener(): void;
|
|
13
|
+
registerEventHandler(registration: EventRegistration): void;
|
|
14
|
+
private processHandlerResult;
|
|
15
|
+
private processCommandArray;
|
|
16
|
+
private processActionOrCommand;
|
|
17
|
+
private processDispatchAction;
|
|
18
|
+
private handleSingleDispatch;
|
|
19
|
+
private handleParallelDispatch;
|
|
20
|
+
private handleSequentialDispatch;
|
|
21
|
+
private handleCustomDispatch;
|
|
22
|
+
getEventHandlers(): Map<string, Array<(event: Event) => void>>;
|
|
23
|
+
getEventHistory(): Array<{
|
|
24
|
+
event: Event;
|
|
25
|
+
timestamp: string;
|
|
26
|
+
}>;
|
|
27
|
+
clearEventHistory(): void;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=event-processor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-processor.d.ts","sourceRoot":"","sources":["../../../src/server/event-processor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,KAAK,EAAW,MAAM,4BAA4B,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAkB,MAAM,cAAc,CAAC;AAKtE,qBAAa,cAAc;IAMvB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,gBAAgB;IAP1B,OAAO,CAAC,aAAa,CAAyD;IAC9E,OAAO,CAAC,YAAY,CAAkD;IACtE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAQ;gBAG9B,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACnD,gBAAgB,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI;IAGlD,wBAAwB,IAAI,IAAI;IAyChC,oBAAoB,CAAC,YAAY,EAAE,iBAAiB,GAAG,IAAI;YA+B7C,oBAAoB;YAUpB,mBAAmB;YAgBnB,sBAAsB;YAUtB,qBAAqB;YAiBrB,oBAAoB;YAOpB,sBAAsB;YAOtB,wBAAwB;YASxB,oBAAoB;IAUlC,gBAAgB,IAAI,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,CAAC;IAI9D,eAAe,IAAI,KAAK,CAAC;QAAE,KAAK,EAAE,KAAK,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAI7D,iBAAiB,IAAI,IAAI;CAG1B"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import createDebug from 'debug';
|
|
2
|
+
const debugBus = createDebug('auto-engineer:server:bus');
|
|
3
|
+
export class EventProcessor {
|
|
4
|
+
constructor(messageBus, stateManager, onEventBroadcast) {
|
|
5
|
+
this.messageBus = messageBus;
|
|
6
|
+
this.stateManager = stateManager;
|
|
7
|
+
this.onEventBroadcast = onEventBroadcast;
|
|
8
|
+
this.eventHandlers = new Map();
|
|
9
|
+
this.eventHistory = [];
|
|
10
|
+
this.maxEventHistory = 1000;
|
|
11
|
+
}
|
|
12
|
+
setupGlobalEventListener() {
|
|
13
|
+
this.messageBus.subscribeAll({
|
|
14
|
+
name: 'ServerStateManager',
|
|
15
|
+
handle: async (event) => {
|
|
16
|
+
debugBus('Received event:', event.type);
|
|
17
|
+
// Store event in history
|
|
18
|
+
this.eventHistory.push({
|
|
19
|
+
event,
|
|
20
|
+
timestamp: new Date().toISOString(),
|
|
21
|
+
});
|
|
22
|
+
// Trim history if it exceeds max size
|
|
23
|
+
if (this.eventHistory.length > this.maxEventHistory) {
|
|
24
|
+
this.eventHistory = this.eventHistory.slice(-this.maxEventHistory);
|
|
25
|
+
}
|
|
26
|
+
// Apply event to state
|
|
27
|
+
this.stateManager.applyEvent(event);
|
|
28
|
+
// Trigger registered event handlers
|
|
29
|
+
const handlers = this.eventHandlers.get(event.type) || [];
|
|
30
|
+
for (const handler of handlers) {
|
|
31
|
+
try {
|
|
32
|
+
handler(event);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
const isTest = process.env.NODE_ENV === 'test' || process.env.VITEST === 'true';
|
|
36
|
+
if (!isTest) {
|
|
37
|
+
console.error(`Error in event handler for ${event.type}:`, error);
|
|
38
|
+
}
|
|
39
|
+
debugBus('Event handler error (suppressed in tests):', error);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Broadcast event to WebSocket clients
|
|
43
|
+
this.onEventBroadcast(event);
|
|
44
|
+
debugBus('Broadcasted event to clients:', event.type);
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
registerEventHandler(registration) {
|
|
49
|
+
debugBus('Registering event handler for:', registration.eventType);
|
|
50
|
+
const handler = (event) => {
|
|
51
|
+
(async () => {
|
|
52
|
+
try {
|
|
53
|
+
const result = registration.handler(event);
|
|
54
|
+
await this.processHandlerResult(result);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
const isTest = process.env.NODE_ENV === 'test' || process.env.VITEST === 'true';
|
|
58
|
+
if (!isTest) {
|
|
59
|
+
console.error('Error in event handler:', error);
|
|
60
|
+
}
|
|
61
|
+
debugBus('Event handler error (suppressed in tests):', error);
|
|
62
|
+
}
|
|
63
|
+
})().catch((error) => {
|
|
64
|
+
const isTest = process.env.NODE_ENV === 'test' || process.env.VITEST === 'true';
|
|
65
|
+
if (!isTest) {
|
|
66
|
+
console.error('Unhandled error in event handler:', error);
|
|
67
|
+
}
|
|
68
|
+
debugBus('Unhandled event handler error (suppressed in tests):', error);
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
// Store handler for later execution
|
|
72
|
+
if (!this.eventHandlers.has(registration.eventType)) {
|
|
73
|
+
this.eventHandlers.set(registration.eventType, []);
|
|
74
|
+
}
|
|
75
|
+
this.eventHandlers.get(registration.eventType).push(handler);
|
|
76
|
+
}
|
|
77
|
+
async processHandlerResult(result) {
|
|
78
|
+
if (result === null || result === undefined)
|
|
79
|
+
return;
|
|
80
|
+
if (Array.isArray(result)) {
|
|
81
|
+
await this.processCommandArray(result);
|
|
82
|
+
}
|
|
83
|
+
else if (typeof result === 'object' && result !== null && 'type' in result) {
|
|
84
|
+
await this.processActionOrCommand(result);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async processCommandArray(commands) {
|
|
88
|
+
debugBus('Dispatching multiple commands from event handler');
|
|
89
|
+
for (const command of commands) {
|
|
90
|
+
if (command !== null &&
|
|
91
|
+
command !== undefined &&
|
|
92
|
+
typeof command === 'object' &&
|
|
93
|
+
'type' in command &&
|
|
94
|
+
'data' in command) {
|
|
95
|
+
debugBus('Dispatching command:', command.type);
|
|
96
|
+
await this.messageBus.sendCommand(command);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async processActionOrCommand(action) {
|
|
101
|
+
const actionObj = action;
|
|
102
|
+
if (actionObj !== null && typeof actionObj === 'object' && 'data' in actionObj) {
|
|
103
|
+
debugBus('Dispatching command from event handler:', action.type);
|
|
104
|
+
await this.messageBus.sendCommand(action);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
await this.processDispatchAction(action);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async processDispatchAction(action) {
|
|
111
|
+
switch (action.type) {
|
|
112
|
+
case 'dispatch':
|
|
113
|
+
await this.handleSingleDispatch(action);
|
|
114
|
+
break;
|
|
115
|
+
case 'dispatch-parallel':
|
|
116
|
+
await this.handleParallelDispatch(action);
|
|
117
|
+
break;
|
|
118
|
+
case 'dispatch-sequence':
|
|
119
|
+
await this.handleSequentialDispatch(action);
|
|
120
|
+
break;
|
|
121
|
+
case 'dispatch-custom':
|
|
122
|
+
await this.handleCustomDispatch(action);
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async handleSingleDispatch(action) {
|
|
127
|
+
if (action.command) {
|
|
128
|
+
debugBus('Dispatching command from dispatch action:', action.command.type);
|
|
129
|
+
await this.messageBus.sendCommand(action.command);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async handleParallelDispatch(action) {
|
|
133
|
+
if (action.commands) {
|
|
134
|
+
debugBus('Dispatching parallel commands from event handler');
|
|
135
|
+
await Promise.all(action.commands.map((cmd) => this.messageBus.sendCommand(cmd)));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async handleSequentialDispatch(action) {
|
|
139
|
+
if (action.commands) {
|
|
140
|
+
debugBus('Dispatching sequential commands from event handler');
|
|
141
|
+
for (const cmd of action.commands) {
|
|
142
|
+
await this.messageBus.sendCommand(cmd);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async handleCustomDispatch(action) {
|
|
147
|
+
if (action.commandFactory) {
|
|
148
|
+
const cmds = action.commandFactory();
|
|
149
|
+
const commands = Array.isArray(cmds) ? cmds : [cmds];
|
|
150
|
+
for (const cmd of commands) {
|
|
151
|
+
await this.messageBus.sendCommand(cmd);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
getEventHandlers() {
|
|
156
|
+
return this.eventHandlers;
|
|
157
|
+
}
|
|
158
|
+
getEventHistory() {
|
|
159
|
+
return this.eventHistory;
|
|
160
|
+
}
|
|
161
|
+
clearEventHistory() {
|
|
162
|
+
this.eventHistory = [];
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=event-processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-processor.js","sourceRoot":"","sources":["../../../src/server/event-processor.ts"],"names":[],"mappings":"AAGA,OAAO,WAAW,MAAM,OAAO,CAAC;AAEhC,MAAM,QAAQ,GAAG,WAAW,CAAC,0BAA0B,CAAC,CAAC;AAEzD,MAAM,OAAO,cAAc;IAKzB,YACU,UAAsB,EACtB,YAAmD,EACnD,gBAAwC;QAFxC,eAAU,GAAV,UAAU,CAAY;QACtB,iBAAY,GAAZ,YAAY,CAAuC;QACnD,qBAAgB,GAAhB,gBAAgB,CAAwB;QAP1C,kBAAa,GAA+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|
2
|
+
import type { MessageBus, Event } from '@auto-engineer/message-bus';
|
|
3
|
+
import type { StateManager, FoldFunction } from './state-manager';
|
|
4
|
+
export interface HttpRoutesConfig {
|
|
5
|
+
commandHandlerNames: string[];
|
|
6
|
+
commandMetadata: Map<string, {
|
|
7
|
+
alias: string;
|
|
8
|
+
description: string;
|
|
9
|
+
package: string;
|
|
10
|
+
version?: string;
|
|
11
|
+
category?: string;
|
|
12
|
+
}>;
|
|
13
|
+
eventHandlers: Map<string, Array<(event: Event) => void>>;
|
|
14
|
+
foldRegistry: Map<string, FoldFunction<Record<string, unknown>>>;
|
|
15
|
+
eventHistory: Array<{
|
|
16
|
+
event: Event;
|
|
17
|
+
timestamp: string;
|
|
18
|
+
}>;
|
|
19
|
+
onCommandError: (error: {
|
|
20
|
+
commandId: string;
|
|
21
|
+
error: string;
|
|
22
|
+
timestamp: string;
|
|
23
|
+
}) => void;
|
|
24
|
+
}
|
|
25
|
+
export declare function setupHttpRoutes(app: express.Application, messageBus: MessageBus, stateManager: StateManager<Record<string, unknown>>, config: HttpRoutesConfig): void;
|
|
26
|
+
//# sourceMappingURL=http-routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-routes.d.ts","sourceRoot":"","sources":["../../../src/server/http-routes.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAG9B,OAAO,KAAK,EAAE,UAAU,EAAW,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAKlE,MAAM,WAAW,gBAAgB;IAC/B,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,eAAe,EAAE,GAAG,CAClB,MAAM,EACN;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAC7F,CAAC;IACF,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC;IAC1D,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACjE,YAAY,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,KAAK,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACzD,cAAc,EAAE,CAAC,KAAK,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CAC1F;AAED,wBAAgB,eAAe,CAC7B,GAAG,EAAE,OAAO,CAAC,WAAW,EACxB,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACnD,MAAM,EAAE,gBAAgB,GACvB,IAAI,CAoIN"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { fileURLToPath } from 'url';
|
|
2
|
+
import { dirname, join } from 'path';
|
|
3
|
+
import createDebug from 'debug';
|
|
4
|
+
const debugHttp = createDebug('auto-engineer:server:http');
|
|
5
|
+
export function setupHttpRoutes(app, messageBus, stateManager, config) {
|
|
6
|
+
// Health check endpoint
|
|
7
|
+
app.get('/health', (_req, res) => {
|
|
8
|
+
res.json({
|
|
9
|
+
status: 'healthy',
|
|
10
|
+
uptime: process.uptime(),
|
|
11
|
+
timestamp: new Date().toISOString(),
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
// Serve dashboard
|
|
15
|
+
app.get('/', (_req, res) => {
|
|
16
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
17
|
+
res.sendFile(join(__dirname, 'dashboard.html'));
|
|
18
|
+
});
|
|
19
|
+
// Get registry information
|
|
20
|
+
app.get('/registry', (_req, res) => {
|
|
21
|
+
// Sort commands alphabetically by alias
|
|
22
|
+
const sortedCommands = config.commandHandlerNames
|
|
23
|
+
.map((name) => ({
|
|
24
|
+
name,
|
|
25
|
+
metadata: config.commandMetadata.get(name),
|
|
26
|
+
}))
|
|
27
|
+
.sort((a, b) => {
|
|
28
|
+
const aliasA = a.metadata?.alias ?? a.name;
|
|
29
|
+
const aliasB = b.metadata?.alias ?? b.name;
|
|
30
|
+
return aliasA.localeCompare(aliasB);
|
|
31
|
+
});
|
|
32
|
+
res.json({
|
|
33
|
+
eventHandlers: Array.from(config.eventHandlers.keys()),
|
|
34
|
+
folds: Array.from(config.foldRegistry.keys()),
|
|
35
|
+
commandHandlers: sortedCommands.map((cmd) => cmd.name),
|
|
36
|
+
commandsWithMetadata: sortedCommands.map((cmd) => ({
|
|
37
|
+
name: cmd.name,
|
|
38
|
+
alias: cmd.metadata?.alias ?? cmd.name,
|
|
39
|
+
description: cmd.metadata?.description ?? 'No description',
|
|
40
|
+
package: cmd.metadata?.package ?? 'unknown',
|
|
41
|
+
version: cmd.metadata?.version,
|
|
42
|
+
category: cmd.metadata?.category,
|
|
43
|
+
})),
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
// Get event history
|
|
47
|
+
app.get('/events', (_req, res) => {
|
|
48
|
+
res.json(config.eventHistory);
|
|
49
|
+
});
|
|
50
|
+
// Get current state
|
|
51
|
+
app.get('/state', (_req, res) => {
|
|
52
|
+
res.json(stateManager.getState());
|
|
53
|
+
});
|
|
54
|
+
// Command endpoint
|
|
55
|
+
app.post('/command', (req, res) => {
|
|
56
|
+
(async () => {
|
|
57
|
+
try {
|
|
58
|
+
const command = req.body;
|
|
59
|
+
debugHttp('Received command:', command.type);
|
|
60
|
+
debugHttp('Command data:', command.data);
|
|
61
|
+
// Validate command structure
|
|
62
|
+
if (!command.type || !('data' in command)) {
|
|
63
|
+
return res.status(400).json({
|
|
64
|
+
status: 'nack',
|
|
65
|
+
error: 'Invalid command structure. Must have type and data fields.',
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
// Add request ID if not present
|
|
69
|
+
const hasRequestId = command.requestId !== null && command.requestId !== undefined && command.requestId !== '';
|
|
70
|
+
const cmdWithId = hasRequestId
|
|
71
|
+
? command
|
|
72
|
+
: { ...command, requestId: `req-${Date.now()}-${Math.random().toString(36).substring(2, 11)}` };
|
|
73
|
+
// Check if command handler exists
|
|
74
|
+
if (!config.commandHandlerNames.includes(cmdWithId.type)) {
|
|
75
|
+
return res.status(404).json({
|
|
76
|
+
status: 'nack',
|
|
77
|
+
error: `Command handler not found for command: ${cmdWithId.type}`,
|
|
78
|
+
availableCommands: config.commandHandlerNames,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
// Send to message bus (non-blocking)
|
|
82
|
+
messageBus
|
|
83
|
+
.sendCommand(cmdWithId)
|
|
84
|
+
.then(() => {
|
|
85
|
+
debugHttp('Command processed successfully:', cmdWithId.type);
|
|
86
|
+
})
|
|
87
|
+
.catch((err) => {
|
|
88
|
+
const isTest = process.env.NODE_ENV === 'test' || process.env.VITEST === 'true';
|
|
89
|
+
if (!isTest) {
|
|
90
|
+
console.error('Command failed:', err);
|
|
91
|
+
}
|
|
92
|
+
debugHttp('Command failed (suppressed in tests):', err);
|
|
93
|
+
// Emit error event for UI to capture
|
|
94
|
+
config.onCommandError({
|
|
95
|
+
commandId: cmdWithId.requestId ?? 'unknown',
|
|
96
|
+
error: err instanceof Error ? err.message : String(err),
|
|
97
|
+
timestamp: new Date().toISOString(),
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
// Return acknowledgment immediately
|
|
101
|
+
res.json({
|
|
102
|
+
status: 'ack',
|
|
103
|
+
commandId: cmdWithId.requestId ?? 'unknown',
|
|
104
|
+
timestamp: new Date().toISOString(),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
debugHttp('Error processing command:', error);
|
|
109
|
+
res.status(400).json({
|
|
110
|
+
status: 'nack',
|
|
111
|
+
error: error instanceof Error ? error.message : 'Failed to process command',
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
})().catch((err) => {
|
|
115
|
+
debugHttp('Unhandled error in command handler:', err);
|
|
116
|
+
if (!res.headersSent) {
|
|
117
|
+
res.status(500).json({
|
|
118
|
+
status: 'nack',
|
|
119
|
+
error: 'Internal server error',
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
debugHttp('HTTP routes configured');
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=http-routes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-routes.js","sourceRoot":"","sources":["../../../src/server/http-routes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAGrC,OAAO,WAAW,MAAM,OAAO,CAAC;AAEhC,MAAM,SAAS,GAAG,WAAW,CAAC,2BAA2B,CAAC,CAAC;AAc3D,MAAM,UAAU,eAAe,CAC7B,GAAwB,EACxB,UAAsB,EACtB,YAAmD,EACnD,MAAwB;IAExB,wBAAwB;IACxB,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;QAC/B,GAAG,CAAC,IAAI,CAAC;YACP,MAAM,EAAE,SAAS;YACjB,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE;YACxB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACpC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,kBAAkB;IAClB,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;QAC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AC,CAAC,CAAC;IAEH,SAAS,CAAC,wBAAwB,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -16,17 +16,9 @@ export declare class MessageBusServer {
|
|
|
16
16
|
private stateManager;
|
|
17
17
|
private fileSyncer?;
|
|
18
18
|
private config;
|
|
19
|
-
private
|
|
20
|
-
private
|
|
21
|
-
private commandHandlerNames;
|
|
22
|
-
private commandMetadata;
|
|
23
|
-
private eventHistory;
|
|
24
|
-
private maxEventHistory;
|
|
19
|
+
private eventProcessor;
|
|
20
|
+
private commandRegistry;
|
|
25
21
|
constructor(config?: MessageBusServerConfig);
|
|
26
|
-
/**
|
|
27
|
-
* Set up global event listener for state management and event forwarding
|
|
28
|
-
*/
|
|
29
|
-
private setupGlobalEventListener;
|
|
30
22
|
/**
|
|
31
23
|
* Set up HTTP routes
|
|
32
24
|
*/
|
|
@@ -35,13 +27,6 @@ export declare class MessageBusServer {
|
|
|
35
27
|
* Set up WebSocket handlers
|
|
36
28
|
*/
|
|
37
29
|
private setupWebSocketHandlers;
|
|
38
|
-
/**
|
|
39
|
-
* Process handler result to reduce complexity
|
|
40
|
-
*/
|
|
41
|
-
private processHandlerResult;
|
|
42
|
-
private processCommandArray;
|
|
43
|
-
private processActionOrCommand;
|
|
44
|
-
private processDispatchAction;
|
|
45
30
|
/**
|
|
46
31
|
* Register event handlers from DSL
|
|
47
32
|
*/
|
|
@@ -64,8 +49,6 @@ export declare class MessageBusServer {
|
|
|
64
49
|
* Register command handlers directly with the message bus
|
|
65
50
|
*/
|
|
66
51
|
registerCommandHandlers(handlers: unknown[]): void;
|
|
67
|
-
private processCommandHandler;
|
|
68
|
-
private extractUnifiedHandlerMetadata;
|
|
69
52
|
/**
|
|
70
53
|
* Initialize state
|
|
71
54
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/server/server.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"server.d.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