forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDesktopAutomationBridge+RealtimeHub.swift
More file actions
68 lines (64 loc) · 2.89 KB
/
Copy pathDesktopAutomationBridge+RealtimeHub.swift
File metadata and controls
68 lines (64 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import Foundation
/// Realtime-hub automation actions (non-production): drive the REAL provider
/// failover path and substitute the HID idle sample the presence-gated warm
/// loop reads — everything downstream of each seam is the production path.
extension DesktopAutomationActionRegistry {
func registerRealtimeHubActions() {
// Onboarding screen-demo step: open the three-doors page (same path as the
// "Open the doors" button), so agents can exercise the demo without the cursor.
register(
name: "onboarding_open_doors",
summary: "Onboarding screen-demo step: open the three-doors page (same path as the Open the doors button)"
) { _ in
await MainActor.run {
NotificationCenter.default.post(name: .onboardingOpenDoorsRequested, object: nil)
}
return ["status": "requested"]
}
// Drives the REAL provider failover the quota/auth close handlers call
// (failoverToAlternateProvider), then re-warms, so the cross-provider path
// can be exercised without waiting for the shared key to actually throttle.
register(
name: "realtime_failover",
summary: "Fail the realtime hub over to the alternate provider via the production path (non-prod).",
params: []
) { _ in
guard AppBuild.isNonProduction else {
return ["error": "realtime_failover is disabled on production bundles"]
}
let controller = RealtimeHubController.shared
let from = controller.effectiveProvider.rawValue
let started = controller.failoverToAlternateProvider(reason: "quota")
controller.ensureWarm(userInitiated: true)
return [
"failover_started": started ? "true" : "false",
"from": from,
"to": controller.effectiveProvider.rawValue,
]
}
// Substitutes the HID idle sample the presence-gated warm loop reads, so
// the away → defer → return → re-warm path can be exercised without a real
// 10-minute walk-away. Everything downstream is the production path.
register(
name: "realtime_presence",
summary: "Override the realtime hub's user-idle sample (non-prod): idle_seconds=<n> or reset.",
params: ["idle_seconds"]
) { params in
guard AppBuild.isNonProduction else {
return ["error": "realtime_presence is disabled on production bundles"]
}
let controller = RealtimeHubController.shared
if let raw = params["idle_seconds"], let idle = TimeInterval(raw) {
controller.presenceIdleProvider = { idle }
} else {
controller.presenceIdleProvider = { UserInputPresence.secondsSinceLastInput() }
}
return [
"idle_sample": controller.presenceIdleProvider().map { String($0) } ?? "nil",
"warm_deferred": controller.warmDeferredForUserAway ? "true" : "false",
"session_active": controller.session != nil ? "true" : "false",
]
}
registerResponseContextActions()
}
}