mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 00:50:28 +00:00
Gateway: inject timestamps into agent/chat.send (#3705) (thanks @conroywhitney, @CashWilliams)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { resolveUserTimezone } from "../../agents/date-time.js";
|
||||
import { formatZonedTimestamp } from "../../auto-reply/envelope.js";
|
||||
import type { MoltbotConfig } from "../../config/types.js";
|
||||
import type { OpenClawConfig } from "../../config/types.js";
|
||||
|
||||
/**
|
||||
* Cron jobs inject "Current time: ..." into their messages.
|
||||
@@ -39,19 +39,27 @@ export interface TimestampInjectionOptions {
|
||||
* @see https://github.com/moltbot/moltbot/issues/3658
|
||||
*/
|
||||
export function injectTimestamp(message: string, opts?: TimestampInjectionOptions): string {
|
||||
if (!message.trim()) return message;
|
||||
if (!message.trim()) {
|
||||
return message;
|
||||
}
|
||||
|
||||
// Already has an envelope or injected timestamp
|
||||
if (TIMESTAMP_ENVELOPE_PATTERN.test(message)) return message;
|
||||
if (TIMESTAMP_ENVELOPE_PATTERN.test(message)) {
|
||||
return message;
|
||||
}
|
||||
|
||||
// Already has a cron-injected timestamp
|
||||
if (CRON_TIME_PATTERN.test(message)) return message;
|
||||
if (CRON_TIME_PATTERN.test(message)) {
|
||||
return message;
|
||||
}
|
||||
|
||||
const now = opts?.now ?? new Date();
|
||||
const timezone = opts?.timezone ?? "UTC";
|
||||
|
||||
const formatted = formatZonedTimestamp(now, timezone);
|
||||
if (!formatted) return message;
|
||||
if (!formatted) {
|
||||
return message;
|
||||
}
|
||||
|
||||
// 3-letter DOW: small models (8B) can't reliably derive day-of-week from
|
||||
// a date, and may treat a bare "Wed" as a typo. Costs ~1 token.
|
||||
@@ -63,9 +71,9 @@ export function injectTimestamp(message: string, opts?: TimestampInjectionOption
|
||||
}
|
||||
|
||||
/**
|
||||
* Build TimestampInjectionOptions from a MoltbotConfig.
|
||||
* Build TimestampInjectionOptions from an OpenClawConfig.
|
||||
*/
|
||||
export function timestampOptsFromConfig(cfg: MoltbotConfig): TimestampInjectionOptions {
|
||||
export function timestampOptsFromConfig(cfg: OpenClawConfig): TimestampInjectionOptions {
|
||||
return {
|
||||
timezone: resolveUserTimezone(cfg.agents?.defaults?.userTimezone),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user