mirror of
https://github.com/hanzoai/bot.git
synced 2026-10-30 17:24:26 +00:00
Comprehensive rename of all openclaw references to hanzo-bot equivalents: - Package: openclaw → @hanzo/bot - Binary: openclaw → hanzo-bot - Types: OpenClaw* → Bot* - Env vars: OPENCLAW_* → BOT_* - Android: ai.openclaw.android → ai.hanzo.bot.android - iOS/macOS: ai.openclaw.* → ai.hanzo.* - Swift modules: OpenClaw* → Bot* - Plugins: openclaw.plugin.json → bot.plugin.json - Paths: .openclaw/ → .hanzo/bot/ - URLs: github.com/openclaw → github.com/hanzoai
104 lines
3.7 KiB
Swift
104 lines
3.7 KiB
Swift
import Foundation
|
|
import BotKit
|
|
|
|
extension NodeAppModel {
|
|
static func normalizeWatchNotifyParams(_ params: BotWatchNotifyParams) -> BotWatchNotifyParams {
|
|
var normalized = params
|
|
normalized.title = params.title.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
normalized.body = params.body.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
normalized.promptId = self.trimmedOrNil(params.promptId)
|
|
normalized.sessionKey = self.trimmedOrNil(params.sessionKey)
|
|
normalized.kind = self.trimmedOrNil(params.kind)
|
|
normalized.details = self.trimmedOrNil(params.details)
|
|
normalized.priority = self.normalizedWatchPriority(params.priority, risk: params.risk)
|
|
normalized.risk = self.normalizedWatchRisk(params.risk, priority: normalized.priority)
|
|
|
|
let normalizedActions = self.normalizeWatchActions(
|
|
params.actions,
|
|
kind: normalized.kind,
|
|
promptId: normalized.promptId)
|
|
normalized.actions = normalizedActions.isEmpty ? nil : normalizedActions
|
|
return normalized
|
|
}
|
|
|
|
static func normalizeWatchActions(
|
|
_ actions: [BotWatchAction]?,
|
|
kind: String?,
|
|
promptId: String?) -> [BotWatchAction]
|
|
{
|
|
let provided = (actions ?? []).compactMap { action -> BotWatchAction? in
|
|
let id = action.id.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
let label = action.label.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
guard !id.isEmpty, !label.isEmpty else { return nil }
|
|
return BotWatchAction(
|
|
id: id,
|
|
label: label,
|
|
style: self.trimmedOrNil(action.style))
|
|
}
|
|
if !provided.isEmpty {
|
|
return Array(provided.prefix(4))
|
|
}
|
|
|
|
// Only auto-insert quick actions when this is a prompt/decision flow.
|
|
guard promptId?.isEmpty == false else {
|
|
return []
|
|
}
|
|
|
|
let normalizedKind = kind?.trimmingCharacters(in: .whitespacesAndNewlines).lowercased() ?? ""
|
|
if normalizedKind.contains("approval") || normalizedKind.contains("approve") {
|
|
return [
|
|
BotWatchAction(id: "approve", label: "Approve"),
|
|
BotWatchAction(id: "decline", label: "Decline", style: "destructive"),
|
|
BotWatchAction(id: "open_phone", label: "Open iPhone"),
|
|
BotWatchAction(id: "escalate", label: "Escalate"),
|
|
]
|
|
}
|
|
|
|
return [
|
|
BotWatchAction(id: "done", label: "Done"),
|
|
BotWatchAction(id: "snooze_10m", label: "Snooze 10m"),
|
|
BotWatchAction(id: "open_phone", label: "Open iPhone"),
|
|
BotWatchAction(id: "escalate", label: "Escalate"),
|
|
]
|
|
}
|
|
|
|
static func normalizedWatchRisk(
|
|
_ risk: BotWatchRisk?,
|
|
priority: BotNotificationPriority?) -> BotWatchRisk?
|
|
{
|
|
if let risk { return risk }
|
|
switch priority {
|
|
case .passive:
|
|
return .low
|
|
case .active:
|
|
return .medium
|
|
case .timeSensitive:
|
|
return .high
|
|
case nil:
|
|
return nil
|
|
}
|
|
}
|
|
|
|
static func normalizedWatchPriority(
|
|
_ priority: BotNotificationPriority?,
|
|
risk: BotWatchRisk?) -> BotNotificationPriority?
|
|
{
|
|
if let priority { return priority }
|
|
switch risk {
|
|
case .low:
|
|
return .passive
|
|
case .medium:
|
|
return .active
|
|
case .high:
|
|
return .timeSensitive
|
|
case nil:
|
|
return nil
|
|
}
|
|
}
|
|
|
|
static func trimmedOrNil(_ value: String?) -> String? {
|
|
let trimmed = value?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
|
|
return trimmed.isEmpty ? nil : trimmed
|
|
}
|
|
}
|