Skip to content

feat(connect): add @midscene/connect to serve any device over HTTP - #3430

Open
ottomao wants to merge 5 commits into
mainfrom
feat/connect
Open

ottomao wants to merge 5 commits into
mainfrom
feat/connect

Conversation

@ottomao

@ottomao ottomao commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds @midscene/connect (midscene-connect CLI), which replaces the Universal Device stack in midscene-test-everything with a much smaller design that lives in the main repo.

  • Device definition: one .mjs default-exports { name, description, pointerType, options, connect(options) }. connect() returns screenshot() plus a flat actions map. Keys that match core InputPrimitives names (tap, swipe, typeText, homeButton, …) are plain functions. Any other key is a custom action { description, params, call }. Primitive group rules are checked at startup: the keyboard trio must come together, and swipe needs pointerType.
  • Schemas: custom action params and device options use a small JSON Schema subset instead of zod. Anything outside the subset is rejected at startup, and request bodies are validated strictly. x-midscene-locate marks AI-located elements. The client converts the subset to zod for core planning.
  • midscene-connect serve <device.mjs> [--port --host --token --<device options>]: one process holds one device instance. Actions run one at a time, with no sessions or leases. The server ships Swagger at /api/docs/ and OpenAPI at /api/openapi.json. A token is required on non-loopback hosts and is auto-generated if not given.
  • @midscene/connect/server: createConnectHandler(device, { basePath, token }) for embedding into existing servers (e.g. iOS AirLink, which serves many phones).
  • Clients:
    • agentOverConnectProtocol({ url, token }): RemoteDevice rebuilds the action space with defineActionsFromInputPrimitives and adds the remote custom actions.
    • CLI commands generated through BaseMidsceneTools and runToolsCLI.
    • midscene-connect playground.
  • MCP is intentionally not included, following Retire MCP packages and keep Skills support #2694.
  • Docs: the package has README.md / README.zh.md, and integrate-with-any-interface (en/zh) on the site has a new "Connect a device without writing a class" section.

Validation

  • cd packages/connect && npx rstest: 19 tests pass. They cover the schema subset, device validation, and a real serveDevice driven by RemoteDevice: primitives, custom actions, 400/401/404, OpenAPI, agent context.
  • cd packages/connect && npx tsc --noEmit -p tsconfig.json
  • npx nx build connect
  • pnpm run lint
  • pnpm install --frozen-lockfile
  • Manual: served tests/fixtures/mock-device.mjs, then ran:
    • curl against every endpoint
    • CLI --help, take_screenshot, homebutton, input, and the custom action
    • midscene-connect playground --no-open: page loads and the action space is exposed
  • Not run: act/assert against a real model.

Follow-ups

  • MJPEG preview stream.
  • Propagating aborts to device implementations.

Describe a device in one .mjs file (screenshot + input primitives + custom
actions), run `midscene-connect serve` to expose it with an OpenAPI/Swagger
documented HTTP protocol, then drive it via agentOverConnectProtocol, the
generated CLI commands, or the Playground.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Deploying midscene with  Cloudflare Pages  Cloudflare Pages

Latest commit: be04e92
Status: ✅  Deploy successful!
Preview URL: https://72de40e0.midscene.pages.dev
Branch Preview URL: https://feat-connect.midscene.pages.dev

View logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants