mirror of
https://github.com/aljazceru/claude-code-viewer.git
synced 2026-01-03 13:44:23 +01:00
refactor: split request handle logic to controller
This commit is contained in:
41
src/server/core/claude-code/services/ClaudeCodeService.ts
Normal file
41
src/server/core/claude-code/services/ClaudeCodeService.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { Context, Data, Effect, Layer } from "effect";
|
||||
import type { InferEffect } from "../../../lib/effect/types";
|
||||
import { ProjectRepository } from "../../project/infrastructure/ProjectRepository";
|
||||
import { parseMcpListOutput } from "../functions/parseMcpListOutput";
|
||||
import * as ClaudeCode from "../models/ClaudeCode";
|
||||
|
||||
class ProjectPathNotFoundError extends Data.TaggedError(
|
||||
"ProjectPathNotFoundError",
|
||||
)<{
|
||||
projectId: string;
|
||||
}> {}
|
||||
|
||||
const LayerImpl = Effect.gen(function* () {
|
||||
const projectRepository = yield* ProjectRepository;
|
||||
|
||||
const getMcpList = (projectId: string) =>
|
||||
Effect.gen(function* () {
|
||||
const { project } = yield* projectRepository.getProject(projectId);
|
||||
if (project.meta.projectPath === null) {
|
||||
return yield* Effect.fail(new ProjectPathNotFoundError({ projectId }));
|
||||
}
|
||||
|
||||
const output = yield* ClaudeCode.getMcpListOutput(
|
||||
project.meta.projectPath,
|
||||
);
|
||||
return parseMcpListOutput(output);
|
||||
});
|
||||
|
||||
return {
|
||||
getMcpList,
|
||||
};
|
||||
});
|
||||
|
||||
export type IClaudeCodeService = InferEffect<typeof LayerImpl>;
|
||||
|
||||
export class ClaudeCodeService extends Context.Tag("ClaudeCodeService")<
|
||||
ClaudeCodeService,
|
||||
IClaudeCodeService
|
||||
>() {
|
||||
static Live = Layer.effect(this, LayerImpl);
|
||||
}
|
||||
Reference in New Issue
Block a user