feat(mobile): a device lease carries agent-device client configuration

Merged
OK
2mo ago
+286-39

A DeviceLease can now carry client: agent-device client configuration the worker's client is created with, next to the daemon address, which becomes optional.

  • agent-device ships its own device-cloud runtimes (Limrun, BrowserStack, AWS Device Farm). Their daemon resolves a hosted device from the lease scope on each command: tenant, runId, leaseId, leaseBackend, leaseProvider, as leases.allocate returned it. A command without that scope falls back to the local inventory, and on a Mac with a booted simulator the test silently runs there while the hosted instance sits idle.
  • The engine's client only knew a session name and a daemon URL, so a provider on one of those runtimes had to put a proxy in front of the daemon that stamped the scope onto every request. Now it returns what leases.allocate gave it.
  • client.stateDir reaches a daemon the provider started for the run, so such a provider needs no daemon address at all. A lease names daemon, client, or both.
  • client is JSON data, since it travels to the worker through the environment under the existing 16 KiB cap. session, daemonBaseUrl, and daemonAuthToken stay with the engine and daemon; a lease setting them is refused at prepare.
  • DeviceClientConfig and DeviceConnection are exported. The mobile guide gains a second example, a provider on a device cloud through agent-device, typechecked like the first.
const lease = await client.leases.allocate({ tenant, runId, leaseBackend, leaseProvider, platform, target: 'mobile' });
return {
  id: lease.leaseId,
  client: { stateDir, tenant: lease.tenantId, runId: lease.runId, leaseId: lease.leaseId, leaseBackend, leaseProvider },
};
flowchart LR
  P[provider.acquire] -->|lease.client| B[SlotBinding in worker env]
  B --> F["createAgentDeviceClient({ ...client, session, daemonBaseUrl?, daemonAuthToken? })"]
  F --> D[daemon]
  D -->|lease scope on every command| H[hosted device]

Refs: packages/mobile/src/bindings.ts (DeviceClientConfig, isSlotBinding), packages/mobile/src/provider.ts (DeviceLease, isDeviceLease), packages/mobile/src/engine.ts (the client factory), docs/examples/mobile/device-cloud-provider.ts.


Devin Review