Gateway: inject timestamps into agent/chat.send (#3705) (thanks @conroywhitney, @CashWilliams)
This commit is contained in:
@@ -18,6 +18,7 @@ Docs: https://docs.openclaw.ai
|
||||
- Auth: switch Kimi Coding to built-in provider; normalize OAuth profile email.
|
||||
- Auth: add MiniMax OAuth plugin + onboarding option. (#4521) Thanks @Maosghoul.
|
||||
- Agents: update pi SDK/API usage and dependencies.
|
||||
- Gateway: inject timestamps into agent and chat.send messages. (#3705) Thanks @conroywhitney, @CashWilliams.
|
||||
- Web UI: refresh sessions after chat commands and improve session display names.
|
||||
- Build: move TypeScript builds to `tsdown` + `tsgo` (faster builds, CI typechecks), update tsconfig target, and clean up lint rules.
|
||||
- Build: align npm tar override and bin metadata so the `openclaw` CLI entrypoint is preserved in npm publishes.
|
||||
|
||||
@@ -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