feat(agent): localize date/time in system prompt (#45)

Send the user's IANA timezone (Intl API) as x-timezone header
from the chat transport. The system prompt now formats date
and time in the user's local timezone instead of UTC.

Co-authored-by: Nicholai <nicholaivogelfilms@gmail.com>
This commit is contained in:
Nicholai 2026-02-06 18:08:16 -07:00 committed by GitHub
parent 3e5b351b19
commit f8faabd508
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 1 deletions

View File

@ -37,6 +37,8 @@ export async function POST(req: Request): Promise<Response> {
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<Response> {
userName: user.displayName ?? user.email,
userRole: user.role,
currentPage,
timezone,
memories,
pluginSections,
mode: "full",

View File

@ -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) => {

View File

@ -26,6 +26,7 @@ interface PromptContext {
readonly userRole: string
readonly currentPage?: string
readonly memories?: string
readonly timezone?: string
readonly pluginSections?: ReadonlyArray<PromptSection>
readonly mode?: PromptMode
}
@ -216,11 +217,27 @@ function buildUserContext(
state: DerivedState,
): ReadonlyArray<string> {
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})`,
]
}