fix(agent): raise tool rounds and ease calendar creates
CI / checks (push) Has been cancelled

Local models were burning the 8-round budget on simple event adds.
Raise the limit, resolve calendars by name/default, and inject the
household clock so relative dates work.
This commit is contained in:
ginnoir
2026-07-08 21:40:44 -05:00
parent ea371b8085
commit d3e79edb9e
7 changed files with 240 additions and 10 deletions
+47 -1
View File
@@ -111,8 +111,11 @@ async function dispatchTool(
return callApi(request, origin, "GET", `/api/v1/events?${qs.toString()}`);
}
case "create_event": {
const resolved = await resolveCalendarId(args, request, origin);
if ("error" in resolved) return resolved.error;
const body: Record<string, unknown> = {
calendarId: requireString(args, "calendarId"),
calendarId: resolved.calendarId,
title: requireString(args, "title"),
startAt: requireString(args, "startAt"),
endAt: requireString(args, "endAt"),
@@ -375,6 +378,49 @@ async function dispatchTool(
}
}
async function resolveCalendarId(
args: Record<string, unknown>,
request: Request,
origin: string,
): Promise<{ calendarId: string } | { error: ApiCallResult }> {
const calendarId = typeof args.calendarId === "string" ? args.calendarId.trim() : "";
if (calendarId) return { calendarId };
const calendarsResult = await callApi(request, origin, "GET", "/api/v1/calendars");
if (calendarsResult.status !== 200 || !Array.isArray(calendarsResult.body)) {
return { error: calendarsResult };
}
const calendars = calendarsResult.body as Array<{ id?: string; name?: string }>;
const calendarName =
typeof args.calendarName === "string" ? args.calendarName.trim().toLowerCase() : "";
if (calendarName) {
const match = calendars.find(
(calendar) =>
typeof calendar.name === "string" && calendar.name.toLowerCase() === calendarName,
);
if (!match?.id) {
return {
error: {
status: 404,
body: {
error: `No calendar named "${args.calendarName}"`,
calendars: calendars.map((calendar) => ({ id: calendar.id, name: calendar.name })),
},
},
};
}
return { calendarId: match.id };
}
const first = calendars[0];
if (!first?.id) {
return { error: { status: 404, body: { error: "No calendars found" } } };
}
return { calendarId: first.id };
}
function requireString(args: Record<string, unknown>, key: string): string {
const value = args[key];
if (typeof value !== "string" || value.trim().length === 0) {