This commit is contained in:
@@ -25,7 +25,8 @@ const ADD_CALENDAR_EVENT_DEF: ToolDef = {
|
||||
title: { type: 'string', description: '予定のタイトル(必須)' },
|
||||
date: { type: 'string', description: '開始日 YYYY-MM-DD(ローカル日付、必須)' },
|
||||
end_date: { type: 'string', description: '終了日 YYYY-MM-DD。複数日にまたがる予定のとき指定。省略すると単日' },
|
||||
time: { type: 'string', description: 'HH:MM。省略すると終日扱い' },
|
||||
time: { type: 'string', description: '開始 HH:MM。省略すると終日扱い' },
|
||||
end_time: { type: 'string', description: '終了 HH:MM。time(開始)があるときのみ有効。単日は開始以降のみ' },
|
||||
description: { type: 'string', description: '予定の補足説明(任意)' },
|
||||
},
|
||||
required: ['title', 'date'],
|
||||
@@ -84,6 +85,7 @@ async function executeAddCalendarEvent(
|
||||
const date = input['date'];
|
||||
const endDateInput = input['end_date'];
|
||||
const time = input['time'];
|
||||
const endTimeInput = input['end_time'];
|
||||
const description = input['description'];
|
||||
|
||||
if (typeof title !== 'string' || !title.trim()) {
|
||||
@@ -105,11 +107,26 @@ async function executeAddCalendarEvent(
|
||||
}
|
||||
endDate = endDateInput;
|
||||
}
|
||||
const startTime = typeof time === 'string' && time !== '' ? time : null;
|
||||
if (time !== undefined && time !== null && time !== '') {
|
||||
if (typeof time !== 'string' || !TIME_PATTERN.test(time)) {
|
||||
return { output: 'time は HH:MM 形式で指定してください', isError: true };
|
||||
}
|
||||
}
|
||||
let endTime: string | null = null;
|
||||
if (endTimeInput !== undefined && endTimeInput !== null && endTimeInput !== '') {
|
||||
if (typeof endTimeInput !== 'string' || !TIME_PATTERN.test(endTimeInput)) {
|
||||
return { output: 'end_time は HH:MM 形式で指定してください', isError: true };
|
||||
}
|
||||
if (startTime == null) {
|
||||
return { output: 'end_time は time(開始時刻)とあわせて指定してください', isError: true };
|
||||
}
|
||||
const multiDay = endDate != null && endDate > date;
|
||||
if (!multiDay && endTimeInput < startTime) {
|
||||
return { output: 'end_time は開始時刻以降にしてください(単日の予定)', isError: true };
|
||||
}
|
||||
endTime = endTimeInput;
|
||||
}
|
||||
if (description !== undefined && description !== null) {
|
||||
if (typeof description !== 'string') {
|
||||
return { output: 'description は文字列で指定してください', isError: true };
|
||||
@@ -125,14 +142,16 @@ async function executeAddCalendarEvent(
|
||||
ownerId: ctx.ownerId ?? null,
|
||||
date,
|
||||
endDate,
|
||||
time: typeof time === 'string' && time !== '' ? time : null,
|
||||
time: startTime,
|
||||
endTime,
|
||||
title: title.trim(),
|
||||
description: typeof description === 'string' ? description : null,
|
||||
createdBy: 'agent',
|
||||
sourceTaskId: Number.isFinite(sourceTaskId) ? sourceTaskId : null,
|
||||
});
|
||||
const timeLabel = ev.time ? (ev.endTime ? `${ev.time}–${ev.endTime}` : ev.time) : '(終日)';
|
||||
return {
|
||||
output: `予定を追加しました: ${ev.date}${ev.time ? ` ${ev.time}` : '(終日)'} 「${ev.title}」(id=${ev.id})`,
|
||||
output: `予定を追加しました: ${ev.date}${ev.endDate ? `–${ev.endDate}` : ''} ${timeLabel} 「${ev.title}」(id=${ev.id})`,
|
||||
isError: false,
|
||||
};
|
||||
}
|
||||
@@ -166,8 +185,9 @@ async function executeListCalendarEvents(
|
||||
if (events.length === 0) {
|
||||
return { output: '指定範囲に予定はありません', isError: false };
|
||||
}
|
||||
const lines = events.map(
|
||||
(e) => `- ${e.date}${e.time ? ` ${e.time}` : '(終日)'} 「${e.title}」(id=${e.id}, ${e.createdBy})`,
|
||||
);
|
||||
const lines = events.map((e) => {
|
||||
const timeLabel = e.time ? (e.endTime ? `${e.time}–${e.endTime}` : e.time) : '(終日)';
|
||||
return `- ${e.date}${e.endDate ? `–${e.endDate}` : ''} ${timeLabel} 「${e.title}」(id=${e.id}, ${e.createdBy})`;
|
||||
});
|
||||
return { output: lines.join('\n'), isError: false };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user