@lightcone-ai/daemon 0.15.0 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
function normalizeInteger(value, fallback = null) {
|
|
2
|
+
const parsed = Number.parseInt(String(value ?? ''), 10);
|
|
3
|
+
if (!Number.isFinite(parsed)) return fallback;
|
|
4
|
+
return parsed;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function resolveDurationMs(phase, fallback = 0) {
|
|
8
|
+
const parsed = normalizeInteger(phase?.duration_ms, null);
|
|
9
|
+
if (parsed !== null && parsed >= 0) return parsed;
|
|
10
|
+
|
|
11
|
+
const dwellMs = normalizeInteger(phase?.dwell_ms, null);
|
|
12
|
+
if (dwellMs !== null && dwellMs >= 0) return dwellMs;
|
|
13
|
+
|
|
14
|
+
const secs = Number(phase?.duration_s);
|
|
15
|
+
if (Number.isFinite(secs) && secs >= 0) return Math.round(secs * 1000);
|
|
16
|
+
|
|
17
|
+
return fallback;
|
|
18
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { resolveDurationMs } from './phase-duration.js';
|
|
2
|
+
import { normalizePlanPhases } from './plan-executor.js';
|
|
3
|
+
|
|
4
|
+
export function estimatePlanDurationMs(plan = {}) {
|
|
5
|
+
let phases = [];
|
|
6
|
+
try {
|
|
7
|
+
phases = normalizePlanPhases(plan);
|
|
8
|
+
} catch {
|
|
9
|
+
phases = [];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return phases.reduce((total, phase) => {
|
|
13
|
+
const action = String(phase?.action ?? phase?.visual_action?.type ?? '').trim().toLowerCase();
|
|
14
|
+
const durationMs = resolveDurationMs(phase, Number.NaN);
|
|
15
|
+
const dwellMs = Number(phase?.dwell_ms);
|
|
16
|
+
const transitionMs = Number(phase?.transition_ms ?? phase?.visual_action?.transition_ms);
|
|
17
|
+
const effectiveHoldMs = Number.isFinite(dwellMs) && dwellMs > 0
|
|
18
|
+
? dwellMs
|
|
19
|
+
: durationMs;
|
|
20
|
+
|
|
21
|
+
if (action === 'hold' && Number.isFinite(effectiveHoldMs) && effectiveHoldMs > 0) {
|
|
22
|
+
return total + effectiveHoldMs;
|
|
23
|
+
}
|
|
24
|
+
if (action === 'linear_scroll_during') {
|
|
25
|
+
if (Number.isFinite(effectiveHoldMs) && effectiveHoldMs > 0) return total + effectiveHoldMs;
|
|
26
|
+
return total + 1200;
|
|
27
|
+
}
|
|
28
|
+
if (action === 'scroll_to_dwell' || action === 'cursor_focus' || action === 'scroll_back') {
|
|
29
|
+
let next = total;
|
|
30
|
+
if (Number.isFinite(transitionMs) && transitionMs > 0) next += transitionMs;
|
|
31
|
+
if (Number.isFinite(effectiveHoldMs) && effectiveHoldMs > 0) next += effectiveHoldMs;
|
|
32
|
+
if (next === total) next += 1200;
|
|
33
|
+
return next;
|
|
34
|
+
}
|
|
35
|
+
if (Number.isFinite(transitionMs) && transitionMs > 0) {
|
|
36
|
+
return total + transitionMs;
|
|
37
|
+
}
|
|
38
|
+
if (Number.isFinite(durationMs) && durationMs > 0) {
|
|
39
|
+
return total + durationMs;
|
|
40
|
+
}
|
|
41
|
+
return total + 800;
|
|
42
|
+
}, 0);
|
|
43
|
+
}
|