refactor(sdk-swift): wrap relaycast engine SDK in hosted transport

Merged
WI
5mo ago
+660-1064

Summary

Refactors the hosted-participant path of the Swift SDK (AgentRelaySDK) to wrap relaycast's Swift engine SDK (Relaycast, package relaycast-swift) instead of hand-rolling URLSession/WebSocket. The local broker product AgentRelayBrokerSDK is untouched.

The bespoke HostedHTTP (RelayHTTP.swift) and RelayEventTransport (RelayTransport.swift) are deleted; all HTTP + realtime work is now delegated to Relaycast.RelayCast / Relaycast.AgentClient / Relaycast.WsClient. The relay-specific glue is kept on top.

Mapping (relay hosted -> relaycast)

relay hosted callrelaycast
register / registerOrRotate (409 -> get + rotate-token)RelayCast.agents.register / RelayCast.registerOrRotate
reconnect by token (GET /v1/agent)RelayCast.reconnect + AgentClient.me
workspace infoRelayCast.workspace.info
post channel / dmAgentClient.send / AgentClient.dm (mode .wait)
action register / deleteRelayCast.actions.register / .delete
invocation get / completeAgentClient.actions.getInvocation / .completeInvocation
WS subscribe + typed eventsAgentClient.subscribe + AgentClient.on (message.created, thread.reply, dm.received, group_dm.received, action.invoked)

Kept on top (unchanged behavior / signatures)

  • The action-dispatch loop: action.invoked -> loadInvocation -> handler -> completeInvocation.
  • The RelayChannelEvent shape and the AsyncStream-based public API.
  • All public type signatures of AgentRelayClient so callers don't break.

Hard constraints honored

  • Default base URL https://gateway.relaycast.dev is preserved and passed explicitly into RelayCastOptions.baseURL.
  • SwiftPM dependency added.

RegisterActionRequest upstream check

Relaycast.RegisterActionRequest (relaycast Models.swift) already carries handlerAgent (handler_agent) and inputSchema (input_schema). No upstream relaycast change was required.

SwiftPM dependency wiring (note for reviewers)

relaycast-swift lives in the relaycast monorepo under packages/sdk-swift โ€” not at the repo root โ€” so SwiftPM can't consume it by git URL directly, and its directory basename (sdk-swift) collides with this package's own SwiftPM identity. The dependency is therefore referenced through a committed relative symlink packages/sdk-swift/.relaycast-swift -> ../../../relaycast/packages/sdk-swift (a sibling clone of relaycast). Repoint the symlink for other checkout locations, or swap in a git/tag reference (e.g. from: "4.1.6") once a root-level relaycast-swift mirror is published. Documented in Package.swift and the README.

Verification

swift build and swift test both pass โ€” 69 tests, 0 failures (Swift 6.2.4 toolchain). Hosted tests were rewritten to cover facade config + bridging glue (the old tests mocked now-deleted internal transport types); broker and RelayObserver tests are unchanged.

๐Ÿค– Generated with Claude Code