Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]> Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: codex <[email protected]>
74 lines
2.7 KiB
TypeScript
74 lines
2.7 KiB
TypeScript
/**
|
||
* RoutingTextGeneration – Dispatches text generation requests to either the
|
||
* Codex CLI or Claude CLI implementation based on the provider in each
|
||
* request input.
|
||
*
|
||
* When `modelSelection.provider` is `"claudeAgent"` the request is forwarded to
|
||
* the Claude layer; for any other value (including the default `undefined`) it
|
||
* falls through to the Codex layer.
|
||
*
|
||
* @module RoutingTextGeneration
|
||
*/
|
||
import { Effect, Layer, Context } from "effect";
|
||
|
||
import {
|
||
TextGeneration,
|
||
type TextGenerationProvider,
|
||
type TextGenerationShape,
|
||
} from "../Services/TextGeneration.ts";
|
||
import { CodexTextGenerationLive } from "./CodexTextGeneration.ts";
|
||
import { ClaudeTextGenerationLive } from "./ClaudeTextGeneration.ts";
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Internal service tags so both concrete layers can coexist.
|
||
// ---------------------------------------------------------------------------
|
||
|
||
class CodexTextGen extends Context.Service<CodexTextGen, TextGenerationShape>()(
|
||
"t3/git/Layers/RoutingTextGeneration/CodexTextGen",
|
||
) {}
|
||
|
||
class ClaudeTextGen extends Context.Service<ClaudeTextGen, TextGenerationShape>()(
|
||
"t3/git/Layers/RoutingTextGeneration/ClaudeTextGen",
|
||
) {}
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Routing implementation
|
||
// ---------------------------------------------------------------------------
|
||
|
||
const makeRoutingTextGeneration = Effect.gen(function* () {
|
||
const codex = yield* CodexTextGen;
|
||
const claude = yield* ClaudeTextGen;
|
||
|
||
const route = (provider?: TextGenerationProvider): TextGenerationShape =>
|
||
provider === "claudeAgent" ? claude : codex;
|
||
|
||
return {
|
||
generateCommitMessage: (input) =>
|
||
route(input.modelSelection.provider).generateCommitMessage(input),
|
||
generatePrContent: (input) => route(input.modelSelection.provider).generatePrContent(input),
|
||
generateBranchName: (input) => route(input.modelSelection.provider).generateBranchName(input),
|
||
generateThreadTitle: (input) => route(input.modelSelection.provider).generateThreadTitle(input),
|
||
} satisfies TextGenerationShape;
|
||
});
|
||
|
||
const InternalCodexLayer = Layer.effect(
|
||
CodexTextGen,
|
||
Effect.gen(function* () {
|
||
const svc = yield* TextGeneration;
|
||
return svc;
|
||
}),
|
||
).pipe(Layer.provide(CodexTextGenerationLive));
|
||
|
||
const InternalClaudeLayer = Layer.effect(
|
||
ClaudeTextGen,
|
||
Effect.gen(function* () {
|
||
const svc = yield* TextGeneration;
|
||
return svc;
|
||
}),
|
||
).pipe(Layer.provide(ClaudeTextGenerationLive));
|
||
|
||
export const RoutingTextGenerationLive = Layer.effect(
|
||
TextGeneration,
|
||
makeRoutingTextGeneration,
|
||
).pipe(Layer.provide(InternalCodexLayer), Layer.provide(InternalClaudeLayer));
|