Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
383 lines
10 KiB
Swift
383 lines
10 KiB
Swift
import Foundation
|
|
import Observation
|
|
import OpenClawProtocol
|
|
|
|
struct ChannelsStatusSnapshot: Codable {
|
|
struct WhatsAppSelf: Codable {
|
|
let e164: String?
|
|
let jid: String?
|
|
}
|
|
|
|
struct WhatsAppDisconnect: Codable {
|
|
let at: Double
|
|
let status: Int?
|
|
let error: String?
|
|
let loggedOut: Bool?
|
|
}
|
|
|
|
struct WhatsAppStatus: Codable {
|
|
let configured: Bool
|
|
let linked: Bool
|
|
let authAgeMs: Double?
|
|
let `self`: WhatsAppSelf?
|
|
let running: Bool
|
|
let connected: Bool
|
|
let lastConnectedAt: Double?
|
|
let lastDisconnect: WhatsAppDisconnect?
|
|
let reconnectAttempts: Int
|
|
let lastMessageAt: Double?
|
|
let lastEventAt: Double?
|
|
let lastError: String?
|
|
}
|
|
|
|
struct TelegramBot: Codable {
|
|
let id: Int?
|
|
let username: String?
|
|
}
|
|
|
|
struct TelegramWebhook: Codable {
|
|
let url: String?
|
|
let hasCustomCert: Bool?
|
|
}
|
|
|
|
struct TelegramProbe: Codable {
|
|
let ok: Bool
|
|
let status: Int?
|
|
let error: String?
|
|
let elapsedMs: Double?
|
|
let bot: TelegramBot?
|
|
let webhook: TelegramWebhook?
|
|
}
|
|
|
|
struct TelegramStatus: Codable {
|
|
let configured: Bool
|
|
let tokenSource: String?
|
|
let running: Bool
|
|
let mode: String?
|
|
let lastStartAt: Double?
|
|
let lastStopAt: Double?
|
|
let lastError: String?
|
|
let probe: TelegramProbe?
|
|
let lastProbeAt: Double?
|
|
}
|
|
|
|
struct DiscordBot: Codable {
|
|
let id: String?
|
|
let username: String?
|
|
}
|
|
|
|
struct DiscordProbe: Codable {
|
|
let ok: Bool
|
|
let status: Int?
|
|
let error: String?
|
|
let elapsedMs: Double?
|
|
let bot: DiscordBot?
|
|
}
|
|
|
|
struct DiscordStatus: Codable {
|
|
let configured: Bool
|
|
let tokenSource: String?
|
|
let running: Bool
|
|
let lastStartAt: Double?
|
|
let lastStopAt: Double?
|
|
let lastError: String?
|
|
let probe: DiscordProbe?
|
|
let lastProbeAt: Double?
|
|
}
|
|
|
|
struct GoogleChatProbe: Codable {
|
|
let ok: Bool
|
|
let status: Int?
|
|
let error: String?
|
|
let elapsedMs: Double?
|
|
}
|
|
|
|
struct GoogleChatStatus: Codable {
|
|
let configured: Bool
|
|
let credentialSource: String?
|
|
let audienceType: String?
|
|
let audience: String?
|
|
let webhookPath: String?
|
|
let webhookUrl: String?
|
|
let running: Bool
|
|
let lastStartAt: Double?
|
|
let lastStopAt: Double?
|
|
let lastError: String?
|
|
let probe: GoogleChatProbe?
|
|
let lastProbeAt: Double?
|
|
}
|
|
|
|
struct SignalProbe: Codable {
|
|
let ok: Bool
|
|
let status: Int?
|
|
let error: String?
|
|
let elapsedMs: Double?
|
|
let version: String?
|
|
}
|
|
|
|
struct SignalStatus: Codable {
|
|
let configured: Bool
|
|
let baseUrl: String
|
|
let running: Bool
|
|
let lastStartAt: Double?
|
|
let lastStopAt: Double?
|
|
let lastError: String?
|
|
let probe: SignalProbe?
|
|
let lastProbeAt: Double?
|
|
}
|
|
|
|
struct IMessageProbe: Codable {
|
|
let ok: Bool
|
|
let error: String?
|
|
}
|
|
|
|
struct IMessageStatus: Codable {
|
|
let configured: Bool
|
|
let running: Bool
|
|
let lastStartAt: Double?
|
|
let lastStopAt: Double?
|
|
let lastError: String?
|
|
let cliPath: String?
|
|
let dbPath: String?
|
|
let probe: IMessageProbe?
|
|
let lastProbeAt: Double?
|
|
}
|
|
|
|
struct ChannelAccountSnapshot: Codable {
|
|
let accountId: String
|
|
let name: String?
|
|
let enabled: Bool?
|
|
let configured: Bool?
|
|
let linked: Bool?
|
|
let running: Bool?
|
|
let connected: Bool?
|
|
let reconnectAttempts: Int?
|
|
let lastConnectedAt: Double?
|
|
let lastError: String?
|
|
let lastStartAt: Double?
|
|
let lastStopAt: Double?
|
|
let lastInboundAt: Double?
|
|
let lastOutboundAt: Double?
|
|
let lastProbeAt: Double?
|
|
let mode: String?
|
|
let dmPolicy: String?
|
|
let allowFrom: [String]?
|
|
let tokenSource: String?
|
|
let botTokenSource: String?
|
|
let appTokenSource: String?
|
|
let baseUrl: String?
|
|
let allowUnmentionedGroups: Bool?
|
|
let cliPath: String?
|
|
let dbPath: String?
|
|
let port: Int?
|
|
let probe: AnyCodable?
|
|
let audit: AnyCodable?
|
|
let application: AnyCodable?
|
|
}
|
|
|
|
struct ChannelUiMetaEntry: Codable {
|
|
let id: String
|
|
let label: String
|
|
let detailLabel: String
|
|
let systemImage: String?
|
|
}
|
|
|
|
let ts: Double
|
|
let channelOrder: [String]
|
|
let channelLabels: [String: String]
|
|
let channelDetailLabels: [String: String]?
|
|
let channelSystemImages: [String: String]?
|
|
let channelMeta: [ChannelUiMetaEntry]?
|
|
let channels: [String: AnyCodable]
|
|
let channelAccounts: [String: [ChannelAccountSnapshot]]
|
|
let channelDefaultAccountId: [String: String]
|
|
|
|
func decodeChannel<T: Decodable>(_ id: String, as type: T.Type) -> T? {
|
|
guard let value = self.channels[id] else { return nil }
|
|
do {
|
|
let data = try JSONEncoder().encode(value)
|
|
return try JSONDecoder().decode(type, from: data)
|
|
} catch {
|
|
return nil
|
|
}
|
|
}
|
|
}
|
|
|
|
struct ConfigSnapshot: Codable {
|
|
struct Issue: Codable {
|
|
let path: String
|
|
let message: String
|
|
}
|
|
|
|
let path: String?
|
|
let exists: Bool?
|
|
let raw: String?
|
|
let hash: String?
|
|
let parsed: AnyCodable?
|
|
let valid: Bool?
|
|
let config: [String: AnyCodable]?
|
|
let issues: [Issue]?
|
|
}
|
|
|
|
struct ConfigSchemaLookupChild: Identifiable {
|
|
let key: String
|
|
let path: String
|
|
let typeLabel: String?
|
|
let required: Bool
|
|
let hasChildren: Bool
|
|
let hint: ConfigUiHint?
|
|
let hintPath: String?
|
|
|
|
var id: String {
|
|
self.path
|
|
}
|
|
|
|
init?(raw: [String: AnyCodable]) {
|
|
guard let key = raw["key"]?.stringValue,
|
|
let path = raw["path"]?.stringValue
|
|
else {
|
|
return nil
|
|
}
|
|
self.key = key
|
|
self.path = path
|
|
if let type = raw["type"]?.stringValue {
|
|
self.typeLabel = type
|
|
} else if let types = raw["type"]?.arrayValue {
|
|
self.typeLabel = types.compactMap(\.stringValue).joined(separator: " / ")
|
|
} else {
|
|
self.typeLabel = nil
|
|
}
|
|
self.required = raw["required"]?.boolValue ?? false
|
|
self.hasChildren = raw["hasChildren"]?.boolValue ?? false
|
|
if let hint = raw["hint"]?.dictionaryValue {
|
|
self.hint = ConfigUiHint(raw: hint.mapValues(\.foundationValue))
|
|
} else {
|
|
self.hint = nil
|
|
}
|
|
self.hintPath = raw["hintPath"]?.stringValue
|
|
}
|
|
}
|
|
|
|
struct ConfigSchemaLookupNode {
|
|
let path: String
|
|
let schema: ConfigSchemaNode
|
|
let hint: ConfigUiHint?
|
|
let hintPath: String?
|
|
let children: [ConfigSchemaLookupChild]
|
|
}
|
|
|
|
@MainActor
|
|
@Observable
|
|
final class ChannelsStore {
|
|
static let shared = ChannelsStore()
|
|
|
|
var snapshot: ChannelsStatusSnapshot? {
|
|
didSet {
|
|
self.decodedChannelCache.removeAll(keepingCapacity: true)
|
|
}
|
|
}
|
|
|
|
var lastError: String?
|
|
var lastSuccess: Date?
|
|
var isRefreshing = false
|
|
|
|
var whatsappLoginMessage: String?
|
|
var whatsappLoginQrDataUrl: String?
|
|
var whatsappLoginConnected: Bool?
|
|
var whatsappBusy = false
|
|
var telegramBusy = false
|
|
|
|
var configStatus: String?
|
|
var isSavingConfig = false
|
|
var configSchemaLoading = false
|
|
var configSchema: ConfigSchemaNode?
|
|
var configLookupRoot: ConfigSchemaLookupNode?
|
|
var configLookupCache: [String: ConfigSchemaLookupNode] = [:]
|
|
var configLookupLoadingPaths: Set<String> = []
|
|
var configUiHints: [String: ConfigUiHint] = [:]
|
|
var configSchemaSourceKey: String?
|
|
var configSchemaLoadingSourceKey: String?
|
|
var configSchemaReloadPending = false
|
|
var configLoading = false
|
|
var configLoadingSourceKey: String?
|
|
var configForceReloadPending = false
|
|
var configDraft: [String: Any] = [:]
|
|
var configDirty = false
|
|
|
|
let interval: TimeInterval = 45
|
|
let isPreview: Bool
|
|
var startCount = 0
|
|
var pollTask: Task<Void, Never>?
|
|
var configRoot: [String: Any] = [:]
|
|
var configLoaded = false
|
|
var configSourceKey: String?
|
|
@ObservationIgnored private var decodedChannelCache: [String: Any] = [:]
|
|
|
|
func channelMetaEntry(_ id: String) -> ChannelsStatusSnapshot.ChannelUiMetaEntry? {
|
|
self.snapshot?.channelMeta?.first(where: { $0.id == id })
|
|
}
|
|
|
|
func resolveChannelLabel(_ id: String) -> String {
|
|
if let meta = self.channelMetaEntry(id), !meta.label.isEmpty {
|
|
return meta.label
|
|
}
|
|
if let label = self.snapshot?.channelLabels[id], !label.isEmpty {
|
|
return label
|
|
}
|
|
return id
|
|
}
|
|
|
|
func resolveChannelDetailLabel(_ id: String) -> String {
|
|
if let meta = self.channelMetaEntry(id), !meta.detailLabel.isEmpty {
|
|
return meta.detailLabel
|
|
}
|
|
if let detail = self.snapshot?.channelDetailLabels?[id], !detail.isEmpty {
|
|
return detail
|
|
}
|
|
return self.resolveChannelLabel(id)
|
|
}
|
|
|
|
func resolveChannelSystemImage(_ id: String) -> String {
|
|
if let meta = self.channelMetaEntry(id), let symbol = meta.systemImage, !symbol.isEmpty {
|
|
return symbol
|
|
}
|
|
if let symbol = self.snapshot?.channelSystemImages?[id], !symbol.isEmpty {
|
|
return symbol
|
|
}
|
|
return "message"
|
|
}
|
|
|
|
func orderedChannelIds() -> [String] {
|
|
if let meta = self.snapshot?.channelMeta, !meta.isEmpty {
|
|
return meta.map(\.id)
|
|
}
|
|
return self.snapshot?.channelOrder ?? []
|
|
}
|
|
|
|
func decodedChannel<T: Decodable>(_ id: String, as type: T.Type) -> T? {
|
|
let key = "\(id)#\(ObjectIdentifier(type))"
|
|
if let cached = self.decodedChannelCache[key] as? T {
|
|
return cached
|
|
}
|
|
guard let decoded = self.snapshot?.decodeChannel(id, as: type) else {
|
|
return nil
|
|
}
|
|
self.decodedChannelCache[key] = decoded
|
|
return decoded
|
|
}
|
|
|
|
func applyWhatsAppLoginWaitResult(_ result: WhatsAppLoginWaitResult) {
|
|
self.whatsappLoginMessage = result.message
|
|
self.whatsappLoginConnected = result.connected
|
|
if let qrDataUrl = result.qrDataUrl {
|
|
self.whatsappLoginQrDataUrl = qrDataUrl
|
|
} else if result.connected {
|
|
self.whatsappLoginQrDataUrl = nil
|
|
}
|
|
}
|
|
|
|
init(isPreview: Bool = ProcessInfo.processInfo.isPreview) {
|
|
self.isPreview = isPreview
|
|
}
|
|
}
|