11// Phone Control plugin entrypoint registers its OpenClaw integration.
22import { randomUUID } from "node:crypto" ;
3+ import milliseconds from "ms" ;
34import {
45 asDateTimestampMs ,
56 resolveExpiresAtMsFromDurationMs ,
@@ -10,6 +11,7 @@ import {
1011 normalizeStringEntries ,
1112 sortUniqueStrings ,
1213} from "openclaw/plugin-sdk/string-coerce-runtime" ;
14+ import prettyMilliseconds from "pretty-ms" ;
1315import {
1416 definePluginEntry ,
1517 type OpenClawPluginApi ,
@@ -94,38 +96,20 @@ function formatGroupList(): string {
9496
9597function parseDurationMs ( input : string | undefined ) : number | null {
9698 const raw = normalizeOptionalLowercaseString ( input ) ;
97- if ( ! raw ) {
99+ if ( ! raw || ! / ^ \d + (?: \. \d + ) ? (?: m s | s | m | h | d ) $ / . test ( raw ) ) {
98100 return null ;
99101 }
100- const m = raw . match ( / ^ ( \d + ) ( s | m | h | d ) $ / ) ;
101- if ( ! m ) {
102- return null ;
103- }
104- const n = Number . parseInt ( m [ 1 ] ?? "" , 10 ) ;
105- if ( ! Number . isFinite ( n ) || n <= 0 ) {
106- return null ;
107- }
108- const unit = m [ 2 ] ;
109- const mult = unit === "s" ? 1000 : unit === "m" ? 60_000 : unit === "h" ? 3_600_000 : 86_400_000 ;
110- const durationMs = n * mult ;
111- return Number . isSafeInteger ( durationMs ) ? durationMs : null ;
102+ const durationMs = milliseconds ( raw as Parameters < typeof milliseconds > [ 0 ] ) ;
103+ return Number . isSafeInteger ( durationMs ) && durationMs > 0 ? durationMs : null ;
112104}
113105
114106function formatDuration ( ms : number ) : string {
115- const s = Math . max ( 0 , Math . floor ( ms / 1000 ) ) ;
116- if ( s < 60 ) {
117- return `${ s } s` ;
118- }
119- const m = Math . floor ( s / 60 ) ;
120- if ( m < 60 ) {
121- return `${ m } m` ;
122- }
123- const h = Math . floor ( m / 60 ) ;
124- if ( h < 48 ) {
125- return `${ h } h` ;
126- }
127- const d = Math . floor ( h / 24 ) ;
128- return `${ d } d` ;
107+ const roundedMs = ms < 1000 ? Math . round ( ms ) : Math . round ( ms / 1000 ) * 1000 ;
108+ return prettyMilliseconds ( Math . max ( 0 , roundedMs ) , {
109+ compact : true ,
110+ hideYear : true ,
111+ secondsDecimalDigits : 0 ,
112+ } ) ;
129113}
130114
131115function openArmStateStore ( api : OpenClawPluginApi ) {
0 commit comments