mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 07:07:39 +00:00
71 lines
2.2 KiB
TypeScript
71 lines
2.2 KiB
TypeScript
import type { ThinkingLevel } from "@mariozechner/pi-agent-core";
|
|
import type { ReasoningLevel, ThinkLevel } from "../../auto-reply/thinking.js";
|
|
import type { ClawdbotConfig } from "../../config/config.js";
|
|
import type { ExecToolDefaults } from "../bash-tools.js";
|
|
|
|
export function mapThinkingLevel(level?: ThinkLevel): ThinkingLevel {
|
|
// pi-agent-core supports "xhigh"; Clawdbot enables it for specific models.
|
|
if (!level) return "off";
|
|
return level;
|
|
}
|
|
|
|
export function resolveExecToolDefaults(config?: ClawdbotConfig): ExecToolDefaults | undefined {
|
|
const tools = config?.tools;
|
|
if (!tools) return undefined;
|
|
if (!tools.exec) return tools.bash;
|
|
if (!tools.bash) return tools.exec;
|
|
return { ...tools.bash, ...tools.exec };
|
|
}
|
|
|
|
export function resolveUserTimezone(configured?: string): string {
|
|
const trimmed = configured?.trim();
|
|
if (trimmed) {
|
|
try {
|
|
new Intl.DateTimeFormat("en-US", { timeZone: trimmed }).format(new Date());
|
|
return trimmed;
|
|
} catch {
|
|
// ignore invalid timezone
|
|
}
|
|
}
|
|
const host = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
return host?.trim() || "UTC";
|
|
}
|
|
|
|
export function formatUserTime(date: Date, timeZone: string): string | undefined {
|
|
try {
|
|
const parts = new Intl.DateTimeFormat("en-CA", {
|
|
timeZone,
|
|
weekday: "long",
|
|
year: "numeric",
|
|
month: "2-digit",
|
|
day: "2-digit",
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
hourCycle: "h23",
|
|
}).formatToParts(date);
|
|
const map: Record<string, string> = {};
|
|
for (const part of parts) {
|
|
if (part.type !== "literal") map[part.type] = part.value;
|
|
}
|
|
if (!map.weekday || !map.year || !map.month || !map.day || !map.hour || !map.minute) {
|
|
return undefined;
|
|
}
|
|
return `${map.weekday} ${map.year}-${map.month}-${map.day} ${map.hour}:${map.minute}`;
|
|
} catch {
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
export function describeUnknownError(error: unknown): string {
|
|
if (error instanceof Error) return error.message;
|
|
if (typeof error === "string") return error;
|
|
try {
|
|
const serialized = JSON.stringify(error);
|
|
return serialized ?? "Unknown error";
|
|
} catch {
|
|
return "Unknown error";
|
|
}
|
|
}
|
|
|
|
export type { ReasoningLevel, ThinkLevel };
|