Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

TextGeneration.ts

90 lines2.4 KB

1/**
2 * TextGeneration - Effect service contract for AI-generated Git content.
3 *
4 * Generates commit messages and pull request titles/bodies from repository
5 * context prepared by Git services.
6 *
7 * @module TextGeneration
8 */
9import { ServiceMap } from "effect";
10import type { Effect } from "effect";
11import type { ChatAttachment } from "@t3tools/contracts";
12​
13import type { TextGenerationError } from "../Errors.ts";
14​
15export interface CommitMessageGenerationInput {
16 cwd: string;
17 branch: string | null;
18 stagedSummary: string;
19 stagedPatch: string;
21​
22export interface CommitMessageGenerationResult {
23 subject: string;
24 body: string;
26​
27export interface PrContentGenerationInput {
28 cwd: string;
29 baseBranch: string;
30 headBranch: string;
31 commitSummary: string;
32 diffSummary: string;
33 diffPatch: string;
35​
36export interface PrContentGenerationResult {
37 title: string;
38 body: string;
40​
41export interface BranchNameGenerationInput {
42 cwd: string;
43 message: string;
44 attachments?: ReadonlyArray<ChatAttachment> | undefined;
46​
47export interface BranchNameGenerationResult {
48 branch: string;
50​
51export interface TextGenerationService {
52 generateCommitMessage(
53 input: CommitMessageGenerationInput,
54 ): Promise<CommitMessageGenerationResult>;
55 generatePrContent(input: PrContentGenerationInput): Promise<PrContentGenerationResult>;
56 generateBranchName(input: BranchNameGenerationInput): Promise<BranchNameGenerationResult>;
58​
59/**
60 * TextGenerationShape - Service API for commit/PR text generation.
61 */
62export interface TextGenerationShape {
63 /**
64 * Generate a commit message from staged change context.
65 */
66 readonly generateCommitMessage: (
67 input: CommitMessageGenerationInput,
68 ) => Effect.Effect<CommitMessageGenerationResult, TextGenerationError>;
69​
70 /**
71 * Generate pull request title/body from branch and diff context.
72 */
73 readonly generatePrContent: (
74 input: PrContentGenerationInput,
75 ) => Effect.Effect<PrContentGenerationResult, TextGenerationError>;
76​
77 /**
78 * Generate a concise branch name from a user message.
79 */
80 readonly generateBranchName: (
81 input: BranchNameGenerationInput,
82 ) => Effect.Effect<BranchNameGenerationResult, TextGenerationError>;
84​
85/**
86 * TextGeneration - Service tag for commit and PR text generation.
87 */
88export class TextGeneration extends ServiceMap.Service<TextGeneration, TextGenerationShape>()(
89 "t3/git/Services/TextGeneration",
90) {}