@v587d/capital-generation 2.12.0 → 2.13.0

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.
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Settings resolution at call time, in the documented order:
3
+ * code defaults -> deployment row values -> current profile user settings -> task override.
4
+ * The task override is applied by the task record, not here.
5
+ */
6
+ import { readCapitalEntry } from '../lib/capital-settings.js'
7
+ import {
8
+ DEFAULT_AUTOMATION_SETTINGS,
9
+ MAX_IDLE_TIMEOUT_MINUTES,
10
+ MAX_MAX_STEPS,
11
+ MAX_MAX_TOOL_CALLS,
12
+ MAX_RUN_TIMEOUT_MINUTES,
13
+ MAX_TICK_MS,
14
+ MIN_IDLE_TIMEOUT_MINUTES,
15
+ MIN_MAX_STEPS,
16
+ MIN_MAX_TOOL_CALLS,
17
+ MIN_RUN_TIMEOUT_MINUTES,
18
+ MIN_TICK_MS,
19
+ } from './defaults.js'
20
+
21
+ function intIn(value, minimum, maximum, fallback) {
22
+ const number = typeof value === 'number' ? value : Number(value)
23
+ if (!Number.isFinite(number)) return fallback
24
+ return Math.min(maximum, Math.max(minimum, Math.round(number)))
25
+ }
26
+
27
+ export function normalizeAutomationSettings(value = {}, fallback = DEFAULT_AUTOMATION_SETTINGS) {
28
+ const source = value ?? {}
29
+ return {
30
+ tickMs: intIn(source.tickMs, MIN_TICK_MS, MAX_TICK_MS, fallback.tickMs),
31
+ runTimeoutMinutes: intIn(source.runTimeoutMinutes, MIN_RUN_TIMEOUT_MINUTES, MAX_RUN_TIMEOUT_MINUTES, fallback.runTimeoutMinutes),
32
+ idleTimeoutMinutes: intIn(source.idleTimeoutMinutes, MIN_IDLE_TIMEOUT_MINUTES, MAX_IDLE_TIMEOUT_MINUTES, fallback.idleTimeoutMinutes),
33
+ maxSteps: intIn(source.maxSteps, MIN_MAX_STEPS, MAX_MAX_STEPS, fallback.maxSteps),
34
+ maxToolCalls: intIn(source.maxToolCalls, MIN_MAX_TOOL_CALLS, MAX_MAX_TOOL_CALLS, fallback.maxToolCalls),
35
+ inAppNotifications: source.inAppNotifications === undefined ? fallback.inAppNotifications : source.inAppNotifications !== false,
36
+ }
37
+ }
38
+
39
+ export function resolveAutomationSettings(ctx, deployment = {}) {
40
+ let user
41
+ try {
42
+ user = readCapitalEntry(ctx).value?.automation
43
+ } catch {
44
+ user = undefined
45
+ }
46
+ const deployed = normalizeAutomationSettings(deployment)
47
+ return normalizeAutomationSettings(user, deployed)
48
+ }