Align Swift SDK broker API parity#1103
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Warning Review limit reached
More reviews will be available in 14 minutes and 30 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f71c875ad1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
|
|
||
| func listAgents() async throws -> [ListAgent] { | ||
| try decodeJSON(try await http.get(path: "/api/spawned"), as: [ListAgent].self) |
There was a problem hiding this comment.
Decode the /api/spawned response envelope
In the broker, GET /api/spawned returns an object envelope like { "agents": workers.list() } (also what the TS/Python clients unwrap), not a top-level array. As written, every successful listAgents() call attempts to decode that object as [ListAgent] and throws decodingFailed, so the new API is unusable against the real broker.
Useful? React with 👍 / 👎.
|
|
||
| func sendInput(name: String, data: String) async throws { | ||
| let body = try encodeJSON(InputRequestBody(data: data)) | ||
| _ = try await http.post(path: "/api/spawned/\(escapePathSegment(name))/input", body: body) |
There was a problem hiding this comment.
Use the broker PTY input route
The broker registers PTY input at POST /api/input/{name} and the existing TS/Python clients use that route; there is no /api/spawned/{name}/input route in crates/broker/src/listen_api.rs. Any caller of this new sendInput helper will get a 404/protocol error instead of writing to the agent PTY.
Useful? React with 👍 / 👎.
|
|
||
| func resizePty(name: String, rows: Int, cols: Int) async throws { | ||
| let body = try encodeJSON(ResizeRequestBody(rows: rows, cols: cols)) | ||
| _ = try await http.post(path: "/api/spawned/\(escapePathSegment(name))/resize", body: body) |
There was a problem hiding this comment.
Use the broker PTY resize route
The broker exposes resize as POST /api/resize/{name} and the other SDKs call that endpoint; /api/spawned/{name}/resize is not registered. In contexts like attach/terminal resizing, this new Swift method will consistently fail with a 404 instead of resizing the PTY.
Useful? React with 👍 / 👎.
| } | ||
|
|
||
| public struct CrashRecord: Codable, Sendable { | ||
| public var name: String |
There was a problem hiding this comment.
Match crash insight response fields
When /api/crash-insights has any recorded crashes, the broker returns recent entries with fields like agent_name, exit_code, timestamp, uptime_secs, category, and description, while patterns use category, count, and agents. This model requires absent fields such as name (and the pattern model below requires name/crashes/restarts), so getCrashInsights() starts throwing a decoding error precisely when diagnostics are present.
Useful? React with 👍 / 👎.
Motivation
Description
listAgents,sendInput,resizePty,flush,snapshot,sendMessage(full payload),setModel,subscribeChannels,unsubscribeChannels,getStatus,getMetrics,getCrashInsights,preflight, andrenewLeaseinAgentRelayClient/RelayCore.Codableparity types and fields inRelayTypes.swift(messagemode,SnapshotFormat,ListAgent,BrokerStatus,PendingDeliveryInfo,SendMessageResult,ModelUpdateResult,FlushResult,PreflightResult,RenewLeaseResult, metrics/crash types, and related keys) and added JSON key mappings to preserve wire compatibility.FoundationNetworkingwhen available soURLSession/WebSocket APIs compile on Linux, and added small helper utilities for URL/query/path escaping and JSON encode/decode helpers used by the new REST helpers.packages/sdk-swift/README.mdandCHANGELOG.mdto document the new public API surface and the user-visible parity change, and added unit tests validating send-message payload encoding and broker-status decoding.Testing
swift test --package-path packages/sdk-swiftand the Swift unit test suite passed (56 tests, 0 failures).npm --prefix packages/sdk testand the TypeScript SDK tests passed (107 tests, 0 failures).git diff --check(style/sanity) had no errors.python -m pytest packages/sdk-py/tests/test_send_message_mode.py packages/sdk-py/tests/test_builder.py, but test collection failed due to missing Python dependencies (aiohttp,pyyaml) and inability to fetch optional deps from PyPI in the current environment, so Python tests were not executed successfully in this run.Codex Task