🕐 fix: Use client timezone for special variable date formatting

`replaceSpecialVars` uses `dayjs()` which defaults to the server's
timezone (UTC in Docker), causing `{{current_datetime}}` and
`{{current_date}}` to always show +00:00 regardless of the user's
location. This is inconsistent with `append_current_datetime` for
assistants which already handles client timezone via `clientTimestamp`.

Add dayjs timezone plugin support and a `timezone` parameter to
`replaceSpecialVars`. The client sends its IANA timezone string
(`Intl.DateTimeFormat().resolvedOptions().timeZone`) alongside the
existing `clientTimestamp`, and the agent initialization flow passes
it through to produce timezone-aware date formatting.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lionel Ringenbach 2026-03-27 00:02:26 -07:00
parent f277b32030
commit 736960e0a4
6 changed files with 86 additions and 4 deletions

View file

@ -403,6 +403,7 @@ export async function initializeAgent(
agent.instructions = replaceSpecialVars({
text: agent.instructions,
user: req.user ? (req.user as unknown as TUser) : null,
timezone: req.body?.clientTimezone,
});
}

View file

@ -16,6 +16,7 @@ export type RequestBody = {
model?: string;
key?: string;
endpointOption?: Partial<TEndpointOption>;
clientTimezone?: string;
};
export type ServerRequest = Request<unknown, unknown, RequestBody> & {