mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-11 15:13:23 +08:00
重构主控编排与运行时预热链路,统一工作区提示词/专家调度协议并补齐 wiki 记忆注入与写回闭环。
同时收敛启动与运维脚本默认行为(含 wiki worker)、更新 Admin 可观测性与相关测试,降低首轮时延并提高运行稳定性。 Made-with: Cursor
This commit is contained in:
parent
4a23b715a2
commit
dbbe3add6a
14438 changed files with 2693620 additions and 2546 deletions
121
openclaw/apps/macos/Sources/OpenClaw/WebChatManager.swift
Normal file
121
openclaw/apps/macos/Sources/OpenClaw/WebChatManager.swift
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
import AppKit
|
||||
import Foundation
|
||||
|
||||
/// A borderless panel that can still accept key focus (needed for typing).
|
||||
final class WebChatPanel: NSPanel {
|
||||
override var canBecomeKey: Bool {
|
||||
true
|
||||
}
|
||||
|
||||
override var canBecomeMain: Bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
enum WebChatPresentation {
|
||||
case window
|
||||
case panel(anchorProvider: () -> NSRect?)
|
||||
|
||||
var isPanel: Bool {
|
||||
if case .panel = self { return true }
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
final class WebChatManager {
|
||||
static let shared = WebChatManager()
|
||||
|
||||
private var windowController: WebChatSwiftUIWindowController?
|
||||
private var windowSessionKey: String?
|
||||
private var panelController: WebChatSwiftUIWindowController?
|
||||
private var panelSessionKey: String?
|
||||
private var cachedPreferredSessionKey: String?
|
||||
|
||||
var onPanelVisibilityChanged: ((Bool) -> Void)?
|
||||
|
||||
var activeSessionKey: String? {
|
||||
self.panelSessionKey ?? self.windowSessionKey
|
||||
}
|
||||
|
||||
func show(sessionKey: String) {
|
||||
self.closePanel()
|
||||
if let controller = self.windowController {
|
||||
if self.windowSessionKey == sessionKey {
|
||||
controller.show()
|
||||
return
|
||||
}
|
||||
|
||||
controller.close()
|
||||
self.windowController = nil
|
||||
self.windowSessionKey = nil
|
||||
}
|
||||
let controller = WebChatSwiftUIWindowController(sessionKey: sessionKey, presentation: .window)
|
||||
controller.onVisibilityChanged = { [weak self] visible in
|
||||
self?.onPanelVisibilityChanged?(visible)
|
||||
}
|
||||
self.windowController = controller
|
||||
self.windowSessionKey = sessionKey
|
||||
controller.show()
|
||||
}
|
||||
|
||||
func togglePanel(sessionKey: String, anchorProvider: @escaping () -> NSRect?) {
|
||||
if let controller = self.panelController {
|
||||
if self.panelSessionKey != sessionKey {
|
||||
controller.close()
|
||||
self.panelController = nil
|
||||
self.panelSessionKey = nil
|
||||
} else {
|
||||
if controller.isVisible {
|
||||
controller.close()
|
||||
} else {
|
||||
controller.presentAnchored(anchorProvider: anchorProvider)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
let controller = WebChatSwiftUIWindowController(
|
||||
sessionKey: sessionKey,
|
||||
presentation: .panel(anchorProvider: anchorProvider))
|
||||
controller.onClosed = { [weak self] in
|
||||
self?.panelHidden()
|
||||
}
|
||||
controller.onVisibilityChanged = { [weak self] visible in
|
||||
self?.onPanelVisibilityChanged?(visible)
|
||||
}
|
||||
self.panelController = controller
|
||||
self.panelSessionKey = sessionKey
|
||||
controller.presentAnchored(anchorProvider: anchorProvider)
|
||||
}
|
||||
|
||||
func closePanel() {
|
||||
self.panelController?.close()
|
||||
}
|
||||
|
||||
func preferredSessionKey() async -> String {
|
||||
if let cachedPreferredSessionKey { return cachedPreferredSessionKey }
|
||||
let key = await GatewayConnection.shared.mainSessionKey()
|
||||
self.cachedPreferredSessionKey = key
|
||||
return key
|
||||
}
|
||||
|
||||
func resetTunnels() {
|
||||
self.windowController?.close()
|
||||
self.windowController = nil
|
||||
self.windowSessionKey = nil
|
||||
self.panelController?.close()
|
||||
self.panelController = nil
|
||||
self.panelSessionKey = nil
|
||||
self.cachedPreferredSessionKey = nil
|
||||
}
|
||||
|
||||
func close() {
|
||||
self.resetTunnels()
|
||||
}
|
||||
|
||||
private func panelHidden() {
|
||||
self.onPanelVisibilityChanged?(false)
|
||||
// Keep panel controller cached so reopening doesn't re-bootstrap.
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue