// Basic example for the Clawdforge SDK. // // Run with: CLAWDFORGE_TOKEN=cf_... swift run ClawdforgeBasicExample // // This file is intentionally named `main.swift` so it can use top-level // `await` rather than wrapping in `@main`. Swift treats a single-file // executable target named `main.swift` as a script. import Foundation import Clawdforge let baseURL = URL(string: ProcessInfo.processInfo.environment["CLAWDFORGE_URL"] ?? "http://192.168.0.5:8800")! guard let token = ProcessInfo.processInfo.environment["CLAWDFORGE_TOKEN"] else { FileHandle.standardError.write(Data("error: set CLAWDFORGE_TOKEN\n".utf8)) exit(1) } do { let client = try ForgeClient(baseURL: baseURL, token: token) // 1. Health check let h = try await client.healthz() print("claude_present: \(h.claudePresent)") print("claude_version: \(h.claudeVersion ?? "unknown")") // 2. Run a prompt let res = try await client.run(RunRequest( prompt: #"Reply with JSON: {"hello": "world"}"#, model: "sonnet", timeoutSecs: 60 )) print("duration: \(res.durationMs)ms") if case .object(let dict) = res.result, case .string(let hello) = dict["hello"] ?? .null { print("hello = \(hello)") } else { print("result: \(res.result)") } // 3. Optional file upload + reuse — uncomment to try. // // let recipe = URL(fileURLWithPath: "./recipe.png") // let ft = try await client.uploadFile(at: recipe, ttlSecs: 3600) // let extract = try await client.run(RunRequest( // prompt: "extract recipe data as JSON", // files: [ft.fileToken] // )) // print("extract: \(extract.result)") } catch let err as ForgeError { FileHandle.standardError.write(Data("clawdforge error: \(err.localizedDescription)\n".utf8)) exit(2) } catch { FileHandle.standardError.write(Data("unexpected error: \(error)\n".utf8)) exit(2) }