mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 16:38:27 +00:00
Heartbeat: inject cron-style current time into prompts (#13733)
* Heartbeat: inject cron-style current time into prompts * Tests: fix type for web heartbeat timestamp test * Infra: inline heartbeat current-time injection
This commit is contained in:
39
src/agents/current-time.ts
Normal file
39
src/agents/current-time.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
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}`;
|
||||
}
|
||||
Reference in New Issue
Block a user