Files
archived-gitea-ai-assistant/src/utils/global-prompt.ts
jeffusion d5deb75231 feat(repo): add project-level review prompt with UI redesign
- Add database migration and repository for project review prompts
- Add API endpoint for setting project-level prompts
- Integrate project prompts into Agent and Codex review flows
- Redesign repository management UI with dialog-based prompt editor
- Replace flat buttons with Switch for webhook toggle and dedicated prompt button
- Add Dialog and DropdownMenu UI components from Radix UI
- Add comprehensive tests for wiring and interactions
2026-03-26 13:35:05 +08:00

43 lines
1.2 KiB
TypeScript

/**
* Helper to inject the global prompt into LLM system messages.
*
* If globalPrompt is non-empty, it is appended to the original system content
* separated by a blank line. Otherwise the original content is returned as-is.
*/
export function withGlobalPrompt(systemContent: string, globalPrompt: string | undefined): string {
if (!globalPrompt || globalPrompt.trim() === '') {
return systemContent;
}
return `${systemContent}\n\n${globalPrompt}`;
}
export function mergeReviewPrompts(
globalPrompt: string | undefined,
projectPrompt: string | undefined
): string | undefined {
const normalized = [globalPrompt, projectPrompt]
.map((item) => item?.trim())
.filter((item): item is string => !!item && item.length > 0);
if (normalized.length === 0) {
return undefined;
}
return normalized.join('\n\n');
}
export function withCoreGlobalPrompt(
systemContent: string,
globalPrompt: string | undefined,
maxChars?: number
): string {
if (!globalPrompt || globalPrompt.trim() === '') {
return systemContent;
}
const normalized = globalPrompt.trim();
const compact =
typeof maxChars === 'number' && maxChars > 0 ? normalized.slice(0, maxChars) : normalized;
return `${systemContent}\n\n${compact}`;
}