mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 13:26:04 -06:00
refactor: consolidate duplicate helper exports (#106016)
* refactor(normalization): consolidate string helpers * refactor(normalization): consolidate agent ids * refactor(paths): consolidate user path resolution * refactor(gateway): preserve transcript helper facade * fix(normalization): align helper build aliases * fix(memory): keep helper import line neutral * chore(plugin-sdk): align consolidated helper surface * refactor(normalization): reuse lowercase string helper * refactor(normalization): reuse record guard * refactor(normalization): share surrogate boundary helper * refactor(agents): share token estimate constant * refactor(memory): distinguish standalone helper contracts * refactor(normalization): share error cause formatter * refactor(config): distinguish eligibility predicates * refactor(plugins): share registry state symbol * refactor(cli): reuse outbound dependency adapter * refactor(cron): distinguish positive duration parser * fix(gateway): keep transcript helper private * fix(paths): preserve public helper status * refactor(channels): reuse registry normalizer * refactor(agents): reuse agent core runtime facade * refactor(auth): reuse locked profile upsert * refactor(records): distinguish trap-safe guard * refactor(migrations): distinguish sync directory helper * test(plugins): drop stale duration alias expectations * fix(channels): remove stale registry import * chore(plugin-sdk): refresh helper API baseline * fix(memory): keep renamed helpers private * fix(plugins): keep registry state key private * fix(plugin-sdk): tighten wildcard surface budget * chore(plugin-sdk): refresh rebased helper API baseline
This commit is contained in:
committed by
GitHub
parent
62e53919fd
commit
2aa4ff0825
@@ -21,7 +21,7 @@ import {
|
||||
parseCronCommandEnv,
|
||||
parseCronFallbacks,
|
||||
parseCronToolsAllow,
|
||||
parseDurationMs,
|
||||
parsePositiveCronDurationMs,
|
||||
warnIfCronSchedulerDisabled,
|
||||
} from "./shared.js";
|
||||
import { normalizeCronSessionTargetOption, parseCronThreadIdOption } from "./thread-id-shared.js";
|
||||
@@ -605,7 +605,7 @@ export function registerCronEditCommand(cron: Command) {
|
||||
failureAlert.to = to ? to : undefined;
|
||||
}
|
||||
if (hasFailureAlertCooldown) {
|
||||
const cooldownMs = parseDurationMs(String(opts.failureAlertCooldown));
|
||||
const cooldownMs = parsePositiveCronDurationMs(String(opts.failureAlertCooldown));
|
||||
if (!cooldownMs && cooldownMs !== 0) {
|
||||
throw new Error("Invalid --failure-alert-cooldown.");
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Shared schedule option resolver for cron create/edit commands.
|
||||
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
|
||||
import type { CronSchedule } from "../../cron/types.js";
|
||||
import { parseAt, parseCronStaggerMs, parseDurationMs } from "./shared.js";
|
||||
import { parseAt, parseCronStaggerMs, parsePositiveCronDurationMs } from "./shared.js";
|
||||
|
||||
type ScheduleOptionInput = {
|
||||
at?: unknown;
|
||||
@@ -169,7 +169,7 @@ function resolveDirectSchedule(options: NormalizedScheduleOptions): CronSchedule
|
||||
return { kind: "at", at: atIso };
|
||||
}
|
||||
if (options.every) {
|
||||
const everyMs = parseDurationMs(options.every);
|
||||
const everyMs = parsePositiveCronDurationMs(options.every);
|
||||
if (!everyMs) {
|
||||
throw new Error("Invalid --every. Use a duration like 10m, 1h, or 1d.");
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
getCronChannelOptions,
|
||||
parseAt,
|
||||
parseCronToolsAllow,
|
||||
parseDurationMs,
|
||||
parsePositiveCronDurationMs,
|
||||
printCronList,
|
||||
printCronShow,
|
||||
} from "./shared.js";
|
||||
@@ -526,29 +526,29 @@ describe("coerceCronDeliveryPreviews", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("parseDurationMs", () => {
|
||||
describe("parsePositiveCronDurationMs", () => {
|
||||
it("parses valid positive durations", () => {
|
||||
expect(parseDurationMs("500ms")).toBe(500);
|
||||
expect(parseDurationMs("30s")).toBe(30_000);
|
||||
expect(parseDurationMs("1.5h")).toBe(5_400_000);
|
||||
expect(parseDurationMs("1h30m")).toBe(5_400_000);
|
||||
expect(parseDurationMs("1d")).toBe(86_400_000);
|
||||
expect(parsePositiveCronDurationMs("500ms")).toBe(500);
|
||||
expect(parsePositiveCronDurationMs("30s")).toBe(30_000);
|
||||
expect(parsePositiveCronDurationMs("1.5h")).toBe(5_400_000);
|
||||
expect(parsePositiveCronDurationMs("1h30m")).toBe(5_400_000);
|
||||
expect(parsePositiveCronDurationMs("1d")).toBe(86_400_000);
|
||||
});
|
||||
|
||||
it("rejects non-positive and malformed durations", () => {
|
||||
expect(parseDurationMs("0s")).toBeNull();
|
||||
expect(parseDurationMs("0.5ms")).toBe(1);
|
||||
expect(parseDurationMs("0.001ms")).toBeNull();
|
||||
expect(parseDurationMs("-5s")).toBeNull();
|
||||
expect(parseDurationMs("abc")).toBeNull();
|
||||
expect(parseDurationMs("")).toBeNull();
|
||||
expect(parsePositiveCronDurationMs("0s")).toBeNull();
|
||||
expect(parsePositiveCronDurationMs("0.5ms")).toBe(1);
|
||||
expect(parsePositiveCronDurationMs("0.001ms")).toBeNull();
|
||||
expect(parsePositiveCronDurationMs("-5s")).toBeNull();
|
||||
expect(parsePositiveCronDurationMs("abc")).toBeNull();
|
||||
expect(parsePositiveCronDurationMs("")).toBeNull();
|
||||
});
|
||||
|
||||
it("rejects durations that overflow to a non-finite millisecond value (#83906)", () => {
|
||||
// A finite mantissa can still overflow once multiplied by a large unit factor.
|
||||
expect(parseDurationMs(`1${"0".repeat(302)}d`)).toBeNull();
|
||||
expect(parsePositiveCronDurationMs(`1${"0".repeat(302)}d`)).toBeNull();
|
||||
// A large-but-finite result is still accepted.
|
||||
expect(parseDurationMs(`9${"0".repeat(15)}ms`)).toBe(9_000_000_000_000_000);
|
||||
expect(parsePositiveCronDurationMs(`9${"0".repeat(15)}ms`)).toBe(9_000_000_000_000_000);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -220,7 +220,7 @@ export async function warnIfCronSchedulerDisabled(opts: GatewayRpcOpts) {
|
||||
}
|
||||
}
|
||||
|
||||
export function parseDurationMs(input: string): number | null {
|
||||
export function parsePositiveCronDurationMs(input: string): number | null {
|
||||
try {
|
||||
const result = parseSharedDurationMs(input);
|
||||
if (result <= 0) {
|
||||
@@ -242,7 +242,7 @@ export function parseCronStaggerMs(params: {
|
||||
if (!params.staggerRaw) {
|
||||
return undefined;
|
||||
}
|
||||
const parsed = parseDurationMs(params.staggerRaw);
|
||||
const parsed = parsePositiveCronDurationMs(params.staggerRaw);
|
||||
if (!parsed) {
|
||||
throw new Error("Invalid --stagger; use e.g. 30s, 1m, 5m");
|
||||
}
|
||||
@@ -301,7 +301,7 @@ export function parseAt(input: string, tz?: string): string | null {
|
||||
return timestampMsToIsoString(absolute) ?? null;
|
||||
}
|
||||
const durationInput = raw.startsWith("+") ? raw.slice(1) : raw;
|
||||
const dur = parseDurationMs(durationInput);
|
||||
const dur = parsePositiveCronDurationMs(durationInput);
|
||||
if (dur !== null) {
|
||||
const expiresAt = resolveExpiresAtMsFromDurationMs(dur);
|
||||
return timestampMsToIsoString(expiresAt) ?? null;
|
||||
|
||||
+2
-8
@@ -1,12 +1,8 @@
|
||||
// Default CLI dependency surface with lazy outbound channel send adapters.
|
||||
import { normalizeChannelId } from "../channels/registry.js";
|
||||
import type { OutboundSendDeps } from "../infra/outbound/send-deps.js";
|
||||
import { createLazyRuntimeSurface } from "../shared/lazy-runtime.js";
|
||||
import type { CliDeps } from "./deps.types.js";
|
||||
import {
|
||||
CLI_OUTBOUND_SEND_FACTORY,
|
||||
createOutboundSendDepsFromCliSource,
|
||||
} from "./outbound-send-mapping.js";
|
||||
import { CLI_OUTBOUND_SEND_FACTORY } from "./outbound-send-mapping.js";
|
||||
|
||||
/**
|
||||
* Lazy-loaded per-channel send functions, keyed by channel ID.
|
||||
@@ -118,6 +114,4 @@ export function createDefaultDeps(): CliDeps {
|
||||
});
|
||||
}
|
||||
|
||||
export function createOutboundSendDeps(deps: CliDeps): OutboundSendDeps {
|
||||
return createOutboundSendDepsFromCliSource(deps);
|
||||
}
|
||||
export { createOutboundSendDeps } from "./outbound-send-deps.js";
|
||||
|
||||
Reference in New Issue
Block a user