mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-07-10 16:23:44 +00:00
Server-side resolution of {{current_date}} and {{current_datetime}} for
agent instructions used the server's timezone, so agents received UTC
instead of the user's local time the variables are documented to provide.
The browser's IANA timezone is now sent with each request and threaded
through replaceSpecialVars, anchoring those variables to the user's local
wall clock. {{iso_datetime}} stays UTC. Invalid or missing zones fall back
to the previous behavior.
58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
import type * as t from './types';
|
|
import { EndpointURLs } from './config';
|
|
import * as s from './schemas';
|
|
|
|
/** Resolves the browser's IANA timezone so the server can localize prompt variables. */
|
|
function getUserTimezone(): string | undefined {
|
|
try {
|
|
return Intl.DateTimeFormat().resolvedOptions().timeZone || undefined;
|
|
} catch {
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
export default function createPayload(submission: t.TSubmission) {
|
|
const {
|
|
isEdited,
|
|
addedConvo,
|
|
userMessage,
|
|
isContinued,
|
|
isTemporary,
|
|
isRegenerate,
|
|
conversation,
|
|
editedContent,
|
|
ephemeralAgent,
|
|
endpointOption,
|
|
manualSkills,
|
|
} = submission;
|
|
const { conversationId } = s.tConvoUpdateSchema.parse(conversation);
|
|
const { endpoint: _e, endpointType } = endpointOption as {
|
|
endpoint: s.EModelEndpoint;
|
|
endpointType?: s.EModelEndpoint;
|
|
};
|
|
|
|
const endpoint = _e as s.EModelEndpoint;
|
|
let server = `${EndpointURLs[s.EModelEndpoint.agents]}/${endpoint}`;
|
|
if (s.isAssistantsEndpoint(endpoint)) {
|
|
server =
|
|
EndpointURLs[(endpointType ?? endpoint) as 'assistants' | 'azureAssistants'] +
|
|
(isEdited ? '/modify' : '');
|
|
}
|
|
|
|
const payload: t.TPayload = {
|
|
...userMessage,
|
|
...endpointOption,
|
|
endpoint,
|
|
addedConvo,
|
|
isTemporary,
|
|
isRegenerate,
|
|
editedContent,
|
|
conversationId,
|
|
isContinued: !!(isEdited && isContinued),
|
|
ephemeralAgent: s.isAssistantsEndpoint(endpoint) ? undefined : ephemeralAgent,
|
|
manualSkills: s.isAssistantsEndpoint(endpoint) ? undefined : manualSkills,
|
|
timezone: getUserTimezone(),
|
|
};
|
|
|
|
return { server, payload };
|
|
}
|