mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-13 19:10:39 +00:00
* Heartbeat: inject cron-style current time into prompts * Tests: fix type for web heartbeat timestamp test * Infra: inline heartbeat current-time injection
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import {
|
|
type TimeFormatPreference,
|
|
formatUserTime,
|
|
resolveUserTimeFormat,
|
|
resolveUserTimezone,
|
|
} from "./date-time.js";
|
|
|
|
export type CronStyleNow = {
|
|
userTimezone: string;
|
|
formattedTime: string;
|
|
timeLine: string;
|
|
};
|
|
|
|
type TimeConfigLike = {
|
|
agents?: {
|
|
defaults?: {
|
|
userTimezone?: string;
|
|
timeFormat?: TimeFormatPreference;
|
|
};
|
|
};
|
|
};
|
|
|
|
export function resolveCronStyleNow(cfg: TimeConfigLike, nowMs: number): CronStyleNow {
|
|
const userTimezone = resolveUserTimezone(cfg.agents?.defaults?.userTimezone);
|
|
const userTimeFormat = resolveUserTimeFormat(cfg.agents?.defaults?.timeFormat);
|
|
const formattedTime =
|
|
formatUserTime(new Date(nowMs), userTimezone, userTimeFormat) ?? new Date(nowMs).toISOString();
|
|
const timeLine = `Current time: ${formattedTime} (${userTimezone})`;
|
|
return { userTimezone, formattedTime, timeLine };
|
|
}
|
|
|
|
export function appendCronStyleCurrentTimeLine(text: string, cfg: TimeConfigLike, nowMs: number) {
|
|
const base = text.trimEnd();
|
|
if (!base || base.includes("Current time:")) {
|
|
return base;
|
|
}
|
|
const { timeLine } = resolveCronStyleNow(cfg, nowMs);
|
|
return `${base}\n${timeLine}`;
|
|
}
|