29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
const URL_RE = /\bhttps?:\/\/[^\s<>"')\]]+|\bwww\.[^\s<>"')\]]+/gi;
|
|
|
|
export function stripUrlsForTitle(input: string): string {
|
|
return input.replace(URL_RE, '[URL]').replace(/\s+/g, ' ').trim();
|
|
}
|
|
|
|
export function isUrlOnlyTitleInput(input: string): boolean {
|
|
const trimmed = input.trim();
|
|
if (!trimmed) return false;
|
|
return stripUrlsForTitle(trimmed).replace(/\[URL\]/g, '').trim().length === 0;
|
|
}
|
|
|
|
export function buildTitleFallback(input: string): string {
|
|
if (isUrlOnlyTitleInput(input)) return 'URLの確認';
|
|
return stripUrlsForTitle(input).slice(0, 40).trim() || '新しい依頼';
|
|
}
|
|
|
|
export function buildTitlePrompt(input: string): string | null {
|
|
if (isUrlOnlyTitleInput(input)) return null;
|
|
const sanitized = stripUrlsForTitle(input).slice(0, 500);
|
|
return [
|
|
'以下の依頼内容から20文字以内の簡潔なタイトルを日本語で生成してください。',
|
|
'URLそのものから内容を推測しないでください。URLは必要なら「URL」として扱ってください。',
|
|
'タイトルのみ出力してください。',
|
|
'',
|
|
sanitized,
|
|
].join('\n');
|
|
}
|