diff --git a/src/app/api/agent/route.ts b/src/app/api/agent/route.ts index 17fe4c7..df3ad05 100755 --- a/src/app/api/agent/route.ts +++ b/src/app/api/agent/route.ts @@ -37,6 +37,8 @@ export async function POST(req: Request): Promise { const currentPage = req.headers.get("x-current-page") ?? undefined + const timezone = + req.headers.get("x-timezone") ?? undefined const model = await getAgentModel() @@ -46,6 +48,7 @@ export async function POST(req: Request): Promise { userName: user.displayName ?? user.email, userRole: user.role, currentPage, + timezone, memories, pluginSections, mode: "full", diff --git a/src/hooks/use-compass-chat.ts b/src/hooks/use-compass-chat.ts index 4202664..25fe17d 100755 --- a/src/hooks/use-compass-chat.ts +++ b/src/hooks/use-compass-chat.ts @@ -33,7 +33,11 @@ export function useCompassChat(options?: UseCompassChatOptions) { const chatState = useChat({ transport: new DefaultChatTransport({ api: "/api/agent", - headers: { "x-current-page": pathname }, + headers: { + "x-current-page": pathname, + "x-timezone": + Intl.DateTimeFormat().resolvedOptions().timeZone, + }, }), onFinish: options?.onFinish, onError: (err) => { diff --git a/src/lib/agent/system-prompt.ts b/src/lib/agent/system-prompt.ts index aa88551..a560c9b 100755 --- a/src/lib/agent/system-prompt.ts +++ b/src/lib/agent/system-prompt.ts @@ -26,6 +26,7 @@ interface PromptContext { readonly userRole: string readonly currentPage?: string readonly memories?: string + readonly timezone?: string readonly pluginSections?: ReadonlyArray readonly mode?: PromptMode } @@ -216,11 +217,27 @@ function buildUserContext( state: DerivedState, ): ReadonlyArray { if (state.mode === "none") return [] + const tz = ctx.timezone ?? "UTC" + const now = new Date() + const date = now.toLocaleDateString("en-US", { + weekday: "long", + year: "numeric", + month: "long", + day: "numeric", + timeZone: tz, + }) + const time = now.toLocaleTimeString("en-US", { + hour: "2-digit", + minute: "2-digit", + timeZone: tz, + }) return [ "## User Context", `- Name: ${ctx.userName}`, `- Role: ${ctx.userRole}`, `- Current page: ${state.page}`, + `- Current date: ${date}`, + `- Current time: ${time} (${tz})`, ] }