Open History to see the last commit
1/**
2 * RoutingTextGeneration – Dispatches text generation requests to either the
3 * Codex CLI or Claude CLI implementation based on the provider in each
4 * request input.
5 *
6 * When `modelSelection.provider` is `"claudeAgent"` the request is forwarded to
7 * the Claude layer; for any other value (including the default `undefined`) it
8 * falls through to the Codex layer.
9 *
10 * @module RoutingTextGeneration
11 */
12import { Effect, Layer, Context } from "effect";
13
14import { TextGeneration, type TextGenerationShape } from "../Services/TextGeneration.ts";
15import { CodexTextGenerationLive } from "./CodexTextGeneration.ts";
16import { ClaudeTextGenerationLive } from "./ClaudeTextGeneration.ts";
17import { CursorTextGenerationLive } from "./CursorTextGeneration.ts";
18import { OpenCodeTextGenerationLive } from "./OpenCodeTextGeneration.ts";
19
20// ---------------------------------------------------------------------------
21// Internal service tags so both concrete layers can coexist.
22// ---------------------------------------------------------------------------
23
24class CodexTextGen extends Context.Service<CodexTextGen, TextGenerationShape>()(
25 "t3/git/Layers/RoutingTextGeneration/CodexTextGen",
26) {}
27
28class ClaudeTextGen extends Context.Service<ClaudeTextGen, TextGenerationShape>()(
29 "t3/git/Layers/RoutingTextGeneration/ClaudeTextGen",
30) {}
31
32class CursorTextGen extends Context.Service<CursorTextGen, TextGenerationShape>()(
33 "t3/git/Layers/RoutingTextGeneration/CursorTextGen",
34) {}
35
36class OpenCodeTextGen extends Context.Service<OpenCodeTextGen, TextGenerationShape>()(
37 "t3/git/Layers/RoutingTextGeneration/OpenCodeTextGen",
38) {}
39
40// ---------------------------------------------------------------------------
41// Routing implementation
42// ---------------------------------------------------------------------------
43
44const makeRoutingTextGeneration = Effect.gen(function* () {
45 const byProvider = {
46 codex: yield* CodexTextGen,
47 claudeAgent: yield* ClaudeTextGen,
48 cursor: yield* CursorTextGen,
49 opencode: yield* OpenCodeTextGen,
50 };
51
52 return {
53 generateCommitMessage: (input) =>
54 byProvider[input.modelSelection.provider].generateCommitMessage(input),
55 generatePrContent: (input) =>
56 byProvider[input.modelSelection.provider].generatePrContent(input),
57 generateBranchName: (input) =>
58 byProvider[input.modelSelection.provider].generateBranchName(input),
59 generateThreadTitle: (input) =>
60 byProvider[input.modelSelection.provider].generateThreadTitle(input),
61 } satisfies TextGenerationShape;
62});
63
64const InternalCodexLayer = Layer.effect(
65 CodexTextGen,
66 Effect.gen(function* () {
67 const svc = yield* TextGeneration;
68 return svc;
69 }),
70).pipe(Layer.provide(CodexTextGenerationLive));
71
72const InternalClaudeLayer = Layer.effect(
73 ClaudeTextGen,
74 Effect.gen(function* () {
75 const svc = yield* TextGeneration;
76 return svc;
77 }),
78).pipe(Layer.provide(ClaudeTextGenerationLive));
79
80const InternalCursorLayer = Layer.effect(
81 CursorTextGen,
82 Effect.gen(function* () {
83 const svc = yield* TextGeneration;
84 return svc;
85 }),
86).pipe(Layer.provide(CursorTextGenerationLive));
87
88const InternalOpenCodeLayer = Layer.effect(
89 OpenCodeTextGen,
90 Effect.gen(function* () {
91 const svc = yield* TextGeneration;
92 return svc;
93 }),
94).pipe(Layer.provide(OpenCodeTextGenerationLive));
95
96export const RoutingTextGenerationLive = Layer.effect(
97 TextGeneration,
98 makeRoutingTextGeneration,
99).pipe(
100 Layer.provide(InternalCodexLayer),
101 Layer.provide(InternalClaudeLayer),
102 Layer.provide(InternalCursorLayer),
103 Layer.provide(InternalOpenCodeLayer),
104);