Nodes: advertise canvas invoke commands

This commit is contained in:
Peter Steinberger
2025-12-18 02:05:06 +00:00
parent 54830e8401
commit efed2ae30f
15 changed files with 212 additions and 153 deletions

View File

@@ -66,6 +66,7 @@ public struct BridgeHello: Codable, Sendable {
public let deviceFamily: String?
public let modelIdentifier: String?
public let caps: [String]?
public let commands: [String]?
public init(
type: String = "hello",
@@ -76,7 +77,8 @@ public struct BridgeHello: Codable, Sendable {
version: String?,
deviceFamily: String? = nil,
modelIdentifier: String? = nil,
caps: [String]? = nil)
caps: [String]? = nil,
commands: [String]? = nil)
{
self.type = type
self.nodeId = nodeId
@@ -87,6 +89,7 @@ public struct BridgeHello: Codable, Sendable {
self.deviceFamily = deviceFamily
self.modelIdentifier = modelIdentifier
self.caps = caps
self.commands = commands
}
}
@@ -109,6 +112,7 @@ public struct BridgePairRequest: Codable, Sendable {
public let deviceFamily: String?
public let modelIdentifier: String?
public let caps: [String]?
public let commands: [String]?
public let remoteAddress: String?
public init(
@@ -120,6 +124,7 @@ public struct BridgePairRequest: Codable, Sendable {
deviceFamily: String? = nil,
modelIdentifier: String? = nil,
caps: [String]? = nil,
commands: [String]? = nil,
remoteAddress: String? = nil)
{
self.type = type
@@ -130,6 +135,7 @@ public struct BridgePairRequest: Codable, Sendable {
self.deviceFamily = deviceFamily
self.modelIdentifier = modelIdentifier
self.caps = caps
self.commands = commands
self.remoteAddress = remoteAddress
}
}

View File

@@ -0,0 +1,47 @@
import Foundation
public enum ClawdisCanvasMode: String, Codable, Sendable {
case canvas
case web
}
public struct ClawdisCanvasNavigateParams: Codable, Sendable, Equatable {
public var url: String
public init(url: String) {
self.url = url
}
}
public struct ClawdisCanvasSetModeParams: Codable, Sendable, Equatable {
public var mode: ClawdisCanvasMode
public init(mode: ClawdisCanvasMode) {
self.mode = mode
}
}
public struct ClawdisCanvasEvalParams: Codable, Sendable, Equatable {
public var javaScript: String
public init(javaScript: String) {
self.javaScript = javaScript
}
}
public enum ClawdisCanvasSnapshotFormat: String, Codable, Sendable {
case png
case jpeg
}
public struct ClawdisCanvasSnapshotParams: Codable, Sendable, Equatable {
public var maxWidth: Int?
public var quality: Double?
public var format: ClawdisCanvasSnapshotFormat?
public init(maxWidth: Int? = nil, quality: Double? = nil, format: ClawdisCanvasSnapshotFormat? = nil) {
self.maxWidth = maxWidth
self.quality = quality
self.format = format
}
}

View File

@@ -8,21 +8,3 @@ public enum ClawdisCanvasCommand: String, Codable, Sendable {
case evalJS = "canvas.eval"
case snapshot = "canvas.snapshot"
}
public enum ClawdisInvokeCommandAliases {
public static func canonicalizeCanvasToScreen(_ command: String) -> String {
if command.hasPrefix(ClawdisCanvasCommand.namespacePrefix) {
return ClawdisScreenCommand.namespacePrefix +
command.dropFirst(ClawdisCanvasCommand.namespacePrefix.count)
}
return command
}
}
extension ClawdisCanvasCommand {
public static var namespacePrefix: String { "canvas." }
}
extension ClawdisScreenCommand {
public static var namespacePrefix: String { "screen." }
}

View File

@@ -1,56 +0,0 @@
import Foundation
public enum ClawdisScreenMode: String, Codable, Sendable {
case canvas
case web
}
public enum ClawdisScreenCommand: String, Codable, Sendable {
case show = "canvas.show"
case hide = "canvas.hide"
case setMode = "canvas.setMode"
case navigate = "canvas.navigate"
case evalJS = "canvas.eval"
case snapshot = "canvas.snapshot"
}
public struct ClawdisScreenNavigateParams: Codable, Sendable, Equatable {
public var url: String
public init(url: String) {
self.url = url
}
}
public struct ClawdisScreenSetModeParams: Codable, Sendable, Equatable {
public var mode: ClawdisScreenMode
public init(mode: ClawdisScreenMode) {
self.mode = mode
}
}
public struct ClawdisScreenEvalParams: Codable, Sendable, Equatable {
public var javaScript: String
public init(javaScript: String) {
self.javaScript = javaScript
}
}
public enum ClawdisSnapshotFormat: String, Codable, Sendable {
case png
case jpeg
}
public struct ClawdisScreenSnapshotParams: Codable, Sendable, Equatable {
public var maxWidth: Int?
public var quality: Double?
public var format: ClawdisSnapshotFormat?
public init(maxWidth: Int? = nil, quality: Double? = nil, format: ClawdisSnapshotFormat? = nil) {
self.maxWidth = maxWidth
self.quality = quality
self.format = format
}
}