Repository navigation
feat(functions): add context bindings - #23
Merged
Merged
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A function can now declare what it needs as a typed
Contextsubclass: a device, credential packages, a mailbox, a proxy and tasks. The runner provides each binding beforemainruns. In the cloud it uses the platform's resources. Locally it uses the command-line flags, or the cloud with your own key via--cloud. The same file runs unchanged in both places.Changes
Device,Credentials,Mailbox,ProxyandOperator, plusbinding(...). The declaration rules are checked when the function is loaded. A concrete implementation inCtxis rejected.inspectnow reports arequiresobject (device,credentials,mailbox,proxy,tasks), so the platform knows a function's needs before it runs.main. If one is missing, the run fails early withNotAvailableError, naming the field.MailboxandProxyare run resources, declared as bare annotations: the Input model stays pure business input, andbinding(input=...)and package options on them are refused at inspect. Theinputoption and themobilerun-mailbox/mobilerun-proxyformats are removed. AProxybinding needs aDevicebinding;inspectrefuses it otherwise.RunInfogainsmailbox_idandproxy(ProxyRef(kind, id), exported withRunInfo), set by--mailbox-idand the paired--proxy-kind/--proxy-id. A half pair, an unknown kind or an invalid UUID is a usage error beforemain.ctx.mailboxonly fromctx.run.mailbox_idandctx.proxyonly fromctx.run.proxy. Connect attaches the selected proxy once, beforemain, withdevices.proxy.connect(device_id, connect={"id": ...})and needs a cloud device;byois refused explicitly. Missing selections,byo, a local device and invalid IDs fail before any remote call, whatever the declaration order.type_field(device, field, *, name=None)andlist()take no package. In the cloud only the declared packages are read, one per-package request each; other packages' values never enter the run. A local file's flat entry binds to the declared package.wait_for_codecaptures one UTC baseline when the wait begins (unlessafteris passed) and forwardssenderandafterunchanged. A 204 keeps polling; 404, 409 and auth errors end the wait at once; the timeout and cancellation stop polling.device.do(...)anddevice.expect(...)run tasks on the bound device.expectraisesExpectationFailedorExpectationInconclusiveand returns only when the check passes.MOBILERUN_LOG=debug.mobilerun-screenshot-*in the temp directory); anything else is validated base64, so JPEGs starting with/9j/decode.mainruns on the runner's event loop, soasyncio.run(ctx.email.wait_for_code())is safe there.dry_runandverificationskip the connect andstatus()stays readable.deviceextra requiresmobilerun-core>=1.12.0,<2.ctxmethod buys, creates or deletes resources. Tasks consume usage like any other task.runflags--cloudand--credentials-file.deviceextra now includes the SDK and PyYAML.ctx: Contextandctx.device()keep working and log a deprecation warning.AI:ai: AI,ctx.ai.openai(), base URL = API base +/ai,requireskeyai, extramobilerun-functions[ai].examples/bindings.pyand the README now use the new form. Version 0.2.0rc1 (release candidate).Testing
uv sync --frozenpasses.requires, runner target selection, resolution failures, focus-checked credential typing, task polling and timeouts, per-package credential reads, bound typing, mailbox baseline and status handling, the Proxy-needs-Device rule, the threeexpectoutcomes, and the oldctx.device()path.Runtime
inspect examples/bindings.pyprints the expectedrequires.mainwith the documented error.Rollout
Release 0.2.0rc1 after merge. The platform image moves to it in a separate change. The platform already accepts
requires. The run-selected mailbox and proxy fields reach it in a separate change; no released consumer uses the removed input-bound form.