+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]>
362 lines
14 KiB
TypeScript
362 lines
14 KiB
TypeScript
import { useNavigate } from "@tanstack/react-router";
|
|
import { useRef, useState } from "react";
|
|
import type {
|
|
ProviderInstanceId,
|
|
ServerSettings,
|
|
SourceControlWritingStyleMode,
|
|
} from "@t3tools/contracts";
|
|
import { DEFAULT_UNIFIED_SETTINGS } from "@t3tools/contracts/settings";
|
|
import { createModelSelection } from "@t3tools/shared/model";
|
|
import { resolveSourceControlWriterModelSelection } from "@t3tools/shared/serverSettings";
|
|
|
|
import {
|
|
useScopedSettings,
|
|
useScopedSettingsMixed,
|
|
useUpdateScopedSettings,
|
|
} from "./useScopedSettings";
|
|
import { useScopedModelDisabledReason } from "./useScopedModelAvailability";
|
|
import { useSettingsScope } from "./SettingsScopeContext";
|
|
import {
|
|
applyProviderInstanceSettings,
|
|
deriveProviderInstanceEntries,
|
|
sortProviderInstanceEntries,
|
|
} from "../../providerInstances";
|
|
import {
|
|
getCustomModelOptionsByInstance,
|
|
resolveAppModelSelectionState,
|
|
} from "../../modelSelection";
|
|
import { EMPTY_SERVER_PROVIDERS } from "../../state/server";
|
|
import { ProviderModelPicker } from "../chat/ProviderModelPicker";
|
|
import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select";
|
|
import { Switch } from "../ui/switch";
|
|
import { Textarea } from "../ui/textarea";
|
|
import { toastManager } from "../ui/toast";
|
|
import { Button } from "../ui/button";
|
|
import {
|
|
SETTINGS_PICKER_TRIGGER_CLASSNAME,
|
|
SettingResetButton,
|
|
SettingsRow,
|
|
SettingsSection,
|
|
} from "./settingsLayout";
|
|
import { BranchNamingSettings } from "./BranchNamingSettings";
|
|
import { searchableSetting } from "./settingsSearch";
|
|
|
|
const MODE_OPTIONS: Record<SourceControlWritingStyleMode, { label: string; description: string }> =
|
|
{
|
|
repo_conventions: {
|
|
label: "Repository conventions",
|
|
description: "In each project, matches recent change descriptions and change request titles.",
|
|
},
|
|
conventional_commits: {
|
|
label: "Conventional Commits",
|
|
description: "Use Conventional Commit prefixes and keep change request text concise.",
|
|
},
|
|
custom: {
|
|
label: "Custom instructions",
|
|
description:
|
|
"Use your instructions for change descriptions and change requests in every project.",
|
|
},
|
|
};
|
|
|
|
export function SourceControlWritingSettingsSection() {
|
|
const settings = useScopedSettings();
|
|
const updateSettings = useUpdateScopedSettings();
|
|
const navigate = useNavigate();
|
|
const { environment, connectedEnvironments, targets } = useSettingsScope();
|
|
// The representative supplies the provider list; a model choice is checked
|
|
// against every target before it fans out.
|
|
const environmentId = environment?.environmentId ?? null;
|
|
const hasServerTargets = connectedEnvironments.length > 0;
|
|
const serverProviders = environment?.serverConfig?.providers ?? EMPTY_SERVER_PROVIDERS;
|
|
// The writing style is one object; each control only cares about its own field.
|
|
const styleFieldMixed = (field: keyof ServerSettings["sourceControlWritingStyle"]) => {
|
|
const first = targets[0];
|
|
return (
|
|
first !== undefined &&
|
|
targets.some(
|
|
(candidate) =>
|
|
candidate.settings.sourceControlWritingStyle[field] !==
|
|
first.settings.sourceControlWritingStyle[field],
|
|
)
|
|
);
|
|
};
|
|
const modeMixed = styleFieldMixed("mode");
|
|
const instructionsMixed = styleFieldMixed("customInstructions");
|
|
const templatesMixed = styleFieldMixed("followChangeRequestTemplates");
|
|
const writingStyleMixed = modeMixed || instructionsMixed;
|
|
const mixedWriterModel = useScopedSettingsMixed(["sourceControlWriterModelSelection"]);
|
|
const customInstructionsRef = useRef<HTMLTextAreaElement>(null);
|
|
const [editingAllInstructions, setEditingAllInstructions] = useState(false);
|
|
const [allInstructions, setAllInstructions] = useState<string | null>(null);
|
|
const style = settings.sourceControlWritingStyle;
|
|
const defaults = DEFAULT_UNIFIED_SETTINGS.sourceControlWritingStyle;
|
|
const isSourceControlWritingStyleDirty =
|
|
writingStyleMixed ||
|
|
style.mode !== defaults.mode ||
|
|
style.customInstructions !== defaults.customInstructions;
|
|
|
|
const textGenerationProviders = serverProviders.filter(
|
|
(provider) => provider.supportsTextGeneration !== false,
|
|
);
|
|
const defaultModelSelection = resolveAppModelSelectionState(settings, textGenerationProviders);
|
|
const usesDedicatedModel = settings.sourceControlWriterModelSelection !== null;
|
|
const activeSelection = resolveAppModelSelectionState(
|
|
{
|
|
...settings,
|
|
textGenerationModelSelection: resolveSourceControlWriterModelSelection(
|
|
settings,
|
|
textGenerationProviders,
|
|
),
|
|
},
|
|
textGenerationProviders,
|
|
);
|
|
const instanceEntries = sortProviderInstanceEntries(
|
|
applyProviderInstanceSettings(deriveProviderInstanceEntries(textGenerationProviders), settings),
|
|
);
|
|
const canEnableDedicatedModel = instanceEntries.some(
|
|
(entry) =>
|
|
entry.instanceId === defaultModelSelection.instanceId && entry.enabled && entry.isAvailable,
|
|
);
|
|
const modelOptionsByInstance = getCustomModelOptionsByInstance(
|
|
settings,
|
|
textGenerationProviders,
|
|
activeSelection.instanceId,
|
|
activeSelection.model,
|
|
);
|
|
const writerModelDisabledReason = useScopedModelDisabledReason(settings, instanceEntries);
|
|
|
|
return (
|
|
<SettingsSection id="source-control-text-generation" title="Text generation">
|
|
<BranchNamingSettings />
|
|
<SettingsRow
|
|
serverScoped
|
|
settingKeys={["sourceControlWritingStyle"]}
|
|
mixed={writingStyleMixed}
|
|
{...searchableSetting("source-control-writing-style")}
|
|
description={MODE_OPTIONS[style.mode].description}
|
|
resetAction={
|
|
isSourceControlWritingStyleDirty ? (
|
|
<SettingResetButton
|
|
label="source control writing style"
|
|
onClick={() =>
|
|
updateSettings({
|
|
sourceControlWritingStyle: {
|
|
mode: defaults.mode,
|
|
customInstructions: defaults.customInstructions,
|
|
},
|
|
})
|
|
}
|
|
/>
|
|
) : null
|
|
}
|
|
control={
|
|
<Select
|
|
value={modeMixed ? null : style.mode}
|
|
onValueChange={(value) => {
|
|
const customInstructions = customInstructionsRef.current?.value.trim();
|
|
updateSettings({
|
|
sourceControlWritingStyle: {
|
|
mode: value as SourceControlWritingStyleMode,
|
|
...(customInstructions !== undefined ? { customInstructions } : {}),
|
|
},
|
|
});
|
|
}}
|
|
>
|
|
<SelectTrigger
|
|
size="sm"
|
|
className="w-full sm:w-56"
|
|
aria-label="Source control writing style"
|
|
>
|
|
<SelectValue>
|
|
{(value: SourceControlWritingStyleMode | null) =>
|
|
value === null ? "Mixed" : MODE_OPTIONS[value].label
|
|
}
|
|
</SelectValue>
|
|
</SelectTrigger>
|
|
<SelectPopup align="end" alignItemWithTrigger={false}>
|
|
{(Object.keys(MODE_OPTIONS) as SourceControlWritingStyleMode[]).map((mode) => (
|
|
<SelectItem key={mode} hideIndicator value={mode}>
|
|
{MODE_OPTIONS[mode].label}
|
|
</SelectItem>
|
|
))}
|
|
</SelectPopup>
|
|
</Select>
|
|
}
|
|
>
|
|
{writingStyleMixed ? (
|
|
<div className="mt-3 max-w-2xl space-y-2 pb-3.5">
|
|
{editingAllInstructions ? (
|
|
<>
|
|
<Textarea
|
|
value={allInstructions ?? ""}
|
|
onChange={(event) => setAllInstructions(event.target.value)}
|
|
rows={4}
|
|
aria-label="Custom source control instructions for all selected environments"
|
|
placeholder="Write the instructions each selected environment should use."
|
|
/>
|
|
<Button
|
|
size="sm"
|
|
variant="outline"
|
|
disabled={allInstructions === null}
|
|
onClick={() => {
|
|
if (allInstructions === null) return;
|
|
updateSettings({
|
|
sourceControlWritingStyle: {
|
|
mode: "custom",
|
|
customInstructions: allInstructions.trim(),
|
|
},
|
|
});
|
|
setEditingAllInstructions(false);
|
|
}}
|
|
>
|
|
Apply instructions to all
|
|
</Button>
|
|
</>
|
|
) : (
|
|
<Button
|
|
size="sm"
|
|
variant="outline"
|
|
onClick={() => {
|
|
setAllInstructions(null);
|
|
setEditingAllInstructions(true);
|
|
}}
|
|
>
|
|
Write custom instructions for all
|
|
</Button>
|
|
)}
|
|
</div>
|
|
) : style.mode === "custom" ? (
|
|
<div className="mt-3 max-w-2xl pb-3.5">
|
|
<Textarea
|
|
key={style.customInstructions}
|
|
ref={customInstructionsRef}
|
|
defaultValue={style.customInstructions}
|
|
onBlur={(event) => {
|
|
const customInstructions = event.target.value.trim();
|
|
if (customInstructions !== style.customInstructions) {
|
|
updateSettings({ sourceControlWritingStyle: { customInstructions } });
|
|
}
|
|
}}
|
|
rows={4}
|
|
placeholder="Keep titles concise. Use short bullet points in descriptions."
|
|
aria-label="Custom source control writing instructions"
|
|
/>
|
|
</div>
|
|
) : null}
|
|
</SettingsRow>
|
|
|
|
<SettingsRow
|
|
serverScoped
|
|
settingKeys={["sourceControlWritingStyle"]}
|
|
mixed={templatesMixed}
|
|
{...searchableSetting("follow-change-request-templates")}
|
|
description="Use the repository's template for change request descriptions when available."
|
|
resetAction={
|
|
templatesMixed ||
|
|
style.followChangeRequestTemplates !== defaults.followChangeRequestTemplates ? (
|
|
<SettingResetButton
|
|
label="change request templates"
|
|
onClick={() =>
|
|
updateSettings({
|
|
sourceControlWritingStyle: {
|
|
followChangeRequestTemplates: defaults.followChangeRequestTemplates,
|
|
},
|
|
})
|
|
}
|
|
/>
|
|
) : null
|
|
}
|
|
control={
|
|
<Switch
|
|
mixed={templatesMixed}
|
|
checked={templatesMixed ? false : style.followChangeRequestTemplates}
|
|
onCheckedChange={(checked) =>
|
|
updateSettings({
|
|
sourceControlWritingStyle: {
|
|
followChangeRequestTemplates: Boolean(checked),
|
|
},
|
|
})
|
|
}
|
|
aria-label="Follow change request templates"
|
|
/>
|
|
}
|
|
/>
|
|
|
|
<SettingsRow
|
|
serverScoped
|
|
settingKeys={["sourceControlWriterModelSelection"]}
|
|
{...searchableSetting("source-control-writer-model")}
|
|
description="Model for source control text and branch or bookmark names. Off uses the environment's text generation model."
|
|
control={
|
|
!hasServerTargets ? (
|
|
<span className="text-sm text-muted-foreground">
|
|
Connect an environment to choose its source control writer model.
|
|
</span>
|
|
) : (
|
|
<div className="flex flex-wrap items-center justify-end gap-2">
|
|
{usesDedicatedModel && !canEnableDedicatedModel ? (
|
|
<span className="text-sm text-muted-foreground">
|
|
No text generation providers available.
|
|
</span>
|
|
) : null}
|
|
{usesDedicatedModel && canEnableDedicatedModel ? (
|
|
<ProviderModelPicker
|
|
activeInstanceId={activeSelection.instanceId}
|
|
model={activeSelection.model}
|
|
lockedProvider={null}
|
|
instanceEntries={instanceEntries}
|
|
modelOptionsByInstance={modelOptionsByInstance}
|
|
triggerClassName={SETTINGS_PICKER_TRIGGER_CLASSNAME}
|
|
triggerAriaLabel="Source control writer model"
|
|
{...(mixedWriterModel ? { triggerLabel: "Mixed" } : {})}
|
|
{...(environmentId
|
|
? {
|
|
onOpenProviderSetup: (instanceId: ProviderInstanceId) => {
|
|
void navigate({
|
|
to: "/settings/providers",
|
|
search: { environmentId, instanceId },
|
|
});
|
|
},
|
|
}
|
|
: {})}
|
|
getModelDisabledReason={writerModelDisabledReason}
|
|
onInstanceModelChange={(instanceId, model) => {
|
|
const reason = writerModelDisabledReason(instanceId, model);
|
|
if (reason) {
|
|
toastManager.add({
|
|
type: "error",
|
|
title: "Source control writer model not saved",
|
|
description: reason,
|
|
});
|
|
return;
|
|
}
|
|
updateSettings({
|
|
sourceControlWriterModelSelection: createModelSelection(instanceId, model),
|
|
});
|
|
}}
|
|
/>
|
|
) : null}
|
|
<Switch
|
|
checked={usesDedicatedModel}
|
|
disabled={!usesDedicatedModel && !canEnableDedicatedModel}
|
|
onCheckedChange={(checked) =>
|
|
updateSettings({
|
|
sourceControlWriterModelSelection: checked
|
|
? createModelSelection(
|
|
defaultModelSelection.instanceId,
|
|
defaultModelSelection.model,
|
|
defaultModelSelection.options,
|
|
)
|
|
: null,
|
|
})
|
|
}
|
|
aria-label="Use a separate source control writer model"
|
|
/>
|
|
</div>
|
|
)
|
|
}
|
|
/>
|
|
</SettingsSection>
|
|
);
|
|
}
|