+36
![github-actions[bot]](/assets/img/avatar_default.png)








Julius Marminge
maria-rcks
Bilal Bakr
shivam
Vitalii Yehorov
Jake Leventhal
Claude Opus 5
Alex Southwell
github-actions[bot]
Nicholas Wasmiller
PB
Exotic
Yash Singh
Devin
Theo Browne
Gabriel De Andrade
Dara Adedeji
scratchyone
Dominic Roy
chukfinley
Primož Ajdišek
benthecarman
NaveDanan
aaditagrawal
Aditya Garud
Nick Anisimov
MacKinley Smith
Yordis Prieto
t3-code[bot]
AKolenda
Guillermo Casanova
Otavio Salvador
Shirish Pothi
Ishaan Kothari
Bob Fowler
Anton Bezdenezhnykh
ValeraZSD
Ephraim
Ryan Ilano
Alex
maco
Cursor
Tristan Knight
PR Batch Tester
oliver
kamkm
de34391427
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Bilal Bakr <[email protected]> Co-authored-by: shivam <[email protected]> Co-authored-by: Vitalii Yehorov <[email protected]> Co-authored-by: Jake Leventhal <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: Alex Southwell <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Nicholas Wasmiller <[email protected]> Co-authored-by: PB <[email protected]> Co-authored-by: Exotic <[email protected]> Co-authored-by: Yash Singh <[email protected]> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Theo Browne <[email protected]> Co-authored-by: Gabriel De Andrade <[email protected]> Co-authored-by: Dara Adedeji <[email protected]> Co-authored-by: scratchyone <[email protected]> Co-authored-by: Dominic Roy <[email protected]> Co-authored-by: chukfinley <[email protected]> Co-authored-by: Primož Ajdišek <[email protected]> Co-authored-by: benthecarman <[email protected]> Co-authored-by: NaveDanan <[email protected]> Co-authored-by: aaditagrawal <[email protected]> Co-authored-by: Aditya Garud <[email protected]> Co-authored-by: Nick Anisimov <[email protected]> Co-authored-by: MacKinley Smith <[email protected]> Co-authored-by: Yordis Prieto <[email protected]> Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com> Co-authored-by: AKolenda <[email protected]> Co-authored-by: Guillermo Casanova <[email protected]> Co-authored-by: Otavio Salvador <[email protected]> Co-authored-by: Shirish Pothi <[email protected]> Co-authored-by: Ishaan Kothari <[email protected]> Co-authored-by: Bob Fowler <[email protected]> Co-authored-by: Anton Bezdenezhnykh <[email protected]> Co-authored-by: ValeraZSD <[email protected]> Co-authored-by: Ephraim <[email protected]> Co-authored-by: Ryan Ilano <[email protected]> Co-authored-by: Alex <[email protected]> Co-authored-by: maco <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: Tristan Knight <[email protected]> Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: oliver <[email protected]> Co-authored-by: kamkm <[email protected]> Signed-off-by: Yordis Prieto <[email protected]>
179 lines
6.0 KiB
TypeScript
179 lines
6.0 KiB
TypeScript
import * as Context from "effect/Context";
|
|
import * as Effect from "effect/Effect";
|
|
import * as Layer from "effect/Layer";
|
|
import type {
|
|
BranchNamingOptions,
|
|
ChatAttachment,
|
|
ModelSelection,
|
|
ProviderInstanceId,
|
|
} from "@t3tools/contracts";
|
|
import { TextGenerationError } from "@t3tools/contracts";
|
|
|
|
import * as ProviderInstanceRegistry from "../provider/Services/ProviderInstanceRegistry.ts";
|
|
import type { ProviderInstance } from "../provider/ProviderDriver.ts";
|
|
import * as SourceControlProviderRegistry from "../sourceControl/SourceControlProviderRegistry.ts";
|
|
import * as ThreadTitleLinks from "./ThreadTitleLinks.ts";
|
|
import type { TextGenerationPolicy } from "./TextGenerationPolicy.ts";
|
|
|
|
export interface CommitMessageGenerationInput {
|
|
cwd: string;
|
|
branch: string | null;
|
|
stagedSummary: string;
|
|
stagedPatch: string;
|
|
/** When true, the model also returns a semantic branch name for the change. */
|
|
includeBranch?: boolean;
|
|
policy?: TextGenerationPolicy | undefined;
|
|
/** What model and provider to use for generation. */
|
|
modelSelection: ModelSelection;
|
|
}
|
|
|
|
export interface CommitMessageGenerationResult {
|
|
subject: string;
|
|
body: string;
|
|
/** Only present when `includeBranch` was set on the input. */
|
|
branch?: string | undefined;
|
|
}
|
|
|
|
export interface PrContentGenerationInput {
|
|
cwd: string;
|
|
baseBranch: string;
|
|
headBranch: string;
|
|
commitSummary: string;
|
|
diffSummary: string;
|
|
diffPatch: string;
|
|
changeRequestTemplate?: string | undefined;
|
|
policy?: TextGenerationPolicy | undefined;
|
|
/** What model and provider to use for generation. */
|
|
modelSelection: ModelSelection;
|
|
}
|
|
|
|
export interface PrContentGenerationResult {
|
|
title: string;
|
|
body: string;
|
|
}
|
|
|
|
export interface BranchNameGenerationInput {
|
|
naming?: BranchNamingOptions | undefined;
|
|
cwd: string;
|
|
message: string;
|
|
attachments?: ReadonlyArray<ChatAttachment> | undefined;
|
|
/** What model and provider to use for generation. */
|
|
modelSelection: ModelSelection;
|
|
}
|
|
|
|
export interface BranchNameGenerationResult {
|
|
branch: string;
|
|
}
|
|
|
|
export interface ThreadTitleGenerationInput {
|
|
linkedContext?: string | undefined;
|
|
cwd: string;
|
|
message: string;
|
|
/** Present when replacing an existing title from the current thread history. */
|
|
previousTitle?: string | undefined;
|
|
attachments?: ReadonlyArray<ChatAttachment> | undefined;
|
|
/** What model and provider to use for generation. */
|
|
modelSelection: ModelSelection;
|
|
}
|
|
|
|
export interface ThreadTitleGenerationResult {
|
|
title: string;
|
|
needsRefinement?: boolean | undefined;
|
|
}
|
|
|
|
/**
|
|
* TextGeneration - Service tag for commit and change request text generation.
|
|
*/
|
|
export class TextGeneration extends Context.Service<
|
|
TextGeneration,
|
|
{
|
|
/**
|
|
* Generate a commit message from staged change context.
|
|
*/
|
|
readonly generateCommitMessage: (
|
|
input: CommitMessageGenerationInput,
|
|
) => Effect.Effect<CommitMessageGenerationResult, TextGenerationError>;
|
|
|
|
/**
|
|
* Generate change request title/body from branch and diff context.
|
|
*/
|
|
readonly generatePrContent: (
|
|
input: PrContentGenerationInput,
|
|
) => Effect.Effect<PrContentGenerationResult, TextGenerationError>;
|
|
|
|
/**
|
|
* Generate a concise branch name from a user message.
|
|
*/
|
|
readonly generateBranchName: (
|
|
input: BranchNameGenerationInput,
|
|
) => Effect.Effect<BranchNameGenerationResult, TextGenerationError>;
|
|
|
|
/** Generate a concise thread title from a first message or thread history. */
|
|
readonly generateThreadTitle: (
|
|
input: ThreadTitleGenerationInput,
|
|
) => Effect.Effect<ThreadTitleGenerationResult, TextGenerationError>;
|
|
}
|
|
>()("t3/textGeneration/TextGeneration") {}
|
|
|
|
type TextGenerationOp =
|
|
| "generateCommitMessage"
|
|
| "generatePrContent"
|
|
| "generateBranchName"
|
|
| "generateThreadTitle";
|
|
|
|
const resolveInstance = (
|
|
registry: ProviderInstanceRegistry.ProviderInstanceRegistry["Service"],
|
|
operation: TextGenerationOp,
|
|
instanceId: ProviderInstanceId,
|
|
): Effect.Effect<ProviderInstance["textGeneration"], TextGenerationError> =>
|
|
registry.getInstance(instanceId).pipe(
|
|
Effect.flatMap((instance) =>
|
|
instance
|
|
? Effect.succeed(instance.textGeneration)
|
|
: Effect.fail(
|
|
new TextGenerationError({
|
|
operation,
|
|
detail: `No provider instance registered for id '${instanceId}'.`,
|
|
}),
|
|
),
|
|
),
|
|
);
|
|
|
|
/** @public Service construction is part of the canonical Effect module API. */
|
|
export const make = Effect.gen(function* () {
|
|
const registry = yield* ProviderInstanceRegistry.ProviderInstanceRegistry;
|
|
const sourceControl = yield* SourceControlProviderRegistry.SourceControlProviderRegistry;
|
|
return TextGeneration.of({
|
|
generateCommitMessage: (input) =>
|
|
resolveInstance(registry, "generateCommitMessage", input.modelSelection.instanceId).pipe(
|
|
Effect.flatMap((textGeneration) => textGeneration.generateCommitMessage(input)),
|
|
),
|
|
generatePrContent: (input) =>
|
|
resolveInstance(registry, "generatePrContent", input.modelSelection.instanceId).pipe(
|
|
Effect.flatMap((textGeneration) => textGeneration.generatePrContent(input)),
|
|
),
|
|
generateBranchName: (input) =>
|
|
resolveInstance(registry, "generateBranchName", input.modelSelection.instanceId).pipe(
|
|
Effect.flatMap((textGeneration) => textGeneration.generateBranchName(input)),
|
|
),
|
|
generateThreadTitle: (input) =>
|
|
resolveInstance(registry, "generateThreadTitle", input.modelSelection.instanceId).pipe(
|
|
Effect.flatMap((textGeneration) =>
|
|
Effect.gen(function* () {
|
|
const linkedContext =
|
|
input.linkedContext ??
|
|
(yield* ThreadTitleLinks.resolveThreadTitleLinks(input).pipe(
|
|
Effect.provideService(
|
|
SourceControlProviderRegistry.SourceControlProviderRegistry,
|
|
sourceControl,
|
|
),
|
|
));
|
|
return yield* textGeneration.generateThreadTitle({ ...input, linkedContext });
|
|
}),
|
|
),
|
|
),
|
|
});
|
|
});
|
|
|
|
export const layer = Layer.effect(TextGeneration, make);
|