- Move core agent engine to packages/core/ - Add packages/types/ for shared TypeScript types - Add packages/utils/ for utility functions - Add apps/cli/ for command-line interface - Add apps/gateway/ for NestJS WebSocket gateway - Add apps/server/ for REST API server - Restructure desktop app (electron/ → src/main/, src/preload/) - Update pnpm workspace configuration - Remove legacy src/ directory Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
55 lines
1.1 KiB
TypeScript
55 lines
1.1 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Put,
|
|
Delete,
|
|
Param,
|
|
Body,
|
|
Inject,
|
|
} from "@nestjs/common";
|
|
import { Hub } from "@multica/core";
|
|
|
|
@Controller("api")
|
|
export class AppController {
|
|
constructor(@Inject("HUB") private readonly hub: Hub) {}
|
|
|
|
@Get("hub")
|
|
getHub() {
|
|
return {
|
|
hubId: this.hub.hubId,
|
|
url: this.hub.url,
|
|
connectionState: this.hub.connectionState,
|
|
agentCount: this.hub.listAgents().length,
|
|
};
|
|
}
|
|
|
|
@Put("hub/gateway")
|
|
updateGateway(@Body() body: { url: string }) {
|
|
this.hub.reconnect(body.url);
|
|
return {
|
|
url: this.hub.url,
|
|
connectionState: this.hub.connectionState,
|
|
};
|
|
}
|
|
|
|
@Get("agents")
|
|
listAgents() {
|
|
return this.hub.listAgents().map((id) => {
|
|
const agent = this.hub.getAgent(id);
|
|
return { id, closed: agent?.closed ?? true };
|
|
});
|
|
}
|
|
|
|
@Post("agents")
|
|
createAgent(@Body() body?: { id?: string }) {
|
|
const agent = this.hub.createAgent(body?.id);
|
|
return { id: agent.sessionId };
|
|
}
|
|
|
|
@Delete("agents/:id")
|
|
deleteAgent(@Param("id") id: string) {
|
|
const ok = this.hub.closeAgent(id);
|
|
return { ok };
|
|
}
|
|
}
|