Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
fix(spaces-sdk-swift): typed calls for space_job, network_show and network_set (#6403)
injaneity0ea989b0d0fe
diff --git a/libs/spaces-sdk-swift/Sources/CuaSpaces/MCPSurface.swift b/libs/spaces-sdk-swift/Sources/CuaSpaces/MCPSurface.swiftindex e6336e5a2a..fa6ef1abb6 100644--- a/libs/spaces-sdk-swift/Sources/CuaSpaces/MCPSurface.swift+++ b/libs/spaces-sdk-swift/Sources/CuaSpaces/MCPSurface.swift@@ -520,3 +520,67 @@ extension Space {/// Commands this Space keeps running (`space_service`).public var keepRunning: KeepRunning { KeepRunning(space: self) }}++// MARK: - Background jobs++/// Long commands the Space runs in the background: they keep running when+/// the caller goes away, their output kept in a log in the Space.+public struct SpaceJobs: Sendable {+ let space: Space++ /// Calls `space_job` with `action` and its arguments, and returns the+ /// tool's JSON answer (a job's status, a log page, or `jobs`).+ @discardableResult+ public func job(_ action: String, _ arguments: [String: JSONValue] = [:]) async throws -> JSONValue {+ var args = arguments+ args["space"] = .string(space.id.rawValue)+ args["action"] = .string(action)+ return try await space.connection.callTool("space_job", args)+ }++ /// Starts `command` as a background job; `notify` wakes the caller when it ends.+ @discardableResult+ public func start(_ command: String, name: String? = nil, notify: Bool = false) async throws -> JSONValue {+ var args: [String: JSONValue] = ["command": .string(command), "notify": .bool(notify)]+ if let name { args["name"] = .string(name) }+ return try await job("start", args)+ }++ /// A job's state and the end of its log.+ public func status(_ id: String) async throws -> JSONValue {+ try await job("status", ["job": .string(id)])+ }++ /// Stops a job and returns its final status.+ @discardableResult+ public func cancel(_ id: String) async throws -> JSONValue {+ try await job("cancel", ["job": .string(id)])+ }++ /// This Space's jobs, newest first.+ public func list() async throws -> JSONValue { try await job("list") }+}++extension Space {+ /// Commands this Space runs as background jobs (`space_job`).+ public var jobs: SpaceJobs { SpaceJobs(space: self) }++ /// The Space's network: preset, what it opens, where it is enforced+ /// (`network_show`).+ public func network() async throws -> [String: JSONValue] {+ try await connection.object("network_show", ["space": .string(id.rawValue)])+ }++ /// Tightens the Space's network to `internet`, `none` or `custom` with+ /// `allow` / `deny` lists (`network_set`). Opening more is refused: the+ /// user does that.+ @discardableResult+ public func setNetwork(_ preset: String, allow: [String]? = nil, deny: [String]? = nil,+ tree: Bool = false) async throws -> [String: JSONValue] {+ var args: [String: JSONValue] = ["space": .string(id.rawValue),+ "network": .string(preset), "tree": .bool(tree)]+ if let allow { args["allow"] = .array(allow.map(JSONValue.string)) }+ if let deny { args["deny"] = .array(deny.map(JSONValue.string)) }+ return try await connection.object("network_set", args)+ }+}diff --git a/libs/spaces-sdk-swift/Tests/CuaSpacesTests/FakeSpace.swift b/libs/spaces-sdk-swift/Tests/CuaSpacesTests/FakeSpace.swiftindex 69e0135a6f..5423c56ccc 100644--- a/libs/spaces-sdk-swift/Tests/CuaSpacesTests/FakeSpace.swift+++ b/libs/spaces-sdk-swift/Tests/CuaSpacesTests/FakeSpace.swift@@ -319,6 +319,17 @@ actor FakeSpacesBackend: SpacesTransport {case "space_service":return .object(["services": .array([])])+ case "space_job":+ if arguments["action"]?.stringValue == "list" { return .object(["jobs": .array([])]) }+ return .object(["job": "j-1", "state": "running"])++ case "network_show":+ return .object(["settings": .object(["preset": "internet"]), "enforcement": "enforced"])++ case "network_set":+ return .object(["applied": "now",+ "network": .object(["settings": .object(["preset": arguments["network"] ?? "internet"])])])+case "space_write":let path = arguments["path"]?.stringValue ?? ""files.insert(Self.expand(path))diff --git a/libs/spaces-sdk-swift/Tests/CuaSpacesTests/ToolCoverageTests.swift b/libs/spaces-sdk-swift/Tests/CuaSpacesTests/ToolCoverageTests.swiftindex 52999ef2bf..ec1411059a 100644--- a/libs/spaces-sdk-swift/Tests/CuaSpacesTests/ToolCoverageTests.swift+++ b/libs/spaces-sdk-swift/Tests/CuaSpacesTests/ToolCoverageTests.swift@@ -41,7 +41,7 @@ import Testing]@Test func testTheContractIsCompleteTools() {- XCTAssertEqual(Self.advertisedTools.count, 114)+ XCTAssertEqual(Self.advertisedTools.count, 118)// The Python server's `local_rcdp` is gone; `stream_endpoint` mints a// media ticket for any provider, and `send_file` is new.XCTAssertFalse(Self.advertisedTools.contains("local_rcdp"))@@ -96,6 +96,18 @@ import Testing_ = try await space.services.tools() // list_tools_ = try await space.services.call("screenshot") // call_tool_ = try await space.keepRunning.service("list") // space_service+ let job = try await space.jobs.start("make test", name: "unit tests") // space_job+ let jobID = job.objectValue?["job"]?.stringValue ?? ""+ XCTAssertEqual(jobID, "j-1")+ _ = try await space.jobs.status(jobID)+ _ = try await space.jobs.list()+ _ = try await space.jobs.cancel(jobID)++ // --- The Space's network ---------------------------------------------+ let net = try await space.network() // network_show+ XCTAssertEqual(net["settings"]?.objectValue?["preset"]?.stringValue, "internet")+ let tightened = try await space.setNetwork("none") // network_set+ XCTAssertEqual(tightened["applied"]?.stringValue, "now")// --- Agents ----------------------------------------------------------let run = try await space.startAgent(prompt: "x") // agent_start