agent-device 0.21.37 → 0.21.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.37.apk → agent-device-android-ime-helper-0.21.38.apk} +0 -0
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.38.apk.sha256 +1 -0
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.37.manifest.json → agent-device-android-ime-helper-0.21.38.manifest.json} +4 -4
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.37.apk → agent-device-android-snapshot-helper-0.21.38.apk} +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.38.apk.sha256 +1 -0
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.37.manifest.json → agent-device-android-snapshot-helper-0.21.38.manifest.json} +7 -7
- package/apple/fold-helper/Fold.m +8 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerKeyboardReturnKey.swift +53 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AXSnapshotFallback.swift +42 -4
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +26 -18
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +42 -11
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Keyboard.swift +123 -22
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +7 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Navigation.swift +570 -53
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +41 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerXCTestEventBridge.h +7 -0
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerXCTestEventBridge.m +17 -1
- package/dist/src/THIRD_PARTY_NOTICES.txt +2 -2
- package/dist/src/absence-observation-errors.js +1 -1
- package/dist/src/absence-observation.js +1 -1
- package/dist/src/adapter.js +1 -1
- package/dist/src/adb-executor.js +1 -1
- package/dist/src/adb-failure.js +2 -2
- package/dist/src/adb-transport.js +1 -1
- package/dist/src/agent-browser-lifecycle.js +1 -1
- package/dist/src/agent-browser-process-record.js +1 -1
- package/dist/src/agent-browser-provider.js +1 -1
- package/dist/src/agent-browser-tool.js +1 -1
- package/dist/src/ai-sdk.d.ts +1 -1
- package/dist/src/ai-sdk.js +1 -1
- package/dist/src/alert-contract.js +1 -1
- package/dist/src/alert-tree-driver.js +1 -1
- package/dist/src/alert.js +1 -1
- package/dist/src/android-adb.d.ts +1 -1
- package/dist/src/android.js +1 -1
- package/dist/src/android2.js +1 -1
- package/dist/src/app-backend.js +1 -1
- package/dist/src/app-catalog.js +1 -1
- package/dist/src/app-deployment-resolution.js +1 -1
- package/dist/src/app-inventory.js +1 -1
- package/dist/src/app-launch.js +1 -1
- package/dist/src/app-lifecycle.js +4 -4
- package/dist/src/app-lifecycle2.js +2 -2
- package/dist/src/app-log-files.js +1 -1
- package/dist/src/app-log-runtime2.js +2 -2
- package/dist/src/app-log-session-resource.js +1 -1
- package/dist/src/app-resolution.js +1 -1
- package/dist/src/app-state-read.js +1 -1
- package/dist/src/app-state-runtime.d.ts +1 -1
- package/dist/src/application-lifecycle-interaction.js +1 -1
- package/dist/src/archive.js +1 -1
- package/dist/src/args.js +1 -1
- package/dist/src/artifact-download.js +1 -1
- package/dist/src/artifact-tracking.js +1 -1
- package/dist/src/auth-session.js +1 -1
- package/dist/src/auth.js +1 -1
- package/dist/src/automation-helper-artifact.js +1 -1
- package/dist/src/automation-helper.js +1 -1
- package/dist/src/await-with-signal.js +1 -1
- package/dist/src/backend-snapshot-options.js +1 -1
- package/dist/src/boot-diagnostics.js +1 -1
- package/dist/src/bridge-source.js +1 -1
- package/dist/src/browser-launch.js +1 -1
- package/dist/src/browserstack-device-features.js +1 -1
- package/dist/src/browserstack.js +1 -1
- package/dist/src/cache.js +1 -1
- package/dist/src/capture-disclosure.js +1 -1
- package/dist/src/capture-lifecycle.js +1 -1
- package/dist/src/cli-config.js +1 -1
- package/dist/src/cli-help.js +19 -16
- package/dist/src/cli-output.js +11 -11
- package/dist/src/cli-runner.js +1 -1
- package/dist/src/cli.js +2 -2
- package/dist/src/click-button.js +1 -1
- package/dist/src/client-metro-companion.js +1 -1
- package/dist/src/client-metro.js +1 -1
- package/dist/src/client-options.js +1 -1
- package/dist/src/client-port.d.ts +246 -208
- package/dist/src/clipboard-shell-response.js +1 -1
- package/dist/src/cloud-artifacts.d.ts +7 -2
- package/dist/src/code-signature-cache.js +1 -1
- package/dist/src/command-schema.js +6 -4
- package/dist/src/command-tools.js +3 -3
- package/dist/src/command.js +1 -1
- package/dist/src/composed-inventory-gateways.js +1 -1
- package/dist/src/composite-resource-admission.js +1 -1
- package/dist/src/config.js +1 -1
- package/dist/src/connection-lease-transaction.js +1 -1
- package/dist/src/connection-metro-runtime.js +1 -1
- package/dist/src/connection-runtime.js +1 -1
- package/dist/src/connection-verification.js +1 -1
- package/dist/src/connection.js +3 -3
- package/dist/src/context.js +1 -1
- package/dist/src/contract.d.ts +2 -1
- package/dist/src/contracts.d.ts +1 -1
- package/dist/src/contracts.js +1 -1
- package/dist/src/daemon-client-attach.js +1 -1
- package/dist/src/daemon-client-dispatch-disclosure.js +1 -1
- package/dist/src/daemon-client-ensure.js +1 -1
- package/dist/src/daemon-client-ensuring.js +1 -1
- package/dist/src/daemon-client-lease-beat.js +1 -1
- package/dist/src/daemon-client-lifecycle.js +1 -1
- package/dist/src/daemon-client-liveness-probe.js +1 -1
- package/dist/src/daemon-client-remote-health-cache.js +1 -0
- package/dist/src/daemon-client-remote-health-recovery.js +1 -0
- package/dist/src/daemon-client-transport.js +1 -1
- package/dist/src/daemon-command-registry.js +1 -1
- package/dist/src/daemon-composition.js +1 -1
- package/dist/src/daemon-diagnostics-scope.js +1 -1
- package/dist/src/daemon-http.js +1 -1
- package/dist/src/daemon-launch-spec.js +1 -1
- package/dist/src/daemon-lifecycle-errors.js +1 -1
- package/dist/src/daemon-policy-file.js +1 -1
- package/dist/src/daemon-registration-owner.js +3 -3
- package/dist/src/daemon-registration.js +1 -1
- package/dist/src/daemon-resolution.js +1 -1
- package/dist/src/daemon-startup-diagnostics.js +1 -1
- package/dist/src/daemon-stop.js +1 -1
- package/dist/src/daemon.js +1 -1
- package/dist/src/debug-symbols-facade.js +3 -3
- package/dist/src/device-claim-admission.js +1 -0
- package/dist/src/device-claim-reconciliation.js +1 -0
- package/dist/src/device-claim-recovery.js +1 -1
- package/dist/src/device-claim-rule.js +1 -1
- package/dist/src/device-claims.js +1 -1
- package/dist/src/device-input-state.d.ts +1 -1
- package/dist/src/device-inventory-context.js +1 -1
- package/dist/src/device-selection-resolver.js +1 -1
- package/dist/src/device-session.js +1 -1
- package/dist/src/device-shell.js +1 -1
- package/dist/src/device.js +1 -1
- package/dist/src/device3.js +3 -3
- package/dist/src/devicectl.js +1 -1
- package/dist/src/diagnostics.js +1 -1
- package/dist/src/discovery.js +1 -1
- package/dist/src/dispatch-resolve.js +1 -1
- package/dist/src/display-inventory.js +1 -1
- package/dist/src/doctor-facade.js +1 -1
- package/dist/src/doctor2.js +1 -1
- package/dist/src/durable-capture-resource.js +1 -1
- package/dist/src/durable-capture.js +1 -1
- package/dist/src/durable-resource.js +1 -1
- package/dist/src/ended-lease.js +1 -1
- package/dist/src/engine-eval-script.js +1 -1
- package/dist/src/error.js +2 -2
- package/dist/src/errors.js +1 -1
- package/dist/src/explicit-session-resolution.js +1 -1
- package/dist/src/expo-dev-client-launch.js +1 -1
- package/dist/src/failure-output.js +1 -1
- package/dist/src/file.js +1 -1
- package/dist/src/find.js +1 -1
- package/dist/src/finders.js +1 -1
- package/dist/src/flag-registry.js +1 -1
- package/dist/src/focus-runtime.js +1 -1
- package/dist/src/fold-helper.js +1 -1
- package/dist/src/generic-settle.js +1 -1
- package/dist/src/generic.js +1 -1
- package/dist/src/gesture-admission.js +1 -1
- package/dist/src/gesture-plan-types.d.ts +1 -1
- package/dist/src/gesture-plan.js +1 -1
- package/dist/src/gesture-runtime.js +1 -1
- package/dist/src/hdc.js +1 -1
- package/dist/src/helper-artifacts.js +1 -1
- package/dist/src/helper.js +2 -2
- package/dist/src/host-file.js +1 -1
- package/dist/src/host.js +1 -1
- package/dist/src/host2.js +1 -1
- package/dist/src/host3.js +1 -1
- package/dist/src/host4.js +1 -1
- package/dist/src/host5.js +1 -1
- package/dist/src/host6.js +1 -1
- package/dist/src/human-control-contract.js +1 -1
- package/dist/src/human-control.js +1 -1
- package/dist/src/ime-rebind.js +1 -1
- package/dist/src/ime-settings-record.js +1 -1
- package/dist/src/ime-state.js +1 -1
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.js +1 -1
- package/dist/src/input-actions.js +1 -1
- package/dist/src/input-actions2.js +1 -1
- package/dist/src/install-artifact-facade.js +1 -1
- package/dist/src/install-source-network-transport.js +1 -1
- package/dist/src/install-source2.js +1 -1
- package/dist/src/interaction-error.js +1 -1
- package/dist/src/interaction-positionals.js +1 -1
- package/dist/src/interaction-ref-policy.js +1 -1
- package/dist/src/interaction2.js +1 -1
- package/dist/src/interactor-operation-binding.js +1 -1
- package/dist/src/interactor.js +5 -5
- package/dist/src/interactor2.js +1 -1
- package/dist/src/interactor3.js +1 -1
- package/dist/src/interactor4.js +1 -1
- package/dist/src/interactor5.js +1 -1
- package/dist/src/interactors.js +1 -1
- package/dist/src/internal/bin.js +1 -1
- package/dist/src/internal/companion-tunnel.js +1 -1
- package/dist/src/internal/daemon.js +1 -1
- package/dist/src/internal/png-worker.js +1 -1
- package/dist/src/internal/run-script-child.js +1 -1
- package/dist/src/inventory.js +1 -1
- package/dist/src/inventory2.js +1 -1
- package/dist/src/inventory3.js +1 -1
- package/dist/src/inventory5.js +1 -1
- package/dist/src/ios-node-interpretation.js +1 -1
- package/dist/src/ios-simulator-accessibility.js +1 -1
- package/dist/src/ios-snapshot-acquisition.js +1 -1
- package/dist/src/ios-snapshot-engine.js +1 -1
- package/dist/src/ios-snapshot-runtime.js +1 -1
- package/dist/src/launch-confirmation.js +1 -1
- package/dist/src/launch-services-registration.js +1 -1
- package/dist/src/lease-context.js +1 -1
- package/dist/src/lease-registry-scope.js +1 -1
- package/dist/src/lease-release2.js +1 -1
- package/dist/src/lease-scope.js +1 -1
- package/dist/src/lease.js +1 -1
- package/dist/src/leased-recording-retention.js +1 -1
- package/dist/src/legacy.js +1 -1
- package/dist/src/limrun-download-file.js +1 -1
- package/dist/src/limrun-ios-files.js +1 -1
- package/dist/src/limrun-ios-runner.js +2 -2
- package/dist/src/limrun-runtime-dependencies.js +1 -1
- package/dist/src/limrun.d.ts +1 -1
- package/dist/src/local-interactor-operation-set.js +1 -1
- package/dist/src/local-simulator-apps.js +1 -1
- package/dist/src/local-simulator-files.js +1 -1
- package/dist/src/location-coordinates.js +1 -1
- package/dist/src/manifest.js +1 -1
- package/dist/src/mechanics.js +12 -12
- package/dist/src/merge-flags.js +1 -1
- package/dist/src/metro-reload-endpoints.js +1 -1
- package/dist/src/metro-session-hints.js +1 -1
- package/dist/src/metro.d.ts +1 -1
- package/dist/src/mobile-snapshot-semantics.js +1 -1
- package/dist/src/network-traffic.js +1 -1
- package/dist/src/node-http.js +1 -1
- package/dist/src/node-touch-point.js +1 -1
- package/dist/src/observation.js +1 -1
- package/dist/src/open-script.js +1 -1
- package/dist/src/open-target-device-resolution.js +1 -1
- package/dist/src/orientation.js +1 -1
- package/dist/src/parameterized-recorded-fill.js +1 -1
- package/dist/src/perf-facade.js +1 -1
- package/dist/src/perf-runtime-operation-builder.js +1 -1
- package/dist/src/perf-runtime-plan.js +1 -1
- package/dist/src/perf-target.js +2 -2
- package/dist/src/perf.js +1 -1
- package/dist/src/physical-device-control.js +1 -1
- package/dist/src/platform-runtime-android-adb-host.js +1 -1
- package/dist/src/platform-runtime-app-log-process.js +1 -1
- package/dist/src/platform-runtime-apple-application-tools.js +1 -1
- package/dist/src/platform-runtime-claim-recovery.js +1 -1
- package/dist/src/platform-runtime-host.js +1 -1
- package/dist/src/platform-runtime-open-target.js +1 -1
- package/dist/src/platform-runtime-operation-host.js +3 -3
- package/dist/src/platform-runtime-runtime-hints.js +1 -1
- package/dist/src/platform-runtime-screen-recording-apple-runner-transport.js +1 -1
- package/dist/src/platform-runtime-screen-recording-apple-simulator-host.js +1 -1
- package/dist/src/platform-runtime-screen-recording-finalizer-host.js +1 -1
- package/dist/src/platform-runtime-screen-recording-process-host.js +1 -1
- package/dist/src/platform-runtime-shutdown-error.js +1 -1
- package/dist/src/platform-runtime-unavailable.js +1 -1
- package/dist/src/platform-runtime.js +1 -1
- package/dist/src/platform-runtime2.js +1 -1
- package/dist/src/plist.js +1 -1
- package/dist/src/plugins2.js +1 -1
- package/dist/src/png-crop-bytes.js +1 -1
- package/dist/src/png-resize.js +1 -1
- package/dist/src/png-size.js +1 -1
- package/dist/src/png-worker-client.js +1 -1
- package/dist/src/png.js +1 -1
- package/dist/src/post-gesture-stability.js +1 -1
- package/dist/src/process-executable-path.js +1 -0
- package/dist/src/process-exit.js +1 -1
- package/dist/src/provider-device-runtime.d.ts +2 -2
- package/dist/src/provider-limrun-credentials.js +1 -1
- package/dist/src/provider-plugin.d.ts +1 -1
- package/dist/src/provider-profile-fields.js +1 -1
- package/dist/src/provider-webdriver.js +1 -1
- package/dist/src/provider.js +1 -1
- package/dist/src/proxy.js +2 -2
- package/dist/src/react-devtools-connection.js +1 -1
- package/dist/src/react-devtools-inspect-command.js +1 -1
- package/dist/src/react-native-overlay2.js +2 -2
- package/dist/src/react-native.js +1 -1
- package/dist/src/react-profile-command.js +1 -1
- package/dist/src/record-runtime.js +1 -1
- package/dist/src/record-trace.js +1 -1
- package/dist/src/recording-gestures.js +1 -1
- package/dist/src/recording.js +1 -1
- package/dist/src/rect-center.js +1 -1
- package/dist/src/register-builtins.js +1 -1
- package/dist/src/registry.js +1 -1
- package/dist/src/remote-config-core.js +1 -1
- package/dist/src/remote-config-flags.js +1 -1
- package/dist/src/remote-connection-state.js +1 -1
- package/dist/src/replay-backend-host.js +1 -1
- package/dist/src/replay-divergence.js +1 -1
- package/dist/src/replay-maestro-backend.js +2 -2
- package/dist/src/replay.d.ts +1 -1
- package/dist/src/replay2.js +1 -1
- package/dist/src/reporting.js +1 -1
- package/dist/src/request-dispatch-disclosure.js +1 -1
- package/dist/src/request-ended-leases.js +1 -1
- package/dist/src/request-providers.js +1 -1
- package/dist/src/request-runtime-binding.js +1 -1
- package/dist/src/request.js +1 -1
- package/dist/src/result-serialization.js +2 -2
- package/dist/src/retry.js +1 -1
- package/dist/src/run-script-execution.js +6 -8
- package/dist/src/run-script-http.js +1 -1
- package/dist/src/runner-cache-metadata.js +1 -1
- package/dist/src/runner-cache-retention.js +1 -1
- package/dist/src/runner-client.js +1 -1
- package/dist/src/runner-contract.js +1 -1
- package/dist/src/runner-dev-tools-security.js +1 -1
- package/dist/src/runner-device-readiness.js +1 -1
- package/dist/src/runner-device-set.js +1 -1
- package/dist/src/runner-disposal.js +1 -1
- package/dist/src/runner-error-classification.js +2 -2
- package/dist/src/runner-exchange.js +1 -1
- package/dist/src/runner-io.js +1 -1
- package/dist/src/runner-launched-session.js +1 -1
- package/dist/src/runner-lease.js +1 -1
- package/dist/src/runner-lifecycle.js +1 -1
- package/dist/src/runner-operations-facade.js +1 -1
- package/dist/src/runner-panel.js +1 -1
- package/dist/src/runner-retention.js +1 -1
- package/dist/src/runner-runtime.js +1 -1
- package/dist/src/runner-selector-query.js +1 -1
- package/dist/src/runner-sequence.js +1 -1
- package/dist/src/runner-start-budget.js +1 -1
- package/dist/src/runner-startup-transport.js +1 -1
- package/dist/src/runner-toolchain-identity.js +1 -1
- package/dist/src/runtime-admission.js +1 -1
- package/dist/src/runtime-deployment.js +1 -1
- package/dist/src/runtime-factory.js +1 -1
- package/dist/src/runtime-session.js +1 -1
- package/dist/src/runtime-transport-hints.js +1 -1
- package/dist/src/runtime.js +2 -2
- package/dist/src/runtime10.js +1 -1
- package/dist/src/runtime11.js +1 -1
- package/dist/src/runtime12.js +1 -1
- package/dist/src/runtime13.js +2 -2
- package/dist/src/runtime2.js +2 -2
- package/dist/src/runtime4.js +3 -3
- package/dist/src/runtime5.js +1 -1
- package/dist/src/runtime6.js +1 -1
- package/dist/src/runtime7.js +2 -2
- package/dist/src/runtime8.js +1 -1
- package/dist/src/runtime9.js +1 -1
- package/dist/src/screen-recording-admission-ledger.js +1 -0
- package/dist/src/screen-recording-completion.js +1 -1
- package/dist/src/screen-recording-options.js +1 -1
- package/dist/src/screen-recording-resource-recovery.js +1 -1
- package/dist/src/screen-recording-stop-recovery.js +1 -1
- package/dist/src/screen-recording-transport.js +1 -1
- package/dist/src/screenshot-density.js +1 -1
- package/dist/src/screenshot-image-size.js +1 -1
- package/dist/src/screenshot-image.js +1 -1
- package/dist/src/screenshot-runtime.js +1 -1
- package/dist/src/screenshot-runtime2.js +1 -1
- package/dist/src/screenshot.js +1 -1
- package/dist/src/screenshot2.js +1 -1
- package/dist/src/screenshot4.js +1 -1
- package/dist/src/script-source.js +1 -1
- package/dist/src/script.js +1 -1
- package/dist/src/scroll-command.js +1 -1
- package/dist/src/scroll-gesture.js +1 -1
- package/dist/src/sdk-batch-runner.d.ts +1 -1
- package/dist/src/sdk-batch-runner.js +2 -2
- package/dist/src/sdk-batch.js +2 -2
- package/dist/src/sdk-contracts.d.ts +26 -2
- package/dist/src/sdk-contracts.js +2 -2
- package/dist/src/sdk-device.js +1 -1
- package/dist/src/sdk-finders.d.ts +1 -1
- package/dist/src/sdk-finders.js +1 -1
- package/dist/src/sdk-io.js +5 -5
- package/dist/src/sdk-remote-config.d.ts +1 -1
- package/dist/src/sdk-remote-config.js +1 -1
- package/dist/src/sdk-selectors.d.ts +9 -6
- package/dist/src/sdk-selectors.js +1 -1
- package/dist/src/selection.js +0 -0
- package/dist/src/selector-pipeline-policy.js +1 -1
- package/dist/src/selector-runtime.js +1 -1
- package/dist/src/selectors.js +1 -1
- package/dist/src/server-shutdown.js +1 -1
- package/dist/src/server-startup.js +2 -2
- package/dist/src/server.js +4 -4
- package/dist/src/session-allocation.js +1 -1
- package/dist/src/session-artifact-paths.js +1 -1
- package/dist/src/session-capture-binding.js +1 -1
- package/dist/src/session-device-resolution.js +1 -1
- package/dist/src/session-event-action.js +1 -1
- package/dist/src/session-open.js +1 -1
- package/dist/src/session-repair-tombstone.js +1 -1
- package/dist/src/session-replay-vars.js +1 -1
- package/dist/src/session-routing.js +1 -1
- package/dist/src/session-runtime-admission.js +1 -1
- package/dist/src/session-runtime.js +1 -1
- package/dist/src/session-script-destination.js +1 -0
- package/dist/src/session-selector.js +1 -1
- package/dist/src/session-store.js +3 -3
- package/dist/src/session-teardown.js +1 -1
- package/dist/src/session-tenant-scope.js +1 -1
- package/dist/src/session2.js +5 -5
- package/dist/src/settings-bluetooth.js +1 -1
- package/dist/src/settings-global-toggle.js +1 -1
- package/dist/src/settings.js +1 -1
- package/dist/src/settings2.js +1 -1
- package/dist/src/settle-observation-capture.js +1 -1
- package/dist/src/simctl-execution.js +1 -1
- package/dist/src/simctl-facade.js +1 -1
- package/dist/src/simctl.js +1 -1
- package/dist/src/simulator-app-budget.js +1 -1
- package/dist/src/simulator-boot.js +1 -1
- package/dist/src/simulator-facade.js +1 -1
- package/dist/src/simulator-state.js +1 -1
- package/dist/src/simulator.js +1 -1
- package/dist/src/snapshot-baseline.js +1 -1
- package/dist/src/snapshot-chrome.js +1 -1
- package/dist/src/snapshot-desktop-projection.js +1 -1
- package/dist/src/snapshot-diagnostics.js +1 -1
- package/dist/src/snapshot-helper-install.js +3 -3
- package/dist/src/snapshot-helper-session.js +1 -1
- package/dist/src/snapshot-lines.js +1 -1
- package/dist/src/snapshot-node-lookup.js +1 -1
- package/dist/src/snapshot-occlusion.js +1 -1
- package/dist/src/snapshot-private-evidence.js +1 -1
- package/dist/src/snapshot-runtime-binding.js +1 -1
- package/dist/src/snapshot-runtime-capture-input.js +1 -1
- package/dist/src/snapshot-runtime.js +1 -1
- package/dist/src/snapshot-state.js +1 -1
- package/dist/src/snapshot.js +1 -1
- package/dist/src/snapshot2.js +1 -1
- package/dist/src/snapshot3.js +2 -2
- package/dist/src/snapshot4.js +1 -1
- package/dist/src/source-channel.js +1 -1
- package/dist/src/src.js +1 -1
- package/dist/src/src10.js +1 -1
- package/dist/src/src11.js +1 -1
- package/dist/src/src2.js +1 -1
- package/dist/src/src3.js +5 -5
- package/dist/src/src4.js +2 -2
- package/dist/src/src5.js +1 -1
- package/dist/src/src6.js +1 -1
- package/dist/src/src8.js +1 -1
- package/dist/src/store-legacy.js +1 -1
- package/dist/src/store.js +1 -1
- package/dist/src/string-enum.js +1 -1
- package/dist/src/surface-snapshot.js +1 -1
- package/dist/src/surface-snapshot2.js +1 -1
- package/dist/src/sync-cache.js +1 -1
- package/dist/src/system-surface-foreground.js +2 -2
- package/dist/src/takeover.js +1 -1
- package/dist/src/tap-keyboard-occlusion.js +1 -1
- package/dist/src/target-evidence-tree.js +1 -1
- package/dist/src/target-evidence.js +1 -1
- package/dist/src/telephony-runtime.js +1 -1
- package/dist/src/tool-provider-facade.js +1 -1
- package/dist/src/tool-provider.js +3 -3
- package/dist/src/tool-provider2.js +1 -1
- package/dist/src/tool-provider3.js +1 -1
- package/dist/src/toolchain-probe.js +1 -1
- package/dist/src/touch-runtime.js +1 -1
- package/dist/src/touch-runtime2.js +1 -1
- package/dist/src/transport.js +2 -2
- package/dist/src/tree.js +1 -1
- package/dist/src/tv-remote-runtime.js +1 -1
- package/dist/src/tv-remote.js +1 -1
- package/dist/src/type-text-runtime.js +1 -1
- package/dist/src/unsupported-interactor.js +1 -1
- package/dist/src/update-check.js +1 -1
- package/dist/src/validation.js +1 -1
- package/dist/src/vars.js +1 -1
- package/dist/src/vega-executable.js +1 -1
- package/dist/src/verified-file.js +1 -1
- package/dist/src/video.js +2 -2
- package/dist/src/viewport.js +1 -1
- package/dist/src/web.js +1 -1
- package/dist/src/webdriver-source.js +1 -1
- package/package.json +2 -2
- package/server.json +2 -2
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.37.apk.sha256 +0 -1
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.37.apk.sha256 +0 -1
- package/dist/src/capture-output-ownership.js +0 -1
package/dist/src/png.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e,t}from"./rolldown-runtime.js";import{P as n}from"./sdk-contracts.js";var r=t(((t,n)=>{let r=e(`util`),i=e(`stream`),a=n.exports=function(){i.call(this),this._buffers=[],this._buffered=0,this._reads=[],this._paused=!1,this._encoding=`utf8`,this.writable=!0};r.inherits(a,i),a.prototype.read=function(e,t){this._reads.push({length:Math.abs(e),allowLess:e<0,func:t}),process.nextTick(function(){this._process(),this._paused&&this._reads&&this._reads.length>0&&(this._paused=!1,this.emit(`drain`))}.bind(this))},a.prototype.write=function(e,t){if(!this.writable)return this.emit(`error`,Error(`Stream not writable`)),!1;let n;return n=Buffer.isBuffer(e)?e:Buffer.from(e,t||this._encoding),this._buffers.push(n),this._buffered+=n.length,this._process(),this._reads&&this._reads.length===0&&(this._paused=!0),this.writable&&!this._paused},a.prototype.end=function(e,t){e&&this.write(e,t),this.writable=!1,this._buffers&&(this._buffers.length===0?this._end():(this._buffers.push(null),this._process()))},a.prototype.destroySoon=a.prototype.end,a.prototype._end=function(){this._reads.length>0&&this.emit(`error`,Error(`Unexpected end of input`)),this.destroy()},a.prototype.destroy=function(){this._buffers&&(this.writable=!1,this._reads=null,this._buffers=null,this.emit(`close`))},a.prototype._processReadAllowingLess=function(e){this._reads.shift();let t=this._buffers[0];t.length>e.length?(this._buffered-=e.length,this._buffers[0]=t.slice(e.length),e.func.call(this,t.slice(0,e.length))):(this._buffered-=t.length,this._buffers.shift(),e.func.call(this,t))},a.prototype._processRead=function(e){this._reads.shift();let t=0,n=0,r=Buffer.alloc(e.length);for(;t<e.length;){let i=this._buffers[n++],a=Math.min(i.length,e.length-t);i.copy(r,t,0,a),t+=a,a!==i.length&&(this._buffers[--n]=i.slice(a))}n>0&&this._buffers.splice(0,n),this._buffered-=e.length,e.func.call(this,r)},a.prototype._process=function(){try{for(;this._buffered>0&&this._reads&&this._reads.length>0;){let e=this._reads[0];if(e.allowLess)this._processReadAllowingLess(e);else if(this._buffered>=e.length)this._processRead(e);else break}this._buffers&&!this.writable&&this._end()}catch(e){this.emit(`error`,e)}}})),i=t((e=>{let t=[{x:[0],y:[0]},{x:[4],y:[0]},{x:[0,4],y:[4]},{x:[2,6],y:[0,4]},{x:[0,2,4,6],y:[2,6]},{x:[1,3,5,7],y:[0,2,4,6]},{x:[0,1,2,3,4,5,6,7],y:[1,3,5,7]}];e.getImagePasses=function(e,n){let r=[],i=e%8,a=n%8,o=(e-i)/8,s=(n-a)/8;for(let e=0;e<t.length;e++){let n=t[e],c=o*n.x.length,l=s*n.y.length;for(let e=0;e<n.x.length&&n.x[e]<i;e++)c++;for(let e=0;e<n.y.length&&n.y[e]<a;e++)l++;c>0&&l>0&&r.push({width:c,height:l,index:e})}return r},e.getInterlaceIterator=function(e){return function(n,r,i){let a=n%t[i].x.length,o=(n-a)/t[i].x.length*8+t[i].x[a],s=r%t[i].y.length,c=(r-s)/t[i].y.length*8+t[i].y[s];return o*4+c*e*4}}})),a=t(((e,t)=>{t.exports=function(e,t,n){let r=e+t-n,i=Math.abs(r-e),a=Math.abs(r-t),o=Math.abs(r-n);return i<=a&&i<=o?e:a<=o?t:n}})),o=t(((e,t)=>{let n=i(),r=a();function o(e,t,n){let r=e*t;return n!==8&&(r=Math.ceil(r/(8/n))),r}let s=t.exports=function(e,t){let r=e.width,i=e.height,a=e.interlace,s=e.bpp,c=e.depth;if(this.read=t.read,this.write=t.write,this.complete=t.complete,this._imageIndex=0,this._images=[],a){let e=n.getImagePasses(r,i);for(let t=0;t<e.length;t++)this._images.push({byteWidth:o(e[t].width,s,c),height:e[t].height,lineIndex:0})}else this._images.push({byteWidth:o(r,s,c),height:i,lineIndex:0});this._xComparison=c===8?s:c===16?s*2:1};s.prototype.start=function(){this.read(this._images[this._imageIndex].byteWidth+1,this._reverseFilterLine.bind(this))},s.prototype._unFilterType1=function(e,t,n){let r=this._xComparison,i=r-1;for(let a=0;a<n;a++){let n=e[1+a],o=a>i?t[a-r]:0;t[a]=n+o}},s.prototype._unFilterType2=function(e,t,n){let r=this._lastLine;for(let i=0;i<n;i++){let n=e[1+i],a=r?r[i]:0;t[i]=n+a}},s.prototype._unFilterType3=function(e,t,n){let r=this._xComparison,i=r-1,a=this._lastLine;for(let o=0;o<n;o++){let n=e[1+o],s=a?a[o]:0,c=o>i?t[o-r]:0,l=Math.floor((c+s)/2);t[o]=n+l}},s.prototype._unFilterType4=function(e,t,n){let i=this._xComparison,a=i-1,o=this._lastLine;for(let s=0;s<n;s++){let n=e[1+s],c=o?o[s]:0,l=s>a?t[s-i]:0,u=s>a&&o?o[s-i]:0,d=r(l,c,u);t[s]=n+d}},s.prototype._reverseFilterLine=function(e){let t=e[0],n,r=this._images[this._imageIndex],i=r.byteWidth;if(t===0)n=e.slice(1,i+1);else switch(n=Buffer.alloc(i),t){case 1:this._unFilterType1(e,n,i);break;case 2:this._unFilterType2(e,n,i);break;case 3:this._unFilterType3(e,n,i);break;case 4:this._unFilterType4(e,n,i);break;default:throw Error(`Unrecognised filter type - `+t)}this.write(n),r.lineIndex++,r.lineIndex>=r.height?(this._lastLine=null,this._imageIndex++,r=this._images[this._imageIndex]):this._lastLine=n,r?this.read(r.byteWidth+1,this._reverseFilterLine.bind(this)):(this._lastLine=null,this.complete())}})),s=t(((t,n)=>{let i=e(`util`),a=r(),s=o(),c=n.exports=function(e){a.call(this);let t=[],n=this;this._filter=new s(e,{read:this.read.bind(this),write:function(e){t.push(e)},complete:function(){n.emit(`complete`,Buffer.concat(t))}}),this._filter.start()};i.inherits(c,a)})),c=t(((e,t)=>{t.exports={PNG_SIGNATURE:[137,80,78,71,13,10,26,10],TYPE_IHDR:1229472850,TYPE_IEND:1229278788,TYPE_IDAT:1229209940,TYPE_PLTE:1347179589,TYPE_tRNS:1951551059,TYPE_gAMA:1732332865,COLORTYPE_GRAYSCALE:0,COLORTYPE_PALETTE:1,COLORTYPE_COLOR:2,COLORTYPE_ALPHA:4,COLORTYPE_PALETTE_COLOR:3,COLORTYPE_COLOR_ALPHA:6,COLORTYPE_TO_BPP_MAP:{0:1,2:3,3:1,4:2,6:4},GAMMA_DIVISION:1e5}})),l=t(((e,t)=>{let n=[];(function(){for(let e=0;e<256;e++){let t=e;for(let e=0;e<8;e++)t&1?t=3988292384^t>>>1:t>>>=1;n[e]=t}})();let r=t.exports=function(){this._crc=-1};r.prototype.write=function(e){for(let t=0;t<e.length;t++)this._crc=n[(this._crc^e[t])&255]^this._crc>>>8;return!0},r.prototype.crc32=function(){return this._crc^-1},r.crc32=function(e){let t=-1;for(let r=0;r<e.length;r++)t=n[(t^e[r])&255]^t>>>8;return t^-1}})),u=t(((e,t)=>{let n=c(),r=l(),i=t.exports=function(e,t){this._options=e,e.checkCRC=e.checkCRC!==!1,this._hasIHDR=!1,this._hasIEND=!1,this._emittedHeadersFinished=!1,this._palette=[],this._colorType=0,this._chunks={},this._chunks[n.TYPE_IHDR]=this._handleIHDR.bind(this),this._chunks[n.TYPE_IEND]=this._handleIEND.bind(this),this._chunks[n.TYPE_IDAT]=this._handleIDAT.bind(this),this._chunks[n.TYPE_PLTE]=this._handlePLTE.bind(this),this._chunks[n.TYPE_tRNS]=this._handleTRNS.bind(this),this._chunks[n.TYPE_gAMA]=this._handleGAMA.bind(this),this.read=t.read,this.error=t.error,this.metadata=t.metadata,this.gamma=t.gamma,this.transColor=t.transColor,this.palette=t.palette,this.parsed=t.parsed,this.inflateData=t.inflateData,this.finished=t.finished,this.simpleTransparency=t.simpleTransparency,this.headersFinished=t.headersFinished||function(){}};i.prototype.start=function(){this.read(n.PNG_SIGNATURE.length,this._parseSignature.bind(this))},i.prototype._parseSignature=function(e){let t=n.PNG_SIGNATURE;for(let n=0;n<t.length;n++)if(e[n]!==t[n]){this.error(Error(`Invalid file signature`));return}this.read(8,this._parseChunkBegin.bind(this))},i.prototype._parseChunkBegin=function(e){let t=e.readUInt32BE(0),i=e.readUInt32BE(4),a=``;for(let t=4;t<8;t++)a+=String.fromCharCode(e[t]);let o=!!(e[4]&32);if(!this._hasIHDR&&i!==n.TYPE_IHDR){this.error(Error(`Expected IHDR on beggining`));return}if(this._crc=new r,this._crc.write(Buffer.from(a)),this._chunks[i])return this._chunks[i](t);if(!o){this.error(Error(`Unsupported critical chunk type `+a));return}this.read(t+4,this._skipChunk.bind(this))},i.prototype._skipChunk=function(){this.read(8,this._parseChunkBegin.bind(this))},i.prototype._handleChunkEnd=function(){this.read(4,this._parseChunkEnd.bind(this))},i.prototype._parseChunkEnd=function(e){let t=e.readInt32BE(0),n=this._crc.crc32();if(this._options.checkCRC&&n!==t){this.error(Error(`Crc error - `+t+` - `+n));return}this._hasIEND||this.read(8,this._parseChunkBegin.bind(this))},i.prototype._handleIHDR=function(e){this.read(e,this._parseIHDR.bind(this))},i.prototype._parseIHDR=function(e){this._crc.write(e);let t=e.readUInt32BE(0),r=e.readUInt32BE(4),i=e[8],a=e[9],o=e[10],s=e[11],c=e[12];if(i!==8&&i!==4&&i!==2&&i!==1&&i!==16){this.error(Error(`Unsupported bit depth `+i));return}if(!(a in n.COLORTYPE_TO_BPP_MAP)){this.error(Error(`Unsupported color type`));return}if(o!==0){this.error(Error(`Unsupported compression method`));return}if(s!==0){this.error(Error(`Unsupported filter method`));return}if(c!==0&&c!==1){this.error(Error(`Unsupported interlace method`));return}this._colorType=a;let l=n.COLORTYPE_TO_BPP_MAP[this._colorType];this._hasIHDR=!0,this.metadata({width:t,height:r,depth:i,interlace:!!c,palette:!!(a&n.COLORTYPE_PALETTE),color:!!(a&n.COLORTYPE_COLOR),alpha:!!(a&n.COLORTYPE_ALPHA),bpp:l,colorType:a}),this._handleChunkEnd()},i.prototype._handlePLTE=function(e){this.read(e,this._parsePLTE.bind(this))},i.prototype._parsePLTE=function(e){this._crc.write(e);let t=Math.floor(e.length/3);for(let n=0;n<t;n++)this._palette.push([e[n*3],e[n*3+1],e[n*3+2],255]);this.palette(this._palette),this._handleChunkEnd()},i.prototype._handleTRNS=function(e){this.simpleTransparency(),this.read(e,this._parseTRNS.bind(this))},i.prototype._parseTRNS=function(e){if(this._crc.write(e),this._colorType===n.COLORTYPE_PALETTE_COLOR){if(this._palette.length===0){this.error(Error(`Transparency chunk must be after palette`));return}if(e.length>this._palette.length){this.error(Error(`More transparent colors than palette size`));return}for(let t=0;t<e.length;t++)this._palette[t][3]=e[t];this.palette(this._palette)}this._colorType===n.COLORTYPE_GRAYSCALE&&this.transColor([e.readUInt16BE(0)]),this._colorType===n.COLORTYPE_COLOR&&this.transColor([e.readUInt16BE(0),e.readUInt16BE(2),e.readUInt16BE(4)]),this._handleChunkEnd()},i.prototype._handleGAMA=function(e){this.read(e,this._parseGAMA.bind(this))},i.prototype._parseGAMA=function(e){this._crc.write(e),this.gamma(e.readUInt32BE(0)/n.GAMMA_DIVISION),this._handleChunkEnd()},i.prototype._handleIDAT=function(e){this._emittedHeadersFinished||(this._emittedHeadersFinished=!0,this.headersFinished()),this.read(-e,this._parseIDAT.bind(this,e))},i.prototype._parseIDAT=function(e,t){if(this._crc.write(t),this._colorType===n.COLORTYPE_PALETTE_COLOR&&this._palette.length===0)throw Error(`Expected palette not found`);this.inflateData(t);let r=e-t.length;r>0?this._handleIDAT(r):this._handleChunkEnd()},i.prototype._handleIEND=function(e){this.read(e,this._parseIEND.bind(this))},i.prototype._parseIEND=function(e){this._crc.write(e),this._hasIEND=!0,this._handleChunkEnd(),this.finished&&this.finished()}})),d=t((e=>{let t=i(),n=[function(){},function(e,t,n,r){if(r===t.length)throw Error(`Ran out of data`);let i=t[r];e[n]=i,e[n+1]=i,e[n+2]=i,e[n+3]=255},function(e,t,n,r){if(r+1>=t.length)throw Error(`Ran out of data`);let i=t[r];e[n]=i,e[n+1]=i,e[n+2]=i,e[n+3]=t[r+1]},function(e,t,n,r){if(r+2>=t.length)throw Error(`Ran out of data`);e[n]=t[r],e[n+1]=t[r+1],e[n+2]=t[r+2],e[n+3]=255},function(e,t,n,r){if(r+3>=t.length)throw Error(`Ran out of data`);e[n]=t[r],e[n+1]=t[r+1],e[n+2]=t[r+2],e[n+3]=t[r+3]}],r=[function(){},function(e,t,n,r){let i=t[0];e[n]=i,e[n+1]=i,e[n+2]=i,e[n+3]=r},function(e,t,n){let r=t[0];e[n]=r,e[n+1]=r,e[n+2]=r,e[n+3]=t[1]},function(e,t,n,r){e[n]=t[0],e[n+1]=t[1],e[n+2]=t[2],e[n+3]=r},function(e,t,n){e[n]=t[0],e[n+1]=t[1],e[n+2]=t[2],e[n+3]=t[3]}];function a(e,t){let n=[],r=0;function i(){if(r===e.length)throw Error(`Ran out of data`);let i=e[r];r++;let a,o,s,c,l,u,d,f;switch(t){default:throw Error(`unrecognised depth`);case 16:d=e[r],r++,n.push((i<<8)+d);break;case 4:d=i&15,f=i>>4,n.push(f,d);break;case 2:l=i&3,u=i>>2&3,d=i>>4&3,f=i>>6&3,n.push(f,d,u,l);break;case 1:a=i&1,o=i>>1&1,s=i>>2&1,c=i>>3&1,l=i>>4&1,u=i>>5&1,d=i>>6&1,f=i>>7&1,n.push(f,d,u,l,c,s,o,a)}}return{get:function(e){for(;n.length<e;)i();let t=n.slice(0,e);return n=n.slice(e),t},resetAfterLine:function(){n.length=0},end:function(){if(r!==e.length)throw Error(`extra data found`)}}}function o(e,t,r,i,a,o){let s=e.width,c=e.height,l=e.index;for(let e=0;e<c;e++)for(let c=0;c<s;c++){let s=r(c,e,l);n[i](t,a,s,o),o+=i}return o}function s(e,t,n,i,a,o){let s=e.width,c=e.height,l=e.index;for(let e=0;e<c;e++){for(let c=0;c<s;c++){let s=a.get(i),u=n(c,e,l);r[i](t,s,u,o)}a.resetAfterLine()}}e.dataToBitMap=function(e,n){let r=n.width,i=n.height,c=n.depth,l=n.bpp,u=n.interlace,d;c!==8&&(d=a(e,c));let f;f=c<=8?Buffer.alloc(r*i*4):new Uint16Array(r*i*4);let p=2**c-1,m=0,h,g;if(u)h=t.getImagePasses(r,i),g=t.getInterlaceIterator(r,i);else{let e=0;g=function(){let t=e;return e+=4,t},h=[{width:r,height:i}]}for(let t=0;t<h.length;t++)c===8?m=o(h[t],f,g,l,e,m):s(h[t],f,g,l,d,p);if(c===8){if(m!==e.length)throw Error(`extra data found`)}else d.end();return f}})),f=t(((e,t)=>{function n(e,t,n,r,i){let a=0;for(let o=0;o<r;o++)for(let r=0;r<n;r++){let n=i[e[a]];if(!n)throw Error(`index `+e[a]+` not in palette`);for(let e=0;e<4;e++)t[a+e]=n[e];a+=4}}function r(e,t,n,r,i){let a=0;for(let o=0;o<r;o++)for(let r=0;r<n;r++){let n=!1;if(i.length===1?i[0]===e[a]&&(n=!0):i[0]===e[a]&&i[1]===e[a+1]&&i[2]===e[a+2]&&(n=!0),n)for(let e=0;e<4;e++)t[a+e]=0;a+=4}}function i(e,t,n,r,i){let a=2**i-1,o=0;for(let i=0;i<r;i++)for(let r=0;r<n;r++){for(let n=0;n<4;n++)t[o+n]=Math.floor(e[o+n]*255/a+.5);o+=4}}t.exports=function(e,t,a=!1){let o=t.depth,s=t.width,c=t.height,l=t.colorType,u=t.transColor,d=t.palette,f=e;return l===3?n(e,f,s,c,d):(u&&r(e,f,s,c,u),o!==8&&!a&&(o===16&&(f=Buffer.alloc(s*c*4)),i(e,f,s,c,o))),f}})),p=t(((t,n)=>{let i=e(`util`),a=e(`zlib`),o=r(),c=s(),l=u(),p=d(),m=f(),h=n.exports=function(e){o.call(this),this._parser=new l(e,{read:this.read.bind(this),error:this._handleError.bind(this),metadata:this._handleMetaData.bind(this),gamma:this.emit.bind(this,`gamma`),palette:this._handlePalette.bind(this),transColor:this._handleTransColor.bind(this),finished:this._finished.bind(this),inflateData:this._inflateData.bind(this),simpleTransparency:this._simpleTransparency.bind(this),headersFinished:this._headersFinished.bind(this)}),this._options=e,this.writable=!0,this._parser.start()};i.inherits(h,o),h.prototype._handleError=function(e){this.emit(`error`,e),this.writable=!1,this.destroy(),this._inflate&&this._inflate.destroy&&this._inflate.destroy(),this._filter&&(this._filter.destroy(),this._filter.on(`error`,function(){})),this.errord=!0},h.prototype._inflateData=function(e){if(!this._inflate){if(this._bitmapInfo.interlace)this._inflate=a.createInflate(),this._inflate.on(`error`,this.emit.bind(this,`error`)),this._filter.on(`complete`,this._complete.bind(this)),this._inflate.pipe(this._filter);else{let e=((this._bitmapInfo.width*this._bitmapInfo.bpp*this._bitmapInfo.depth+7>>3)+1)*this._bitmapInfo.height,t=Math.max(e,a.Z_MIN_CHUNK);this._inflate=a.createInflate({chunkSize:t});let n=e,r=this.emit.bind(this,`error`);this._inflate.on(`error`,function(e){n&&r(e)}),this._filter.on(`complete`,this._complete.bind(this));let i=this._filter.write.bind(this._filter);this._inflate.on(`data`,function(e){n&&(e.length>n&&(e=e.slice(0,n)),n-=e.length,i(e))}),this._inflate.on(`end`,this._filter.end.bind(this._filter))}}this._inflate.write(e)},h.prototype._handleMetaData=function(e){this._metaData=e,this._bitmapInfo=Object.create(e),this._filter=new c(this._bitmapInfo)},h.prototype._handleTransColor=function(e){this._bitmapInfo.transColor=e},h.prototype._handlePalette=function(e){this._bitmapInfo.palette=e},h.prototype._simpleTransparency=function(){this._metaData.alpha=!0},h.prototype._headersFinished=function(){this.emit(`metadata`,this._metaData)},h.prototype._finished=function(){this.errord||(this._inflate?this._inflate.end():this.emit(`error`,`No Inflate block`))},h.prototype._complete=function(e){if(this.errord)return;let t;try{let n=p.dataToBitMap(e,this._bitmapInfo);t=m(n,this._bitmapInfo,this._options.skipRescale),n=null}catch(e){this._handleError(e);return}this.emit(`parsed`,t)}})),m=t(((e,t)=>{let n=c();t.exports=function(e,t,r,i){let a=[n.COLORTYPE_COLOR_ALPHA,n.COLORTYPE_ALPHA].indexOf(i.colorType)!==-1;if(i.colorType===i.inputColorType){let t=(function(){let e=new ArrayBuffer(2);return new DataView(e).setInt16(0,256,!0),new Int16Array(e)[0]!==256})();if(i.bitDepth===8||i.bitDepth===16&&t)return e}let o=i.bitDepth===16?new Uint16Array(e.buffer):e,s=255,c=n.COLORTYPE_TO_BPP_MAP[i.inputColorType];c===4&&!i.inputHasAlpha&&(c=3);let l=n.COLORTYPE_TO_BPP_MAP[i.colorType];i.bitDepth===16&&(s=65535,l*=2);let u=Buffer.alloc(t*r*l),d=0,f=0,p=i.bgColor||{};p.red===void 0&&(p.red=s),p.green===void 0&&(p.green=s),p.blue===void 0&&(p.blue=s);function m(){let e,t,r,c=s;switch(i.inputColorType){case n.COLORTYPE_COLOR_ALPHA:c=o[d+3],e=o[d],t=o[d+1],r=o[d+2];break;case n.COLORTYPE_COLOR:e=o[d],t=o[d+1],r=o[d+2];break;case n.COLORTYPE_ALPHA:c=o[d+1],e=o[d],t=e,r=e;break;case n.COLORTYPE_GRAYSCALE:e=o[d],t=e,r=e;break;default:throw Error(`input color type:`+i.inputColorType+` is not supported at present`)}return i.inputHasAlpha&&(a||(c/=s,e=Math.min(Math.max(Math.round((1-c)*p.red+c*e),0),s),t=Math.min(Math.max(Math.round((1-c)*p.green+c*t),0),s),r=Math.min(Math.max(Math.round((1-c)*p.blue+c*r),0),s))),{red:e,green:t,blue:r,alpha:c}}for(let e=0;e<r;e++)for(let e=0;e<t;e++){let e=m(o,d);switch(i.colorType){case n.COLORTYPE_COLOR_ALPHA:case n.COLORTYPE_COLOR:i.bitDepth===8?(u[f]=e.red,u[f+1]=e.green,u[f+2]=e.blue,a&&(u[f+3]=e.alpha)):(u.writeUInt16BE(e.red,f),u.writeUInt16BE(e.green,f+2),u.writeUInt16BE(e.blue,f+4),a&&u.writeUInt16BE(e.alpha,f+6));break;case n.COLORTYPE_ALPHA:case n.COLORTYPE_GRAYSCALE:{let t=(e.red+e.green+e.blue)/3;i.bitDepth===8?(u[f]=t,a&&(u[f+1]=e.alpha)):(u.writeUInt16BE(t,f),a&&u.writeUInt16BE(e.alpha,f+2));break}default:throw Error(`unrecognised color Type `+i.colorType)}d+=c,f+=l}return u}})),h=t(((e,t)=>{let n=a();function r(e,t,n,r,i){for(let a=0;a<n;a++)r[i+a]=e[t+a]}function i(e,t,n){let r=0,i=t+n;for(let n=t;n<i;n++)r+=Math.abs(e[n]);return r}function o(e,t,n,r,i,a){for(let o=0;o<n;o++){let n=o>=a?e[t+o-a]:0,s=e[t+o]-n;r[i+o]=s}}function s(e,t,n,r){let i=0;for(let a=0;a<n;a++){let n=a>=r?e[t+a-r]:0,o=e[t+a]-n;i+=Math.abs(o)}return i}function c(e,t,n,r,i){for(let a=0;a<n;a++){let o=t>0?e[t+a-n]:0,s=e[t+a]-o;r[i+a]=s}}function l(e,t,n){let r=0,i=t+n;for(let a=t;a<i;a++){let i=t>0?e[a-n]:0,o=e[a]-i;r+=Math.abs(o)}return r}function u(e,t,n,r,i,a){for(let o=0;o<n;o++){let s=o>=a?e[t+o-a]:0,c=t>0?e[t+o-n]:0,l=e[t+o]-(s+c>>1);r[i+o]=l}}function d(e,t,n,r){let i=0;for(let a=0;a<n;a++){let o=a>=r?e[t+a-r]:0,s=t>0?e[t+a-n]:0,c=e[t+a]-(o+s>>1);i+=Math.abs(c)}return i}function f(e,t,r,i,a,o){for(let s=0;s<r;s++){let c=s>=o?e[t+s-o]:0,l=t>0?e[t+s-r]:0,u=t>0&&s>=o?e[t+s-(r+o)]:0,d=e[t+s]-n(c,l,u);i[a+s]=d}}function p(e,t,r,i){let a=0;for(let o=0;o<r;o++){let s=o>=i?e[t+o-i]:0,c=t>0?e[t+o-r]:0,l=t>0&&o>=i?e[t+o-(r+i)]:0,u=e[t+o]-n(s,c,l);a+=Math.abs(u)}return a}let m={0:r,1:o,2:c,3:u,4:f},h={0:i,1:s,2:l,3:d,4:p};t.exports=function(e,t,n,r,i){let a;if(!(`filterType`in r)||r.filterType===-1)a=[0,1,2,3,4];else if(typeof r.filterType==`number`)a=[r.filterType];else throw Error(`unrecognised filter types`);r.bitDepth===16&&(i*=2);let o=t*i,s=0,c=0,l=Buffer.alloc((o+1)*n),u=a[0];for(let t=0;t<n;t++){if(a.length>1){let t=1/0;for(let n=0;n<a.length;n++){let r=h[a[n]](e,c,o,i);r<t&&(u=a[n],t=r)}}l[s]=u,s++,m[u](e,c,o,l,s,i),s+=o,c+=o}return l}})),g=t(((t,n)=>{let r=c(),i=l(),a=m(),o=h(),s=e(`zlib`),u=n.exports=function(e){if(this._options=e,e.deflateChunkSize=e.deflateChunkSize||32768,e.deflateLevel=e.deflateLevel==null?9:e.deflateLevel,e.deflateStrategy=e.deflateStrategy==null?3:e.deflateStrategy,e.inputHasAlpha=e.inputHasAlpha==null||e.inputHasAlpha,e.deflateFactory=e.deflateFactory||s.createDeflate,e.bitDepth=e.bitDepth||8,e.colorType=typeof e.colorType==`number`?e.colorType:r.COLORTYPE_COLOR_ALPHA,e.inputColorType=typeof e.inputColorType==`number`?e.inputColorType:r.COLORTYPE_COLOR_ALPHA,[r.COLORTYPE_GRAYSCALE,r.COLORTYPE_COLOR,r.COLORTYPE_COLOR_ALPHA,r.COLORTYPE_ALPHA].indexOf(e.colorType)===-1)throw Error(`option color type:`+e.colorType+` is not supported at present`);if([r.COLORTYPE_GRAYSCALE,r.COLORTYPE_COLOR,r.COLORTYPE_COLOR_ALPHA,r.COLORTYPE_ALPHA].indexOf(e.inputColorType)===-1)throw Error(`option input color type:`+e.inputColorType+` is not supported at present`);if(e.bitDepth!==8&&e.bitDepth!==16)throw Error(`option bit depth:`+e.bitDepth+` is not supported at present`)};u.prototype.getDeflateOptions=function(){return{chunkSize:this._options.deflateChunkSize,level:this._options.deflateLevel,strategy:this._options.deflateStrategy}},u.prototype.createDeflate=function(){return this._options.deflateFactory(this.getDeflateOptions())},u.prototype.filterData=function(e,t,n){let i=a(e,t,n,this._options),s=r.COLORTYPE_TO_BPP_MAP[this._options.colorType];return o(i,t,n,this._options,s)},u.prototype._packChunk=function(e,t){let n=t?t.length:0,r=Buffer.alloc(n+12);return r.writeUInt32BE(n,0),r.writeUInt32BE(e,4),t&&t.copy(r,8),r.writeInt32BE(i.crc32(r.slice(4,r.length-4)),r.length-4),r},u.prototype.packGAMA=function(e){let t=Buffer.alloc(4);return t.writeUInt32BE(Math.floor(e*r.GAMMA_DIVISION),0),this._packChunk(r.TYPE_gAMA,t)},u.prototype.packIHDR=function(e,t){let n=Buffer.alloc(13);return n.writeUInt32BE(e,0),n.writeUInt32BE(t,4),n[8]=this._options.bitDepth,n[9]=this._options.colorType,n[10]=0,n[11]=0,n[12]=0,this._packChunk(r.TYPE_IHDR,n)},u.prototype.packIDAT=function(e){return this._packChunk(r.TYPE_IDAT,e)},u.prototype.packIEND=function(){return this._packChunk(r.TYPE_IEND,null)}})),_=t(((t,n)=>{let r=e(`util`),i=e(`stream`),a=c(),o=g(),s=n.exports=function(e){i.call(this);let t=e||{};this._packer=new o(t),this._deflate=this._packer.createDeflate(),this.readable=!0};r.inherits(s,i),s.prototype.pack=function(e,t,n,r){this.emit(`data`,Buffer.from(a.PNG_SIGNATURE)),this.emit(`data`,this._packer.packIHDR(t,n)),r&&this.emit(`data`,this._packer.packGAMA(r));let i=this._packer.filterData(e,t,n);this._deflate.on(`error`,this.emit.bind(this,`error`)),this._deflate.on(`data`,function(e){this.emit(`data`,this._packer.packIDAT(e))}.bind(this)),this._deflate.on(`end`,function(){this.emit(`data`,this._packer.packIEND()),this.emit(`end`)}.bind(this)),this._deflate.end(i)}})),v=t(((t,n)=>{let r=e(`assert`).ok,i=e(`zlib`),a=e(`util`),o=e(`buffer`).kMaxLength;function s(e){if(!(this instanceof s))return new s(e);e&&e.chunkSize<i.Z_MIN_CHUNK&&(e.chunkSize=i.Z_MIN_CHUNK),i.Inflate.call(this,e),this._offset=this._offset===void 0?this._outOffset:this._offset,this._buffer=this._buffer||this._outBuffer,e&&e.maxLength!=null&&(this._maxLength=e.maxLength)}function c(e){return new s(e)}function l(e,t){t&&process.nextTick(t),e._handle&&=(e._handle.close(),null)}s.prototype._processChunk=function(e,t,n){if(typeof n==`function`)return i.Inflate._processChunk.call(this,e,t,n);let a=this,s=e&&e.length,c=this._chunkSize-this._offset,u=this._maxLength,d=0,f=[],p=0,m;this.on(`error`,function(e){m=e});function h(e,t){if(a._hadError)return;let n=c-t;if(r(n>=0,`have should not go down`),n>0){let e=a._buffer.slice(a._offset,a._offset+n);if(a._offset+=n,e.length>u&&(e=e.slice(0,u)),f.push(e),p+=e.length,u-=e.length,u===0)return!1}return(t===0||a._offset>=a._chunkSize)&&(c=a._chunkSize,a._offset=0,a._buffer=Buffer.allocUnsafe(a._chunkSize)),t===0&&(d+=s-e,s=e,!0)}r(this._handle,`zlib binding closed`);let g;do g=this._handle.writeSync(t,e,d,s,this._buffer,this._offset,c),g||=this._writeState;while(!this._hadError&&h(g[0],g[1]));if(this._hadError)throw m;if(p>=o)throw l(this),RangeError(`Cannot create final Buffer. It would be larger than 0x`+o.toString(16)+` bytes`);let _=Buffer.concat(f,p);return l(this),_},a.inherits(s,i.Inflate);function u(e,t){if(typeof t==`string`&&(t=Buffer.from(t)),!(t instanceof Buffer))throw TypeError(`Not a string or buffer`);let n=e._finishFlushFlag;return n??=i.Z_FINISH,e._processChunk(t,n)}function d(e,t){return u(new s(t),e)}n.exports=t=d,t.Inflate=s,t.createInflate=c,t.inflateSync=d})),y=t(((e,t)=>{let n=t.exports=function(e){this._buffer=e,this._reads=[]};n.prototype.read=function(e,t){this._reads.push({length:Math.abs(e),allowLess:e<0,func:t})},n.prototype.process=function(){for(;this._reads.length>0&&this._buffer.length;){let e=this._reads[0];if(this._buffer.length&&(this._buffer.length>=e.length||e.allowLess)){this._reads.shift();let t=this._buffer;this._buffer=t.slice(e.length),e.func.call(this,t.slice(0,e.length))}else break}if(this._reads.length>0)throw Error(`There are some read requests waitng on finished stream`);if(this._buffer.length>0)throw Error(`unrecognised content at end of stream`)}})),b=t((e=>{let t=y(),n=o();e.process=function(e,r){let i=[],a=new t(e);return new n(r,{read:a.read.bind(a),write:function(e){i.push(e)},complete:function(){}}).start(),a.process(),Buffer.concat(i)}})),x=t(((t,n)=>{let r=!0,i=e(`zlib`),a=v();i.deflateSync||(r=!1);let o=y(),s=b(),c=u(),l=d(),p=f();n.exports=function(e,t){if(!r)throw Error(`To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0`);let n;function u(e){n=e}let d;function f(e){d=e}function m(e){d.transColor=e}function h(e){d.palette=e}function g(){d.alpha=!0}let _;function v(e){_=e}let y=[];function b(e){y.push(e)}let x=new o(e);if(new c(t,{read:x.read.bind(x),error:u,metadata:f,gamma:v,palette:h,transColor:m,inflateData:b,simpleTransparency:g}).start(),x.process(),n)throw n;let S=Buffer.concat(y);y.length=0;let C;if(d.interlace)C=i.inflateSync(S);else{let e=((d.width*d.bpp*d.depth+7>>3)+1)*d.height;C=a(S,{chunkSize:e,maxLength:e})}if(S=null,!C||!C.length)throw Error(`bad png - invalid inflate data response`);let w=s.process(C,d);S=null;let T=l.dataToBitMap(w,d);w=null;let E=p(T,d,t.skipRescale);return d.data=E,d.gamma=_||0,d}})),S=t(((t,n)=>{let r=!0,i=e(`zlib`);i.deflateSync||(r=!1);let a=c(),o=g();n.exports=function(e,t){if(!r)throw Error(`To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0`);let n=new o(t||{}),s=[];s.push(Buffer.from(a.PNG_SIGNATURE)),s.push(n.packIHDR(e.width,e.height)),e.gamma&&s.push(n.packGAMA(e.gamma));let c=n.filterData(e.data,e.width,e.height),l=i.deflateSync(c,n.getDeflateOptions());if(c=null,!l||!l.length)throw Error(`bad png - invalid compressed data response`);return s.push(n.packIDAT(l)),s.push(n.packIEND()),Buffer.concat(s)}})),C=t((e=>{let t=x(),n=S();e.read=function(e,n){return t(e,n||{})},e.write=function(e,t){return n(e,t)}})),w=t((t=>{let n=e(`util`),r=e(`stream`),i=p(),a=_(),o=C(),s=t.PNG=function(e){r.call(this),e||={},this.width=e.width|0,this.height=e.height|0,this.data=this.width>0&&this.height>0?Buffer.alloc(4*this.width*this.height):null,e.fill&&this.data&&this.data.fill(0),this.gamma=0,this.readable=this.writable=!0,this._parser=new i(e),this._parser.on(`error`,this.emit.bind(this,`error`)),this._parser.on(`close`,this._handleClose.bind(this)),this._parser.on(`metadata`,this._metadata.bind(this)),this._parser.on(`gamma`,this._gamma.bind(this)),this._parser.on(`parsed`,function(e){this.data=e,this.emit(`parsed`,e)}.bind(this)),this._packer=new a(e),this._packer.on(`data`,this.emit.bind(this,`data`)),this._packer.on(`end`,this.emit.bind(this,`end`)),this._parser.on(`close`,this._handleClose.bind(this)),this._packer.on(`error`,this.emit.bind(this,`error`))};n.inherits(s,r),s.sync=o,s.prototype.pack=function(){return!this.data||!this.data.length?(this.emit(`error`,`No data provided`),this):(process.nextTick(function(){this._packer.pack(this.data,this.width,this.height,this.gamma)}.bind(this)),this)},s.prototype.parse=function(e,t){if(t){let e,n;e=function(e){this.removeListener(`error`,n),this.data=e,t(null,this)}.bind(this),n=function(n){this.removeListener(`parsed`,e),t(n,null)}.bind(this),this.once(`parsed`,e),this.once(`error`,n)}return this.end(e),this},s.prototype.write=function(e){return this._parser.write(e),!0},s.prototype.end=function(e){this._parser.end(e)},s.prototype._metadata=function(e){this.width=e.width,this.height=e.height,this.emit(`metadata`,e)},s.prototype._gamma=function(e){this.gamma=e},s.prototype._handleClose=function(){!this._parser.writable&&!this._packer.readable&&this.emit(`close`)},s.bitblt=function(e,t,n,r,i,a,o,s){if(n|=0,r|=0,i|=0,a|=0,o|=0,s|=0,n>e.width||r>e.height||n+i>e.width||r+a>e.height)throw Error(`bitblt reading outside image`);if(o>t.width||s>t.height||o+i>t.width||s+a>t.height)throw Error(`bitblt writing outside image`);for(let c=0;c<a;c++)e.data.copy(t.data,(s+c)*t.width+o<<2,(r+c)*e.width+n<<2,(r+c)*e.width+n+i<<2)},s.prototype.bitblt=function(e,t,n,r,i,a,o){return s.bitblt(this,e,t,n,r,i,a,o),this},s.adjustGamma=function(e){if(e.gamma){for(let t=0;t<e.height;t++)for(let n=0;n<e.width;n++){let r=e.width*t+n<<2;for(let t=0;t<3;t++){let n=e.data[r+t]/255;n**=1/2.2/e.gamma,e.data[r+t]=Math.round(n*255)}}e.gamma=0}},s.prototype.adjustGamma=function(){s.adjustGamma(this)}}))();const T=Buffer.from([137,80,78,71,13,10,26,10]);function E(e){return e.subarray(0,T.length).equals(T)}function D(e,t){try{return w.PNG.sync.read(e)}catch(e){throw new n(`COMMAND_FAILED`,`Failed to decode ${t} as PNG`,{label:t,reason:e instanceof Error?e.message:String(e)})}}export{E as n,w as r,D as t};
|
|
1
|
+
import{i as e,t}from"./rolldown-runtime.js";import{_ as n}from"./sdk-contracts.js";var r=t(((t,n)=>{let r=e(`util`),i=e(`stream`),a=n.exports=function(){i.call(this),this._buffers=[],this._buffered=0,this._reads=[],this._paused=!1,this._encoding=`utf8`,this.writable=!0};r.inherits(a,i),a.prototype.read=function(e,t){this._reads.push({length:Math.abs(e),allowLess:e<0,func:t}),process.nextTick(function(){this._process(),this._paused&&this._reads&&this._reads.length>0&&(this._paused=!1,this.emit(`drain`))}.bind(this))},a.prototype.write=function(e,t){if(!this.writable)return this.emit(`error`,Error(`Stream not writable`)),!1;let n;return n=Buffer.isBuffer(e)?e:Buffer.from(e,t||this._encoding),this._buffers.push(n),this._buffered+=n.length,this._process(),this._reads&&this._reads.length===0&&(this._paused=!0),this.writable&&!this._paused},a.prototype.end=function(e,t){e&&this.write(e,t),this.writable=!1,this._buffers&&(this._buffers.length===0?this._end():(this._buffers.push(null),this._process()))},a.prototype.destroySoon=a.prototype.end,a.prototype._end=function(){this._reads.length>0&&this.emit(`error`,Error(`Unexpected end of input`)),this.destroy()},a.prototype.destroy=function(){this._buffers&&(this.writable=!1,this._reads=null,this._buffers=null,this.emit(`close`))},a.prototype._processReadAllowingLess=function(e){this._reads.shift();let t=this._buffers[0];t.length>e.length?(this._buffered-=e.length,this._buffers[0]=t.slice(e.length),e.func.call(this,t.slice(0,e.length))):(this._buffered-=t.length,this._buffers.shift(),e.func.call(this,t))},a.prototype._processRead=function(e){this._reads.shift();let t=0,n=0,r=Buffer.alloc(e.length);for(;t<e.length;){let i=this._buffers[n++],a=Math.min(i.length,e.length-t);i.copy(r,t,0,a),t+=a,a!==i.length&&(this._buffers[--n]=i.slice(a))}n>0&&this._buffers.splice(0,n),this._buffered-=e.length,e.func.call(this,r)},a.prototype._process=function(){try{for(;this._buffered>0&&this._reads&&this._reads.length>0;){let e=this._reads[0];if(e.allowLess)this._processReadAllowingLess(e);else if(this._buffered>=e.length)this._processRead(e);else break}this._buffers&&!this.writable&&this._end()}catch(e){this.emit(`error`,e)}}})),i=t((e=>{let t=[{x:[0],y:[0]},{x:[4],y:[0]},{x:[0,4],y:[4]},{x:[2,6],y:[0,4]},{x:[0,2,4,6],y:[2,6]},{x:[1,3,5,7],y:[0,2,4,6]},{x:[0,1,2,3,4,5,6,7],y:[1,3,5,7]}];e.getImagePasses=function(e,n){let r=[],i=e%8,a=n%8,o=(e-i)/8,s=(n-a)/8;for(let e=0;e<t.length;e++){let n=t[e],c=o*n.x.length,l=s*n.y.length;for(let e=0;e<n.x.length&&n.x[e]<i;e++)c++;for(let e=0;e<n.y.length&&n.y[e]<a;e++)l++;c>0&&l>0&&r.push({width:c,height:l,index:e})}return r},e.getInterlaceIterator=function(e){return function(n,r,i){let a=n%t[i].x.length,o=(n-a)/t[i].x.length*8+t[i].x[a],s=r%t[i].y.length,c=(r-s)/t[i].y.length*8+t[i].y[s];return o*4+c*e*4}}})),a=t(((e,t)=>{t.exports=function(e,t,n){let r=e+t-n,i=Math.abs(r-e),a=Math.abs(r-t),o=Math.abs(r-n);return i<=a&&i<=o?e:a<=o?t:n}})),o=t(((e,t)=>{let n=i(),r=a();function o(e,t,n){let r=e*t;return n!==8&&(r=Math.ceil(r/(8/n))),r}let s=t.exports=function(e,t){let r=e.width,i=e.height,a=e.interlace,s=e.bpp,c=e.depth;if(this.read=t.read,this.write=t.write,this.complete=t.complete,this._imageIndex=0,this._images=[],a){let e=n.getImagePasses(r,i);for(let t=0;t<e.length;t++)this._images.push({byteWidth:o(e[t].width,s,c),height:e[t].height,lineIndex:0})}else this._images.push({byteWidth:o(r,s,c),height:i,lineIndex:0});this._xComparison=c===8?s:c===16?s*2:1};s.prototype.start=function(){this.read(this._images[this._imageIndex].byteWidth+1,this._reverseFilterLine.bind(this))},s.prototype._unFilterType1=function(e,t,n){let r=this._xComparison,i=r-1;for(let a=0;a<n;a++){let n=e[1+a],o=a>i?t[a-r]:0;t[a]=n+o}},s.prototype._unFilterType2=function(e,t,n){let r=this._lastLine;for(let i=0;i<n;i++){let n=e[1+i],a=r?r[i]:0;t[i]=n+a}},s.prototype._unFilterType3=function(e,t,n){let r=this._xComparison,i=r-1,a=this._lastLine;for(let o=0;o<n;o++){let n=e[1+o],s=a?a[o]:0,c=o>i?t[o-r]:0,l=Math.floor((c+s)/2);t[o]=n+l}},s.prototype._unFilterType4=function(e,t,n){let i=this._xComparison,a=i-1,o=this._lastLine;for(let s=0;s<n;s++){let n=e[1+s],c=o?o[s]:0,l=s>a?t[s-i]:0,u=s>a&&o?o[s-i]:0,d=r(l,c,u);t[s]=n+d}},s.prototype._reverseFilterLine=function(e){let t=e[0],n,r=this._images[this._imageIndex],i=r.byteWidth;if(t===0)n=e.slice(1,i+1);else switch(n=Buffer.alloc(i),t){case 1:this._unFilterType1(e,n,i);break;case 2:this._unFilterType2(e,n,i);break;case 3:this._unFilterType3(e,n,i);break;case 4:this._unFilterType4(e,n,i);break;default:throw Error(`Unrecognised filter type - `+t)}this.write(n),r.lineIndex++,r.lineIndex>=r.height?(this._lastLine=null,this._imageIndex++,r=this._images[this._imageIndex]):this._lastLine=n,r?this.read(r.byteWidth+1,this._reverseFilterLine.bind(this)):(this._lastLine=null,this.complete())}})),s=t(((t,n)=>{let i=e(`util`),a=r(),s=o(),c=n.exports=function(e){a.call(this);let t=[],n=this;this._filter=new s(e,{read:this.read.bind(this),write:function(e){t.push(e)},complete:function(){n.emit(`complete`,Buffer.concat(t))}}),this._filter.start()};i.inherits(c,a)})),c=t(((e,t)=>{t.exports={PNG_SIGNATURE:[137,80,78,71,13,10,26,10],TYPE_IHDR:1229472850,TYPE_IEND:1229278788,TYPE_IDAT:1229209940,TYPE_PLTE:1347179589,TYPE_tRNS:1951551059,TYPE_gAMA:1732332865,COLORTYPE_GRAYSCALE:0,COLORTYPE_PALETTE:1,COLORTYPE_COLOR:2,COLORTYPE_ALPHA:4,COLORTYPE_PALETTE_COLOR:3,COLORTYPE_COLOR_ALPHA:6,COLORTYPE_TO_BPP_MAP:{0:1,2:3,3:1,4:2,6:4},GAMMA_DIVISION:1e5}})),l=t(((e,t)=>{let n=[];(function(){for(let e=0;e<256;e++){let t=e;for(let e=0;e<8;e++)t&1?t=3988292384^t>>>1:t>>>=1;n[e]=t}})();let r=t.exports=function(){this._crc=-1};r.prototype.write=function(e){for(let t=0;t<e.length;t++)this._crc=n[(this._crc^e[t])&255]^this._crc>>>8;return!0},r.prototype.crc32=function(){return this._crc^-1},r.crc32=function(e){let t=-1;for(let r=0;r<e.length;r++)t=n[(t^e[r])&255]^t>>>8;return t^-1}})),u=t(((e,t)=>{let n=c(),r=l(),i=t.exports=function(e,t){this._options=e,e.checkCRC=e.checkCRC!==!1,this._hasIHDR=!1,this._hasIEND=!1,this._emittedHeadersFinished=!1,this._palette=[],this._colorType=0,this._chunks={},this._chunks[n.TYPE_IHDR]=this._handleIHDR.bind(this),this._chunks[n.TYPE_IEND]=this._handleIEND.bind(this),this._chunks[n.TYPE_IDAT]=this._handleIDAT.bind(this),this._chunks[n.TYPE_PLTE]=this._handlePLTE.bind(this),this._chunks[n.TYPE_tRNS]=this._handleTRNS.bind(this),this._chunks[n.TYPE_gAMA]=this._handleGAMA.bind(this),this.read=t.read,this.error=t.error,this.metadata=t.metadata,this.gamma=t.gamma,this.transColor=t.transColor,this.palette=t.palette,this.parsed=t.parsed,this.inflateData=t.inflateData,this.finished=t.finished,this.simpleTransparency=t.simpleTransparency,this.headersFinished=t.headersFinished||function(){}};i.prototype.start=function(){this.read(n.PNG_SIGNATURE.length,this._parseSignature.bind(this))},i.prototype._parseSignature=function(e){let t=n.PNG_SIGNATURE;for(let n=0;n<t.length;n++)if(e[n]!==t[n]){this.error(Error(`Invalid file signature`));return}this.read(8,this._parseChunkBegin.bind(this))},i.prototype._parseChunkBegin=function(e){let t=e.readUInt32BE(0),i=e.readUInt32BE(4),a=``;for(let t=4;t<8;t++)a+=String.fromCharCode(e[t]);let o=!!(e[4]&32);if(!this._hasIHDR&&i!==n.TYPE_IHDR){this.error(Error(`Expected IHDR on beggining`));return}if(this._crc=new r,this._crc.write(Buffer.from(a)),this._chunks[i])return this._chunks[i](t);if(!o){this.error(Error(`Unsupported critical chunk type `+a));return}this.read(t+4,this._skipChunk.bind(this))},i.prototype._skipChunk=function(){this.read(8,this._parseChunkBegin.bind(this))},i.prototype._handleChunkEnd=function(){this.read(4,this._parseChunkEnd.bind(this))},i.prototype._parseChunkEnd=function(e){let t=e.readInt32BE(0),n=this._crc.crc32();if(this._options.checkCRC&&n!==t){this.error(Error(`Crc error - `+t+` - `+n));return}this._hasIEND||this.read(8,this._parseChunkBegin.bind(this))},i.prototype._handleIHDR=function(e){this.read(e,this._parseIHDR.bind(this))},i.prototype._parseIHDR=function(e){this._crc.write(e);let t=e.readUInt32BE(0),r=e.readUInt32BE(4),i=e[8],a=e[9],o=e[10],s=e[11],c=e[12];if(i!==8&&i!==4&&i!==2&&i!==1&&i!==16){this.error(Error(`Unsupported bit depth `+i));return}if(!(a in n.COLORTYPE_TO_BPP_MAP)){this.error(Error(`Unsupported color type`));return}if(o!==0){this.error(Error(`Unsupported compression method`));return}if(s!==0){this.error(Error(`Unsupported filter method`));return}if(c!==0&&c!==1){this.error(Error(`Unsupported interlace method`));return}this._colorType=a;let l=n.COLORTYPE_TO_BPP_MAP[this._colorType];this._hasIHDR=!0,this.metadata({width:t,height:r,depth:i,interlace:!!c,palette:!!(a&n.COLORTYPE_PALETTE),color:!!(a&n.COLORTYPE_COLOR),alpha:!!(a&n.COLORTYPE_ALPHA),bpp:l,colorType:a}),this._handleChunkEnd()},i.prototype._handlePLTE=function(e){this.read(e,this._parsePLTE.bind(this))},i.prototype._parsePLTE=function(e){this._crc.write(e);let t=Math.floor(e.length/3);for(let n=0;n<t;n++)this._palette.push([e[n*3],e[n*3+1],e[n*3+2],255]);this.palette(this._palette),this._handleChunkEnd()},i.prototype._handleTRNS=function(e){this.simpleTransparency(),this.read(e,this._parseTRNS.bind(this))},i.prototype._parseTRNS=function(e){if(this._crc.write(e),this._colorType===n.COLORTYPE_PALETTE_COLOR){if(this._palette.length===0){this.error(Error(`Transparency chunk must be after palette`));return}if(e.length>this._palette.length){this.error(Error(`More transparent colors than palette size`));return}for(let t=0;t<e.length;t++)this._palette[t][3]=e[t];this.palette(this._palette)}this._colorType===n.COLORTYPE_GRAYSCALE&&this.transColor([e.readUInt16BE(0)]),this._colorType===n.COLORTYPE_COLOR&&this.transColor([e.readUInt16BE(0),e.readUInt16BE(2),e.readUInt16BE(4)]),this._handleChunkEnd()},i.prototype._handleGAMA=function(e){this.read(e,this._parseGAMA.bind(this))},i.prototype._parseGAMA=function(e){this._crc.write(e),this.gamma(e.readUInt32BE(0)/n.GAMMA_DIVISION),this._handleChunkEnd()},i.prototype._handleIDAT=function(e){this._emittedHeadersFinished||(this._emittedHeadersFinished=!0,this.headersFinished()),this.read(-e,this._parseIDAT.bind(this,e))},i.prototype._parseIDAT=function(e,t){if(this._crc.write(t),this._colorType===n.COLORTYPE_PALETTE_COLOR&&this._palette.length===0)throw Error(`Expected palette not found`);this.inflateData(t);let r=e-t.length;r>0?this._handleIDAT(r):this._handleChunkEnd()},i.prototype._handleIEND=function(e){this.read(e,this._parseIEND.bind(this))},i.prototype._parseIEND=function(e){this._crc.write(e),this._hasIEND=!0,this._handleChunkEnd(),this.finished&&this.finished()}})),d=t((e=>{let t=i(),n=[function(){},function(e,t,n,r){if(r===t.length)throw Error(`Ran out of data`);let i=t[r];e[n]=i,e[n+1]=i,e[n+2]=i,e[n+3]=255},function(e,t,n,r){if(r+1>=t.length)throw Error(`Ran out of data`);let i=t[r];e[n]=i,e[n+1]=i,e[n+2]=i,e[n+3]=t[r+1]},function(e,t,n,r){if(r+2>=t.length)throw Error(`Ran out of data`);e[n]=t[r],e[n+1]=t[r+1],e[n+2]=t[r+2],e[n+3]=255},function(e,t,n,r){if(r+3>=t.length)throw Error(`Ran out of data`);e[n]=t[r],e[n+1]=t[r+1],e[n+2]=t[r+2],e[n+3]=t[r+3]}],r=[function(){},function(e,t,n,r){let i=t[0];e[n]=i,e[n+1]=i,e[n+2]=i,e[n+3]=r},function(e,t,n){let r=t[0];e[n]=r,e[n+1]=r,e[n+2]=r,e[n+3]=t[1]},function(e,t,n,r){e[n]=t[0],e[n+1]=t[1],e[n+2]=t[2],e[n+3]=r},function(e,t,n){e[n]=t[0],e[n+1]=t[1],e[n+2]=t[2],e[n+3]=t[3]}];function a(e,t){let n=[],r=0;function i(){if(r===e.length)throw Error(`Ran out of data`);let i=e[r];r++;let a,o,s,c,l,u,d,f;switch(t){default:throw Error(`unrecognised depth`);case 16:d=e[r],r++,n.push((i<<8)+d);break;case 4:d=i&15,f=i>>4,n.push(f,d);break;case 2:l=i&3,u=i>>2&3,d=i>>4&3,f=i>>6&3,n.push(f,d,u,l);break;case 1:a=i&1,o=i>>1&1,s=i>>2&1,c=i>>3&1,l=i>>4&1,u=i>>5&1,d=i>>6&1,f=i>>7&1,n.push(f,d,u,l,c,s,o,a)}}return{get:function(e){for(;n.length<e;)i();let t=n.slice(0,e);return n=n.slice(e),t},resetAfterLine:function(){n.length=0},end:function(){if(r!==e.length)throw Error(`extra data found`)}}}function o(e,t,r,i,a,o){let s=e.width,c=e.height,l=e.index;for(let e=0;e<c;e++)for(let c=0;c<s;c++){let s=r(c,e,l);n[i](t,a,s,o),o+=i}return o}function s(e,t,n,i,a,o){let s=e.width,c=e.height,l=e.index;for(let e=0;e<c;e++){for(let c=0;c<s;c++){let s=a.get(i),u=n(c,e,l);r[i](t,s,u,o)}a.resetAfterLine()}}e.dataToBitMap=function(e,n){let r=n.width,i=n.height,c=n.depth,l=n.bpp,u=n.interlace,d;c!==8&&(d=a(e,c));let f;f=c<=8?Buffer.alloc(r*i*4):new Uint16Array(r*i*4);let p=2**c-1,m=0,h,g;if(u)h=t.getImagePasses(r,i),g=t.getInterlaceIterator(r,i);else{let e=0;g=function(){let t=e;return e+=4,t},h=[{width:r,height:i}]}for(let t=0;t<h.length;t++)c===8?m=o(h[t],f,g,l,e,m):s(h[t],f,g,l,d,p);if(c===8){if(m!==e.length)throw Error(`extra data found`)}else d.end();return f}})),f=t(((e,t)=>{function n(e,t,n,r,i){let a=0;for(let o=0;o<r;o++)for(let r=0;r<n;r++){let n=i[e[a]];if(!n)throw Error(`index `+e[a]+` not in palette`);for(let e=0;e<4;e++)t[a+e]=n[e];a+=4}}function r(e,t,n,r,i){let a=0;for(let o=0;o<r;o++)for(let r=0;r<n;r++){let n=!1;if(i.length===1?i[0]===e[a]&&(n=!0):i[0]===e[a]&&i[1]===e[a+1]&&i[2]===e[a+2]&&(n=!0),n)for(let e=0;e<4;e++)t[a+e]=0;a+=4}}function i(e,t,n,r,i){let a=2**i-1,o=0;for(let i=0;i<r;i++)for(let r=0;r<n;r++){for(let n=0;n<4;n++)t[o+n]=Math.floor(e[o+n]*255/a+.5);o+=4}}t.exports=function(e,t,a=!1){let o=t.depth,s=t.width,c=t.height,l=t.colorType,u=t.transColor,d=t.palette,f=e;return l===3?n(e,f,s,c,d):(u&&r(e,f,s,c,u),o!==8&&!a&&(o===16&&(f=Buffer.alloc(s*c*4)),i(e,f,s,c,o))),f}})),p=t(((t,n)=>{let i=e(`util`),a=e(`zlib`),o=r(),c=s(),l=u(),p=d(),m=f(),h=n.exports=function(e){o.call(this),this._parser=new l(e,{read:this.read.bind(this),error:this._handleError.bind(this),metadata:this._handleMetaData.bind(this),gamma:this.emit.bind(this,`gamma`),palette:this._handlePalette.bind(this),transColor:this._handleTransColor.bind(this),finished:this._finished.bind(this),inflateData:this._inflateData.bind(this),simpleTransparency:this._simpleTransparency.bind(this),headersFinished:this._headersFinished.bind(this)}),this._options=e,this.writable=!0,this._parser.start()};i.inherits(h,o),h.prototype._handleError=function(e){this.emit(`error`,e),this.writable=!1,this.destroy(),this._inflate&&this._inflate.destroy&&this._inflate.destroy(),this._filter&&(this._filter.destroy(),this._filter.on(`error`,function(){})),this.errord=!0},h.prototype._inflateData=function(e){if(!this._inflate){if(this._bitmapInfo.interlace)this._inflate=a.createInflate(),this._inflate.on(`error`,this.emit.bind(this,`error`)),this._filter.on(`complete`,this._complete.bind(this)),this._inflate.pipe(this._filter);else{let e=((this._bitmapInfo.width*this._bitmapInfo.bpp*this._bitmapInfo.depth+7>>3)+1)*this._bitmapInfo.height,t=Math.max(e,a.Z_MIN_CHUNK);this._inflate=a.createInflate({chunkSize:t});let n=e,r=this.emit.bind(this,`error`);this._inflate.on(`error`,function(e){n&&r(e)}),this._filter.on(`complete`,this._complete.bind(this));let i=this._filter.write.bind(this._filter);this._inflate.on(`data`,function(e){n&&(e.length>n&&(e=e.slice(0,n)),n-=e.length,i(e))}),this._inflate.on(`end`,this._filter.end.bind(this._filter))}}this._inflate.write(e)},h.prototype._handleMetaData=function(e){this._metaData=e,this._bitmapInfo=Object.create(e),this._filter=new c(this._bitmapInfo)},h.prototype._handleTransColor=function(e){this._bitmapInfo.transColor=e},h.prototype._handlePalette=function(e){this._bitmapInfo.palette=e},h.prototype._simpleTransparency=function(){this._metaData.alpha=!0},h.prototype._headersFinished=function(){this.emit(`metadata`,this._metaData)},h.prototype._finished=function(){this.errord||(this._inflate?this._inflate.end():this.emit(`error`,`No Inflate block`))},h.prototype._complete=function(e){if(this.errord)return;let t;try{let n=p.dataToBitMap(e,this._bitmapInfo);t=m(n,this._bitmapInfo,this._options.skipRescale),n=null}catch(e){this._handleError(e);return}this.emit(`parsed`,t)}})),m=t(((e,t)=>{let n=c();t.exports=function(e,t,r,i){let a=[n.COLORTYPE_COLOR_ALPHA,n.COLORTYPE_ALPHA].indexOf(i.colorType)!==-1;if(i.colorType===i.inputColorType){let t=(function(){let e=new ArrayBuffer(2);return new DataView(e).setInt16(0,256,!0),new Int16Array(e)[0]!==256})();if(i.bitDepth===8||i.bitDepth===16&&t)return e}let o=i.bitDepth===16?new Uint16Array(e.buffer):e,s=255,c=n.COLORTYPE_TO_BPP_MAP[i.inputColorType];c===4&&!i.inputHasAlpha&&(c=3);let l=n.COLORTYPE_TO_BPP_MAP[i.colorType];i.bitDepth===16&&(s=65535,l*=2);let u=Buffer.alloc(t*r*l),d=0,f=0,p=i.bgColor||{};p.red===void 0&&(p.red=s),p.green===void 0&&(p.green=s),p.blue===void 0&&(p.blue=s);function m(){let e,t,r,c=s;switch(i.inputColorType){case n.COLORTYPE_COLOR_ALPHA:c=o[d+3],e=o[d],t=o[d+1],r=o[d+2];break;case n.COLORTYPE_COLOR:e=o[d],t=o[d+1],r=o[d+2];break;case n.COLORTYPE_ALPHA:c=o[d+1],e=o[d],t=e,r=e;break;case n.COLORTYPE_GRAYSCALE:e=o[d],t=e,r=e;break;default:throw Error(`input color type:`+i.inputColorType+` is not supported at present`)}return i.inputHasAlpha&&(a||(c/=s,e=Math.min(Math.max(Math.round((1-c)*p.red+c*e),0),s),t=Math.min(Math.max(Math.round((1-c)*p.green+c*t),0),s),r=Math.min(Math.max(Math.round((1-c)*p.blue+c*r),0),s))),{red:e,green:t,blue:r,alpha:c}}for(let e=0;e<r;e++)for(let e=0;e<t;e++){let e=m(o,d);switch(i.colorType){case n.COLORTYPE_COLOR_ALPHA:case n.COLORTYPE_COLOR:i.bitDepth===8?(u[f]=e.red,u[f+1]=e.green,u[f+2]=e.blue,a&&(u[f+3]=e.alpha)):(u.writeUInt16BE(e.red,f),u.writeUInt16BE(e.green,f+2),u.writeUInt16BE(e.blue,f+4),a&&u.writeUInt16BE(e.alpha,f+6));break;case n.COLORTYPE_ALPHA:case n.COLORTYPE_GRAYSCALE:{let t=(e.red+e.green+e.blue)/3;i.bitDepth===8?(u[f]=t,a&&(u[f+1]=e.alpha)):(u.writeUInt16BE(t,f),a&&u.writeUInt16BE(e.alpha,f+2));break}default:throw Error(`unrecognised color Type `+i.colorType)}d+=c,f+=l}return u}})),h=t(((e,t)=>{let n=a();function r(e,t,n,r,i){for(let a=0;a<n;a++)r[i+a]=e[t+a]}function i(e,t,n){let r=0,i=t+n;for(let n=t;n<i;n++)r+=Math.abs(e[n]);return r}function o(e,t,n,r,i,a){for(let o=0;o<n;o++){let n=o>=a?e[t+o-a]:0,s=e[t+o]-n;r[i+o]=s}}function s(e,t,n,r){let i=0;for(let a=0;a<n;a++){let n=a>=r?e[t+a-r]:0,o=e[t+a]-n;i+=Math.abs(o)}return i}function c(e,t,n,r,i){for(let a=0;a<n;a++){let o=t>0?e[t+a-n]:0,s=e[t+a]-o;r[i+a]=s}}function l(e,t,n){let r=0,i=t+n;for(let a=t;a<i;a++){let i=t>0?e[a-n]:0,o=e[a]-i;r+=Math.abs(o)}return r}function u(e,t,n,r,i,a){for(let o=0;o<n;o++){let s=o>=a?e[t+o-a]:0,c=t>0?e[t+o-n]:0,l=e[t+o]-(s+c>>1);r[i+o]=l}}function d(e,t,n,r){let i=0;for(let a=0;a<n;a++){let o=a>=r?e[t+a-r]:0,s=t>0?e[t+a-n]:0,c=e[t+a]-(o+s>>1);i+=Math.abs(c)}return i}function f(e,t,r,i,a,o){for(let s=0;s<r;s++){let c=s>=o?e[t+s-o]:0,l=t>0?e[t+s-r]:0,u=t>0&&s>=o?e[t+s-(r+o)]:0,d=e[t+s]-n(c,l,u);i[a+s]=d}}function p(e,t,r,i){let a=0;for(let o=0;o<r;o++){let s=o>=i?e[t+o-i]:0,c=t>0?e[t+o-r]:0,l=t>0&&o>=i?e[t+o-(r+i)]:0,u=e[t+o]-n(s,c,l);a+=Math.abs(u)}return a}let m={0:r,1:o,2:c,3:u,4:f},h={0:i,1:s,2:l,3:d,4:p};t.exports=function(e,t,n,r,i){let a;if(!(`filterType`in r)||r.filterType===-1)a=[0,1,2,3,4];else if(typeof r.filterType==`number`)a=[r.filterType];else throw Error(`unrecognised filter types`);r.bitDepth===16&&(i*=2);let o=t*i,s=0,c=0,l=Buffer.alloc((o+1)*n),u=a[0];for(let t=0;t<n;t++){if(a.length>1){let t=1/0;for(let n=0;n<a.length;n++){let r=h[a[n]](e,c,o,i);r<t&&(u=a[n],t=r)}}l[s]=u,s++,m[u](e,c,o,l,s,i),s+=o,c+=o}return l}})),g=t(((t,n)=>{let r=c(),i=l(),a=m(),o=h(),s=e(`zlib`),u=n.exports=function(e){if(this._options=e,e.deflateChunkSize=e.deflateChunkSize||32768,e.deflateLevel=e.deflateLevel==null?9:e.deflateLevel,e.deflateStrategy=e.deflateStrategy==null?3:e.deflateStrategy,e.inputHasAlpha=e.inputHasAlpha==null||e.inputHasAlpha,e.deflateFactory=e.deflateFactory||s.createDeflate,e.bitDepth=e.bitDepth||8,e.colorType=typeof e.colorType==`number`?e.colorType:r.COLORTYPE_COLOR_ALPHA,e.inputColorType=typeof e.inputColorType==`number`?e.inputColorType:r.COLORTYPE_COLOR_ALPHA,[r.COLORTYPE_GRAYSCALE,r.COLORTYPE_COLOR,r.COLORTYPE_COLOR_ALPHA,r.COLORTYPE_ALPHA].indexOf(e.colorType)===-1)throw Error(`option color type:`+e.colorType+` is not supported at present`);if([r.COLORTYPE_GRAYSCALE,r.COLORTYPE_COLOR,r.COLORTYPE_COLOR_ALPHA,r.COLORTYPE_ALPHA].indexOf(e.inputColorType)===-1)throw Error(`option input color type:`+e.inputColorType+` is not supported at present`);if(e.bitDepth!==8&&e.bitDepth!==16)throw Error(`option bit depth:`+e.bitDepth+` is not supported at present`)};u.prototype.getDeflateOptions=function(){return{chunkSize:this._options.deflateChunkSize,level:this._options.deflateLevel,strategy:this._options.deflateStrategy}},u.prototype.createDeflate=function(){return this._options.deflateFactory(this.getDeflateOptions())},u.prototype.filterData=function(e,t,n){let i=a(e,t,n,this._options),s=r.COLORTYPE_TO_BPP_MAP[this._options.colorType];return o(i,t,n,this._options,s)},u.prototype._packChunk=function(e,t){let n=t?t.length:0,r=Buffer.alloc(n+12);return r.writeUInt32BE(n,0),r.writeUInt32BE(e,4),t&&t.copy(r,8),r.writeInt32BE(i.crc32(r.slice(4,r.length-4)),r.length-4),r},u.prototype.packGAMA=function(e){let t=Buffer.alloc(4);return t.writeUInt32BE(Math.floor(e*r.GAMMA_DIVISION),0),this._packChunk(r.TYPE_gAMA,t)},u.prototype.packIHDR=function(e,t){let n=Buffer.alloc(13);return n.writeUInt32BE(e,0),n.writeUInt32BE(t,4),n[8]=this._options.bitDepth,n[9]=this._options.colorType,n[10]=0,n[11]=0,n[12]=0,this._packChunk(r.TYPE_IHDR,n)},u.prototype.packIDAT=function(e){return this._packChunk(r.TYPE_IDAT,e)},u.prototype.packIEND=function(){return this._packChunk(r.TYPE_IEND,null)}})),_=t(((t,n)=>{let r=e(`util`),i=e(`stream`),a=c(),o=g(),s=n.exports=function(e){i.call(this);let t=e||{};this._packer=new o(t),this._deflate=this._packer.createDeflate(),this.readable=!0};r.inherits(s,i),s.prototype.pack=function(e,t,n,r){this.emit(`data`,Buffer.from(a.PNG_SIGNATURE)),this.emit(`data`,this._packer.packIHDR(t,n)),r&&this.emit(`data`,this._packer.packGAMA(r));let i=this._packer.filterData(e,t,n);this._deflate.on(`error`,this.emit.bind(this,`error`)),this._deflate.on(`data`,function(e){this.emit(`data`,this._packer.packIDAT(e))}.bind(this)),this._deflate.on(`end`,function(){this.emit(`data`,this._packer.packIEND()),this.emit(`end`)}.bind(this)),this._deflate.end(i)}})),v=t(((t,n)=>{let r=e(`assert`).ok,i=e(`zlib`),a=e(`util`),o=e(`buffer`).kMaxLength;function s(e){if(!(this instanceof s))return new s(e);e&&e.chunkSize<i.Z_MIN_CHUNK&&(e.chunkSize=i.Z_MIN_CHUNK),i.Inflate.call(this,e),this._offset=this._offset===void 0?this._outOffset:this._offset,this._buffer=this._buffer||this._outBuffer,e&&e.maxLength!=null&&(this._maxLength=e.maxLength)}function c(e){return new s(e)}function l(e,t){t&&process.nextTick(t),e._handle&&=(e._handle.close(),null)}s.prototype._processChunk=function(e,t,n){if(typeof n==`function`)return i.Inflate._processChunk.call(this,e,t,n);let a=this,s=e&&e.length,c=this._chunkSize-this._offset,u=this._maxLength,d=0,f=[],p=0,m;this.on(`error`,function(e){m=e});function h(e,t){if(a._hadError)return;let n=c-t;if(r(n>=0,`have should not go down`),n>0){let e=a._buffer.slice(a._offset,a._offset+n);if(a._offset+=n,e.length>u&&(e=e.slice(0,u)),f.push(e),p+=e.length,u-=e.length,u===0)return!1}return(t===0||a._offset>=a._chunkSize)&&(c=a._chunkSize,a._offset=0,a._buffer=Buffer.allocUnsafe(a._chunkSize)),t===0&&(d+=s-e,s=e,!0)}r(this._handle,`zlib binding closed`);let g;do g=this._handle.writeSync(t,e,d,s,this._buffer,this._offset,c),g||=this._writeState;while(!this._hadError&&h(g[0],g[1]));if(this._hadError)throw m;if(p>=o)throw l(this),RangeError(`Cannot create final Buffer. It would be larger than 0x`+o.toString(16)+` bytes`);let _=Buffer.concat(f,p);return l(this),_},a.inherits(s,i.Inflate);function u(e,t){if(typeof t==`string`&&(t=Buffer.from(t)),!(t instanceof Buffer))throw TypeError(`Not a string or buffer`);let n=e._finishFlushFlag;return n??=i.Z_FINISH,e._processChunk(t,n)}function d(e,t){return u(new s(t),e)}n.exports=t=d,t.Inflate=s,t.createInflate=c,t.inflateSync=d})),y=t(((e,t)=>{let n=t.exports=function(e){this._buffer=e,this._reads=[]};n.prototype.read=function(e,t){this._reads.push({length:Math.abs(e),allowLess:e<0,func:t})},n.prototype.process=function(){for(;this._reads.length>0&&this._buffer.length;){let e=this._reads[0];if(this._buffer.length&&(this._buffer.length>=e.length||e.allowLess)){this._reads.shift();let t=this._buffer;this._buffer=t.slice(e.length),e.func.call(this,t.slice(0,e.length))}else break}if(this._reads.length>0)throw Error(`There are some read requests waitng on finished stream`);if(this._buffer.length>0)throw Error(`unrecognised content at end of stream`)}})),b=t((e=>{let t=y(),n=o();e.process=function(e,r){let i=[],a=new t(e);return new n(r,{read:a.read.bind(a),write:function(e){i.push(e)},complete:function(){}}).start(),a.process(),Buffer.concat(i)}})),x=t(((t,n)=>{let r=!0,i=e(`zlib`),a=v();i.deflateSync||(r=!1);let o=y(),s=b(),c=u(),l=d(),p=f();n.exports=function(e,t){if(!r)throw Error(`To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0`);let n;function u(e){n=e}let d;function f(e){d=e}function m(e){d.transColor=e}function h(e){d.palette=e}function g(){d.alpha=!0}let _;function v(e){_=e}let y=[];function b(e){y.push(e)}let x=new o(e);if(new c(t,{read:x.read.bind(x),error:u,metadata:f,gamma:v,palette:h,transColor:m,inflateData:b,simpleTransparency:g}).start(),x.process(),n)throw n;let S=Buffer.concat(y);y.length=0;let C;if(d.interlace)C=i.inflateSync(S);else{let e=((d.width*d.bpp*d.depth+7>>3)+1)*d.height;C=a(S,{chunkSize:e,maxLength:e})}if(S=null,!C||!C.length)throw Error(`bad png - invalid inflate data response`);let w=s.process(C,d);S=null;let T=l.dataToBitMap(w,d);w=null;let E=p(T,d,t.skipRescale);return d.data=E,d.gamma=_||0,d}})),S=t(((t,n)=>{let r=!0,i=e(`zlib`);i.deflateSync||(r=!1);let a=c(),o=g();n.exports=function(e,t){if(!r)throw Error(`To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0`);let n=new o(t||{}),s=[];s.push(Buffer.from(a.PNG_SIGNATURE)),s.push(n.packIHDR(e.width,e.height)),e.gamma&&s.push(n.packGAMA(e.gamma));let c=n.filterData(e.data,e.width,e.height),l=i.deflateSync(c,n.getDeflateOptions());if(c=null,!l||!l.length)throw Error(`bad png - invalid compressed data response`);return s.push(n.packIDAT(l)),s.push(n.packIEND()),Buffer.concat(s)}})),C=t((e=>{let t=x(),n=S();e.read=function(e,n){return t(e,n||{})},e.write=function(e,t){return n(e,t)}})),w=t((t=>{let n=e(`util`),r=e(`stream`),i=p(),a=_(),o=C(),s=t.PNG=function(e){r.call(this),e||={},this.width=e.width|0,this.height=e.height|0,this.data=this.width>0&&this.height>0?Buffer.alloc(4*this.width*this.height):null,e.fill&&this.data&&this.data.fill(0),this.gamma=0,this.readable=this.writable=!0,this._parser=new i(e),this._parser.on(`error`,this.emit.bind(this,`error`)),this._parser.on(`close`,this._handleClose.bind(this)),this._parser.on(`metadata`,this._metadata.bind(this)),this._parser.on(`gamma`,this._gamma.bind(this)),this._parser.on(`parsed`,function(e){this.data=e,this.emit(`parsed`,e)}.bind(this)),this._packer=new a(e),this._packer.on(`data`,this.emit.bind(this,`data`)),this._packer.on(`end`,this.emit.bind(this,`end`)),this._parser.on(`close`,this._handleClose.bind(this)),this._packer.on(`error`,this.emit.bind(this,`error`))};n.inherits(s,r),s.sync=o,s.prototype.pack=function(){return!this.data||!this.data.length?(this.emit(`error`,`No data provided`),this):(process.nextTick(function(){this._packer.pack(this.data,this.width,this.height,this.gamma)}.bind(this)),this)},s.prototype.parse=function(e,t){if(t){let e,n;e=function(e){this.removeListener(`error`,n),this.data=e,t(null,this)}.bind(this),n=function(n){this.removeListener(`parsed`,e),t(n,null)}.bind(this),this.once(`parsed`,e),this.once(`error`,n)}return this.end(e),this},s.prototype.write=function(e){return this._parser.write(e),!0},s.prototype.end=function(e){this._parser.end(e)},s.prototype._metadata=function(e){this.width=e.width,this.height=e.height,this.emit(`metadata`,e)},s.prototype._gamma=function(e){this.gamma=e},s.prototype._handleClose=function(){!this._parser.writable&&!this._packer.readable&&this.emit(`close`)},s.bitblt=function(e,t,n,r,i,a,o,s){if(n|=0,r|=0,i|=0,a|=0,o|=0,s|=0,n>e.width||r>e.height||n+i>e.width||r+a>e.height)throw Error(`bitblt reading outside image`);if(o>t.width||s>t.height||o+i>t.width||s+a>t.height)throw Error(`bitblt writing outside image`);for(let c=0;c<a;c++)e.data.copy(t.data,(s+c)*t.width+o<<2,(r+c)*e.width+n<<2,(r+c)*e.width+n+i<<2)},s.prototype.bitblt=function(e,t,n,r,i,a,o){return s.bitblt(this,e,t,n,r,i,a,o),this},s.adjustGamma=function(e){if(e.gamma){for(let t=0;t<e.height;t++)for(let n=0;n<e.width;n++){let r=e.width*t+n<<2;for(let t=0;t<3;t++){let n=e.data[r+t]/255;n**=1/2.2/e.gamma,e.data[r+t]=Math.round(n*255)}}e.gamma=0}},s.prototype.adjustGamma=function(){s.adjustGamma(this)}}))();const T=Buffer.from([137,80,78,71,13,10,26,10]);function E(e){return e.subarray(0,T.length).equals(T)}function D(e,t){try{return w.PNG.sync.read(e)}catch(e){throw new n(`COMMAND_FAILED`,`Failed to decode ${t} as PNG`,{label:t,reason:e instanceof Error?e.message:String(e)})}}export{E as n,w as r,D as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"./snapshot-capture-annotations.js";import"./capture.js";import{
|
|
1
|
+
import{a as e}from"./snapshot-capture-annotations.js";import"./capture.js";import{St as t,q as n}from"./sdk-io.js";import"./diagnostics.js";import"./retry.js";const r=2500,i=5e3,a=1500,o=[250,400,600];function s(e){return e===`press`||e===`click`||e===`back`||e===`open`}function c(e){return e.map(e=>[e.depth??0,e.type??``,e.label??``,e.value??``,e.identifier??``,e.enabled===!1?`disabled`:`enabled`,e.hittable===!0?`hittable`:`not-hittable`].join(`|`))}function l(e,t){return e<12?!1:t<=Math.floor(e*.2)}function u(e,t,n){return n.interactiveOnly&&e.snapshot.nodes.length===0&&e.rawNodeCount!==void 0&&e.rawNodeCount>=12?`empty-interactive`:n.mode===`ref-refresh`?null:l(t.baselineCount,e.snapshot.nodes.length)?d(e.snapshot)?null:`sharp-drop`:e.cacheInvalidated===!0?null:t.routeComparable&&s(t.action)&&f(t.baselineSignatures,e.snapshot.nodes)?`stuck-route`:null}function d(e){return e.nodes.some(e=>e.hittable===!0||!!e.label?.trim()||!!e.value?.trim()||!!e.identifier?.trim())}function f(e,t){if(!e||e.length===0)return!1;let n=Math.max(e.length,t.length);if(n<12)return!1;let r=c(t),i=Math.min(e.length,r.length),a=0;for(let t=0;t<i;t+=1)e[t]===r[t]&&(a+=1);let o=Math.max(0,r.length-e.length),s=Math.max(0,e.length-r.length),l=Math.max(3,Math.floor(n*.15));return a>=Math.floor(n*.9)&&o<=l&&s<=l}async function p(t){let r=t.window.markedAt+t.retry.retryBudgetMs,i=await t.capture(),a=t.classify(i),o=0;for(let e of t.retry.delaysMs){if(!a)break;let s=r-Date.now();if(s<=0)break;await n(Math.min(e,s)),i=await t.capture(),o+=1,a=t.classify(i)}a||t.onTrustworthyCapture?.();let s=o>0||a?{action:t.window.action,retryCount:o,staleAfterRetries:!!a,reason:a??void 0}:void 0;return{...i,annotations:{...i.annotations,...e({freshness:s})}}}const m={now:()=>Date.now(),sleep:e=>new Promise(t=>setTimeout(t,e))};async function h(e){let t=e.clock??m,n={params:e,clock:t,state:{startedMs:t.now(),budgetMs:e.schedule.budgetMs,observations:0,polls:[],previous:void 0,last:void 0}};if(e.initial!==void 0){if(g(n,`hard`)<=0)return x(n,{kind:`deadline`,last:void 0});n.state.observations+=1;let t=b(n,e.initial);if(t)return t}for(;;){let e=await v(n);if(e)return e;let t=await y(n);if(t)return t}}function g({state:e,clock:t,params:n},r){return r?(n.deadlineMs??1/0)-t.now():e.startedMs+e.budgetMs-t.now()}function _({params:e,state:t}){return t.observations<(e.schedule.minPolls??1)}async function v(e){let{state:t,clock:n,params:r}=e,i=()=>x(e,{kind:`deadline`,last:t.last});if(g(e,`hard`)<=0)return i();if(t.observations===0)return;let a=_(e);if(!a&&g(e)<=0)return x(e,{kind:`expired`,last:t.last});let{intervalMs:o}=r.schedule,s=a?o:Math.max(0,Math.min(o,g(e)));return s>=g(e,`hard`)?i():(await n.sleep(s),g(e,`hard`)>0?void 0:i())}async function y(e){let{params:t,clock:n,state:r}=e,i=n.now(),a=e=>{r.observations+=1,r.polls.push({startedMs:i-r.startedMs,durationMs:n.now()-i,outcome:e})},o;try{o=await t.capture()}catch(t){return a(`failed`),x(e,{kind:`failed`,last:r.last,error:t})}return a(`observed`),g(e,`hard`)<=0?x(e,{kind:`deadline`,last:r.last}):b(e,o)}function b(e,t){let{params:n,state:r}=e,i=n.verdict(t,r.previous,r.polls.length);if(r.previous=t,r.last=t,i.kind===`done`)return x(e,{kind:`done`,result:i.result,value:t});i.budgetMs!==void 0&&(r.budgetMs=Math.max(r.budgetMs,i.budgetMs))}function x(e,t){let{state:n,clock:r}=e;return{...t,polls:n.polls,waitedMs:r.now()-n.startedMs}}const S={intervalMs:200,budgetMs:1500,minPolls:2},C=S.budgetMs+2e3,w={intervalMs:S.intervalMs,budgetMs:1e4,minPolls:2};function T({kind:e,gesture:t}){let n=[t.action,...t.positionals].join(` `).trim();return e===`loading`?`The app was still loading after ${n} when this tree was read: it may show a launch or loading screen. Run snapshot -i again, or wait for expected content (wait text ...) before acting.`:e===`unsettled`?`The surface was still changing after ${n} when this tree was read, so it may not match where the surface comes to rest: an element missing from it is not proof of absence.`:`${n} produced no visible change: the tree still matches its pre-gesture state. Either the container is already at its edge, or it ignores synthesized scrolls — a raw drag moves such lists: swipe x1 y1 x2 y2 (start inside the list).`}function E(e,t){return{kind:e,gesture:{action:t.action,positionals:t.positionals}}}function D(e){let{baseline:t,quiet:n,elapsedMs:r,distrustCapMs:i}=e;return t?.provenance!==`pre-action`||t.signature.length===0||e.classifyBaselineEvidence(t,n)!==`unchanged`?{verdict:`trust`}:r<i?{verdict:`distrust`}:{verdict:`accept-stale`,preActionBaseline:t}}async function O(e){let{pending:n,hooks:r,clock:i}=e,a=()=>i?.now()??Date.now(),o=a(),s=0,c=n.baseline,l=!1,u=n.readiness===`first-screen`,d,f=e=>(d?.value===e||(d={value:e,...r.readSurface(e)}),d),p=await h({...e.initial===void 0?{}:{initial:e.initial},capture:()=>r.capture(),schedule:u?w:S,...i?{clock:i}:{},verdict:(e,i)=>{s+=1;let d=f(e);if(i===void 0)return{kind:`continue`};let p=f(i);if(l=r.signaturesStable(p.signature,d.signature),!l)return{kind:`continue`};let m=a()-o;if(u&&!r.showsFirstScreen(e))return{kind:`continue`};if(c&&c.comparisonKey!==d.comparisonKey)return t({level:`debug`,phase:`post_gesture_snapshot_baseline_rebased`,data:{action:n.action,from:c.comparisonKey,to:d.comparisonKey,attempts:s}}),c={provenance:`post-action`,signature:d.signature,comparisonKey:d.comparisonKey,keyboard:d.keyboard},{kind:`continue`};let h=D({baseline:c,quiet:d,elapsedMs:m,distrustCapMs:C,classifyBaselineEvidence:r.classifyBaselineEvidence});return h.verdict===`distrust`?{kind:`continue`,budgetMs:C}:(k(h.verdict,n.action,s,m),{kind:`done`,result:A(h,n,d,r)})}});if(p.kind===`done`)return p.result;if(p.kind===`failed`)throw p.error;t({level:`warn`,phase:`post_gesture_snapshot_stabilization_timeout`,data:{action:n.action,attempts:s,durationMs:p.waitedMs,lastPairAgreed:l}});let m=p.last;return u&&!r.showsFirstScreen(m)?{value:m,postGestureOutcome:E(`loading`,n)}:l?{value:m}:{value:m,postGestureOutcome:E(`unsettled`,n)}}function k(e,n,r,i){if(e===`accept-stale`){t({level:`warn`,phase:`post_gesture_snapshot_stale_accept`,data:{action:n,attempts:r,durationMs:i,matchedPreGestureBaseline:!0}});return}t({level:r>2?`info`:`debug`,phase:`post_gesture_snapshot_stabilized`,data:{action:n,attempts:r,durationMs:i}})}function A(e,n,r,i){if(e.verdict!==`accept-stale`)return{value:r.value};let a=e.preActionBaseline;return i.surfacesIdentical(a.signature,r.signature)?{value:r.value,postGestureOutcome:E(`no-effect`,n)}:(t({level:`info`,phase:`post_gesture_no_effect_vetoed`,data:{action:n.action,backend:r.comparisonKey,reason:`surface_divergence`,...i.summarizeDivergence(a.signature,r.signature)}}),{value:r.value})}export{i as a,r as c,l as d,s as f,p as i,u as l,O as n,a as o,h as r,o as s,T as t,c as u};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pt as e,rt as t,x as n,z as r}from"./sdk-io.js";import i from"node:path";import{readlink as a}from"node:fs/promises";import{clearTimeout as o,setTimeout as s}from"node:timers";const c=4096;async function l(i,a,o=1e3){let s=r(i).filter(e=>e<=2147483647);if(s.length===0)return new Map;let c=n();return c===`linux`?await d(s,o):c!==`darwin`&&c!==`win32`?new Map:await e(async()=>{try{let e=c===`win32`,n=e?u(a.env):`/usr/bin/osascript`;if(!n)return new Map;let r=await t(n,e?p(s):f(s),{allowFailure:!0,timeoutMs:e?Math.max(o,2e3):o});return r.exitCode===0?m(r.stdout,s,e):new Map}catch{return new Map}})}function u(e){let t=Object.keys(e).find(e=>e.toUpperCase()===`SYSTEMROOT`),n=t===void 0?void 0:e[t];if(!(!n||!i.win32.isAbsolute(n)||i.win32.parse(n).root.length<3))return i.win32.join(n,`System32`,`WindowsPowerShell`,`v1.0`,`powershell.exe`)}async function d(e,t){let n=Promise.all(e.map(async e=>{try{let t=await a(`/proc/${e}/exe`,{encoding:`buffer`});if(t.length>=c)return;let n=new TextDecoder(`utf-8`,{fatal:!0}).decode(t);return h(n,!1)&&!n.endsWith(` (deleted)`)?[e,n]:void 0}catch{return}})),r=()=>{};try{let e=await Promise.race([n,new Promise(e=>{let n=s(e,t);r=()=>o(n)})]);return new Map(e?.filter(e=>e!==void 0)??[])}finally{r()}}function f(e){return[`-l`,`JavaScript`,`-e`,`ObjC.import("Foundation"); ObjC.bindFunction("proc_pidpath", ["int", ["int", "void *", "uint32"]]); JSON.stringify(${JSON.stringify(e)}.map(function(pid) { var b=$.NSMutableData.dataWithLength(${c}); var n=$.proc_pidpath(pid,b.mutableBytes,${c}); if(n<=0 || n>=${c}) return {pid:pid}; var d=$.NSData.dataWithBytesLength(b.bytes,n); try { var s=$.NSString.alloc.initWithDataEncoding(d,$.NSUTF8StringEncoding); return {pid:pid,path:ObjC.unwrap(s)}; } catch (_) { return {pid:pid}; } }));`]}function p(e){return[`-NoProfile`,`-NonInteractive`,`-Command`,`$OutputEncoding=[Console]::OutputEncoding=[System.Text.UTF8Encoding]::new(); ConvertTo-Json -Compress -InputObject @(Get-CimInstance Win32_Process -Filter '${e.map(e=>`ProcessId=${e}`).join(` OR `)}' | ForEach-Object { @{pid=$_.ProcessId; path=$_.ExecutablePath} })`]}function m(e,t,n){let r=new Map;try{let i=JSON.parse(e.replace(/^\uFEFF/,``));if(!Array.isArray(i))return r;let a=new Set(t),o=new Set;for(let e of i){if(!e||typeof e!=`object`)continue;let{pid:t,path:i}=e;if(!(typeof t!=`number`||!a.has(t))){if(o.has(t)){r.delete(t);continue}o.add(t),typeof i==`string`&&h(i,n)&&r.set(t,i)}}}catch{return new Map}return r}function h(e,t){return e.length>0&&Buffer.byteLength(e,`utf8`)<c&&!/[\0\uFFFD]/.test(e)&&(t?i.win32.isAbsolute(e):i.posix.isAbsolute(e))}export{l as readProcessExecutablePaths};
|
package/dist/src/process-exit.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{q as e}from"./sdk-io.js";import"./retry.js";async function t(t){await Promise.race([n(),e(2e3)]),process.exit(t)}async function n(){await Promise.all([r(process.stdout),r(process.stderr)])}function r(e){return e.writableLength===0?Promise.resolve():new Promise(t=>{e.once(`drain`,t)})}export{t as exitAfterFlush};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { B as SnapshotOptions$1, C as DeviceKind, E as PlatformSelector, F as Rect, M as Point, N as PresentedSurface, P as RawSnapshotNode, R as SnapshotKeyboardBandFact, S as DeviceInfo, f as LeaseBackend, j as IosTargetActivation, w as DeviceTarget, z as SnapshotNode } from "./sdk-contracts.js";
|
|
2
|
+
import { C as SnapshotProvenance, S as SnapshotProducerRegistry } from "./sdk-selectors.js";
|
|
3
3
|
import { A as ScrollDirection, F as BackMode, I as SessionSurface, _ as TvRemoteButton, b as DeviceRotation, g as TextSizeCategory, k as ScreenshotScreenMask, n as CloudArtifactProvider, p as ReadableSetting, s as InteractorSnapshotCapture, y as ScrollExecutionOptions } from "./cloud-artifacts.js";
|
|
4
4
|
import { t as GesturePlan } from "./gesture-plan-types.js";
|
|
5
5
|
import { t as AppStateRuntimeResult } from "./app-state-runtime.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{_ as e}from"./sdk-contracts.js";const t={apiKey:`LIMRUN_API_KEY`,region:`LIMRUN_REGION`},n={ios:[`LIM_IOS_INSTANCE_URL`,`LIM_IOS_INSTANCE_TOKEN`],android:[`LIM_ANDROID_INSTANCE_URL`,`LIM_ANDROID_INSTANCE_TOKEN`,`LIM_ANDROID_INSTANCE_ADB_URL`]},r=[...Object.values(t),...n.ios,...n.android],i=new Map([[`ios-instance`,`ios`],[`android-instance`,`android`]]);function a(e){return e===void 0?void 0:i.get(e)}function o(){let e=Object.values(t);return{variables:r,byBackend:Object.fromEntries([...i].map(([t,r])=>[t,[...e,...n[r]]]))}}function s(e){return n[e]}function c(e){let r=u(e,t.apiKey),i=u(e,t.region),a=[`1`,`true`].includes(e.LIMRUN_KEEP_ALIVE?.trim().toLowerCase()??``),o=l(e,n.ios),s=l(e,n.android);if(!r&&!o&&!s)return;let c={ios:o&&{apiUrl:o.LIM_IOS_INSTANCE_URL,token:o.LIM_IOS_INSTANCE_TOKEN},android:s&&{apiUrl:s.LIM_ANDROID_INSTANCE_URL,token:s.LIM_ANDROID_INSTANCE_TOKEN,adbUrl:s.LIM_ANDROID_INSTANCE_ADB_URL}};return{apiKey:r,region:i,keepAlive:a,instances:o||s?c:void 0}}function l(t,n){let r=n.map(e=>[e,u(t,e)]);if(r.every(([,e])=>e===void 0))return;let i=r.filter(([,e])=>e===void 0).map(([e])=>e);if(i.length>0)throw new e(`INVALID_ARGS`,`Limrun instance access is missing ${i.join(`, `)}.`,{hint:`Set ${n.join(`, `)} together from the instance status, or unset them all.`});return Object.fromEntries(r)}function u(e,t){return e[t]?.trim()||void 0}export{c as i,s as n,a as r,o as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as DeviceInfo } from "./sdk-contracts.js";
|
|
2
2
|
import { r as CloudArtifactsResult } from "./cloud-artifacts.js";
|
|
3
3
|
import { r as CloudProviderProfileFields } from "./sdk-remote-config.js";
|
|
4
4
|
import { c as LeaseLifecycleContext, n as ProviderDeviceInstallResult, s as DeviceLease, t as ProviderDeviceInstallOptions } from "./provider-device-runtime.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime.js";import{
|
|
1
|
+
import{r as e}from"./rolldown-runtime.js";import{_ as t}from"./sdk-contracts.js";import{c as n,s as r}from"./sdk-remote-config.js";var i=e({rejectRefusedProviderProfileFields:()=>a,requireResolvedProfilePlatform:()=>s,requireResolvedProfileValue:()=>o});function a(e,n){let i=Object.keys(n.fields).filter(t=>n.fields[t]===`refused`&&l(e?.[t]));if(i.length===0)return;let a=i.length!==1;throw new t(`INVALID_ARGS`,`${i.map(c).join(`, `)} ${a?`are`:`is`} not supported by ${n.label}.`,{hint:`Drop ${a?`those flags`:`the flag`} or use a provider that supports ${a?`them`:`it`}.`,provider:n.provider,flags:i.map(e=>r[e])})}function o(e,n){if(e!==void 0)return e;throw new t(`COMMAND_FAILED`,n,{hint:`Reconnect to regenerate and validate the provider profile.`})}function s(e,n){if(e===`android`||e===`ios`)return e;throw new t(`COMMAND_FAILED`,`${n} profile missed a mobile platform.`,{hint:`Reconnect with --platform ios|android.`})}function c(e){let t=n[e],i=r[e];return t?.length?`${i} (${t.join(`, `)})`:i}function l(e){return e!=null&&e!==!1&&e!==``}export{o as i,a as n,s as r,i as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime.js";import{
|
|
1
|
+
import{r as e}from"./rolldown-runtime.js";import{rt as t}from"./sdk-io.js";import"./command.js";import{a as n}from"./version.js";import{t as r}from"./src15.js";var i=e({bundledCloudWebDriverConnection:()=>o,createBundledCloudWebDriverHost:()=>a});function a(e){return{env:e,clientVersion:n(),runHostCommand:async(e,n)=>({stdout:(await t(e,[...n],{maxBuffer:10485760,timeoutMs:3e4})).stdout})}}function o(e,t){return r(e)?.create(a(t)).connection}export{i as n,o as t};
|
package/dist/src/provider.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{_ as e}from"./sdk-contracts.js";import{t}from"./scoped-provider.js";function n(){return Promise.reject(new e(`COMMAND_FAILED`,`The web provider is not composed for this request.`,{reason:`web-provider-missing`}))}const r=t({open:()=>n(),close:()=>n(),snapshot:()=>n(),screenshot:()=>n(),setViewport:()=>n(),click:()=>n(),fill:()=>n(),typeText:()=>n(),scroll:()=>n()});function i(e){return r.resolve(e)}function a(){return r.hasScope()}async function o(e,t){return await r.run(e,t)}export{a as hasScopedWebProvider,i as resolveWebProvider,o as withWebProvider};
|
package/dist/src/proxy.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{P as e,nt as t}from"./sdk-contracts.js";import{a as n,b as r,c as i,d as a,h as o,i as s,l as c,m as l,n as u,o as d,r as f,s as ee,t as te,u as p,y as m}from"./daemon-http.js";import{a as h}from"./transport.js";import{r as g}from"./src4.js";import{n as ne,t as re}from"./color.js";import{n as ie}from"./shared.js";import{randomBytes as ae,randomUUID as _}from"node:crypto";import oe from"node:http";function se(e){let t=le(e);if(!t)return!1;let n=y(t.meta);return ue(n)?!1:v(t.source)||v(n?.installSource)}function ce(n){let r=new e(`INVALID_ARGS`,`Invalid params: an install source of kind "path" names a file on the daemon host and is not accepted through the proxy`,{hint:`Upload the artifact, or use a "url" or "github-actions-artifact" source.`});return Response.json({jsonrpc:`2.0`,id:n,error:{code:-32602,message:r.message,data:t(r)}},{status:400})}function le(e){if(e)try{return y(y(JSON.parse(e))?.params)}catch{return}}function ue(e){let t=e?.uploadedArtifactId;return typeof t==`string`&&t.trim().length>0}function v(e){return y(e)?.kind===`path`}function y(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:void 0}const b=Object.keys(p(`client`)),x=i,S=`${te}/`,C=[`content-type`,`content-range`,`x-artifact-type`,`x-artifact-filename`,`x-artifact-hash`,`x-artifact-hash-algorithm`,d],w=[`content-type`,`content-disposition`,`x-request-id`,f],T=[`range`,`x-upload-offset`],E=[`content-length`];function D(e){let t=me(e),n=_();return{instanceId:n,handle:async e=>{try{return await A(e,t,n)}catch(e){return Fe(e)}}}}function O(e){return oe.createServer(k(D(e)))}function k(e){return(t,n)=>{import(`./node-http.js`).then(({serveProxyRequest:r})=>r(e,t,n)).catch(e=>{n.destroyed||n.destroy(e instanceof Error?e:void 0)})}}async function A(e,t,n){let r=ge(e.url);if(e.method===`GET`&&r===`/health`)return await L(e,t,n);if(!_e(r,e.method))return new Response(new TextEncoder().encode(`Not found`),{status:404});if(r!==`/rpc`)return await j(e,r,t,n);let i;try{i=await Se(e,t.maxRpcBodyBytes,`Proxy request body is too large.`)}catch(e){return Z(null,e)}let a=Pe(i);if(a)return a;try{return await j(e,r,t,n,i)}catch(e){return Z(Y(i),e)}}async function j(e,t,n,r,i){let a=await M(e,n,i);return a?a.tenantId&&!P(t,a.tenantId)?Response.json({ok:!1,error:`Session is outside this tenant`,code:`UNAUTHORIZED`},{status:401}):a.tenantId&&t===`/rpc`&&!I(i)?Ne(Y(i)):Ae(e,t,Y(i),r)||(se(i)?ce(Y(i)):await z({request:e,route:t,options:n,rpcBody:i,caller:a})):Me(t,Y(i))}async function M(t,n,i){if(!n.authenticate)return Ce(t,n.clientToken??``,i)?{uploadHeaders:p(n.clientToken)}:null;let a=await n.authenticate(new Request(t.url,{method:t.method,headers:t.headers,signal:t.signal,...i===void 0?{}:{body:i}}));if(!a)return null;let o=r(typeof a.tenantId==`string`?a.tenantId:void 0);if(!o)throw new e(`COMMAND_FAILED`,`Proxy authenticate returned an invalid tenantId`,{hint:`Return a tenantId of 1-128 letters, digits, ".", "_" or "-".`});return{tenantId:o,uploadHeaders:a.uploadHeaders??N(t)}}function N(e){let t={};for(let n of b){let r=e.headers.get(n);r!==null&&(t[n]=r)}return t}function P(e,t){if(!G(e))return!0;try{return m(t,decodeURIComponent(e.split(`/`)[2]??``))}catch{return!1}}const F=new Set([`agent_device.command`,`agent-device.command`,`agent_device.lease.allocate`,`agent-device.lease.allocate`,`agent_device.lease.heartbeat`,`agent-device.lease.heartbeat`,`agent_device.lease.release`,`agent-device.lease.release`]);function I(e){let t=Oe(e);return t!==void 0&&F.has(t)}async function L(e,t,n){let[r,{readVersion:i},{readHostCpuArch:a}]=await Promise.all([R(e,t),import(`./version.js`).then(e=>e.t),import(`./sdk-io.js`).then(e=>e.r)]);return Response.json(c(`agent-device-proxy`,i(),{upstream:r,instanceId:n,hostArch:await a()}))}async function R(e,t){let n=await t.upstreamFetch(new Request(l(t.upstreamBaseUrl,`health`),{method:`GET`,headers:q(new Headers,t.upstreamToken,`/health`),signal:AbortSignal.any([e.signal,AbortSignal.timeout(5e3)])})),r=await n.text();try{return r?JSON.parse(r):{ok:n.ok,status:n.status}}catch{return{ok:n.ok,status:n.status}}}async function z(e){let{request:t,route:n,options:r,rpcBody:i,caller:a}=e,o=xe(t,n,i,r.upstreamToken,a.tenantId),s=await r.upstreamFetch(new Request(ye(r.upstreamBaseUrl,n,t.url),{method:t.method,headers:q(t.headers,r.upstreamToken,n,a.tenantId),signal:B(t,r),...o?{body:o,duplex:`half`}:{}})),c=V(s,t,n);return K(n)?await U({request:t,upstreamResponse:s,headers:c,uploadHeaders:a.uploadHeaders}):new Response(s.body,{status:s.status,headers:c})}function B(e,t){return t.upstreamTimeoutMs===void 0?e.signal:AbortSignal.any([e.signal,AbortSignal.timeout(t.upstreamTimeoutMs)])}function V(e,t,n){let r=new Headers;for(let t of[...w,...H(n)]){let n=e.headers.get(t);n&&r.set(t,n)}return r.has(`x-request-id`)||r.set(`x-request-id`,ke(t)),r}function H(e){return e.startsWith(`/upload/direct/`)?T:e.startsWith(`/artifacts/`)?E:[]}async function U(e){let{request:t,upstreamResponse:n,headers:r,uploadHeaders:i}=e,a=await n.text();return r.set(`content-type`,n.headers.get(`content-type`)??`application/json`),new Response(de(a,t,i),{status:n.status,headers:r})}function de(e,t,n){let r;try{r=JSON.parse(e)}catch{return e}if(!r||typeof r!=`object`)return e;let i=r;if(!i.upload||typeof i.upload!=`object`)return e;let a=typeof i.upload.url==`string`?pe(i.upload.url,t):null;return JSON.stringify({...r,upload:{...i.upload,...a?{url:a}:{},headers:{...fe(i.upload.headers),...a?n:{}}}})}function fe(e){if(!e||typeof e!=`object`)return{};for(let[t,n]of Object.entries(e))if(t.toLowerCase()===`content-type`&&typeof n==`string`)return{"content-type":n};return{}}function pe(e,t){let n;try{n=new URL(e)}catch{return null}if(!n.pathname.startsWith(`/upload/`))return null;let r=new URL(t.url),i=r.pathname.lastIndexOf(`/upload/preflight`),a=i>=0?r.pathname.slice(0,i):``,o=t.headers.get(`x-forwarded-proto`)?.split(`,`)[0]?.trim().toLowerCase(),s=new URL(r.origin);return(o===`http`||o===`https`)&&(s.protocol=o),s.pathname=`${a}${n.pathname}`,s.search=n.search,s.toString()}function me(e){return{upstreamBaseUrl:he(e.upstreamBaseUrl,`upstreamBaseUrl`),upstreamToken:W(e.upstreamToken,`upstreamToken`),clientToken:e.authenticate?void 0:W(e.clientToken??``,`clientToken`),authenticate:e.authenticate,maxRpcBodyBytes:e.maxRpcBodyBytes??x,upstreamTimeoutMs:e.upstreamTimeoutMs,upstreamFetch:e.upstreamFetch??(e=>fetch(e))}}function he(t,n){try{let e=new URL(t);if(e.protocol!==`http:`&&e.protocol!==`https:`)throw Error(`unsupported protocol`);return e.toString().replace(/\/+$/,``)}catch(r){throw new e(`INVALID_ARGS`,`Invalid ${n}`,{[n]:t},r)}}function W(t,n){let r=t.trim();if(!r)throw new e(`INVALID_ARGS`,`Proxy ${n} is required.`);return r}function ge(e){let t=new URL(e).pathname;return t===`/agent-device`?`/`:t.startsWith(S)?`/${t.slice(S.length)}`:t}function _e(e,t){return e===`/rpc`?t===`POST`:ve(e,t)?!0:e===`/artifacts`||e===`/artifacts/`||e.startsWith(`/artifacts/`)||G(e)?t===`GET`:!1}function G(e){let t=e.split(`/`);return t.length===6&&t[1]===`sessions`&&t[3]===`requests`&&t[5]===`diagnostics`&&t[2]!==``&&t[4]!==``}function ve(e,t){return e===`/upload`||K(e)||e===`/upload/finalize`?t===`POST`:e.startsWith(`/upload/direct/`)?t===`PUT`:!1}function K(e){return e===`/upload/preflight`}function ye(e,t,n){let r=new URL(l(e,t));return r.search=new URL(n).search,r}function be(e){let t=e.get(ee);return t===null?{}:{[u]:t}}function q(e,t,r,i){let a=new Headers;for(let t of C){let n=e.get(t);n?.trim()&&a.set(t,n)}if(i&&a.set(d,i),r===`/rpc`&&!a.has(`content-type`)&&a.set(`content-type`,`application/json`),r===`/rpc`){a.set(s,n);for(let[t,n]of Object.entries(be(e)))a.set(t,n)}for(let[e,n]of Object.entries(p(t)))a.set(e,n);return a}function xe(e,t,n,r,i){return e.method===`GET`||e.method===`HEAD`?null:t===`/rpc`?Te(n??``,r,i):e.body}async function Se(t,n,r){if(!t.body)return``;let i=t.body.getReader(),a=[],o=0;for(;;){let{done:t,value:s}=await i.read();if(t)break;if(o+=s.byteLength,o>n)throw await i.cancel(),new e(`INVALID_ARGS`,r);a.push(s)}return Buffer.concat(a).toString(`utf8`)}function Ce(e,t,n){let r=we(e,n);return r.length>0&&h(r,t)}function we(e,t){let n=e.headers.get(`authorization`)??``;if(n.toLowerCase().startsWith(`bearer `))return n.slice(7);let r=e.headers.get(`x-agent-device-token`);if(r!==null)return r;if(t){let e=De(t);if(e)return e}return``}function Te(e,t,n){let r=JSON.parse(e);return r.params={...r.params??{},token:t},n&&Ee(r.params,n),JSON.stringify(r)}function Ee(e,t){e.tenantId=t,e.meta={...J(e.meta),tenantId:t,sessionIsolation:`tenant`};let n=J(e.flags);n.tenant!==void 0&&(n.tenant=t),n.sessionIsolation!==void 0&&(n.sessionIsolation=`tenant`)}function J(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:{}}function De(e){try{let t=JSON.parse(e);return typeof t.params?.token==`string`?t.params.token:``}catch{return``}}function Oe(e){if(e)try{let{method:t}=JSON.parse(e);return typeof t==`string`?t:void 0}catch{return}}function Y(e){if(!e)return null;try{return JSON.parse(e).id??null}catch{return null}}function ke(e){let t=e.headers.get(`x-request-id`);return t?.trim()?t.trim().slice(0,128):_()}function Ae(e,t,n,r){if(t!==`/rpc`)return null;let i=e.headers.get(u);return i===null||i===r?null:je(n)}function je(n){return Response.json(o(n,`Proxy instance changed`,t(new e(`COMMAND_FAILED`,`Proxy instance changed`,{reason:`remote_instance_mismatch`}))),{status:409,headers:{[f]:`true`}})}function Me(n,r){return n===`/rpc`?Response.json({jsonrpc:`2.0`,id:r,error:{code:-32001,message:`Invalid proxy token`,data:t(new e(`UNAUTHORIZED`,`Invalid proxy token`))}},{status:401}):Response.json({ok:!1,error:`Invalid proxy token`,code:`UNAUTHORIZED`},{status:401})}function Ne(n){let r=new e(`UNAUTHORIZED`,`This RPC method cannot act as an authenticated tenant through the proxy`,{hint:`Use agent_device.command or the agent_device.lease methods.`});return Response.json({jsonrpc:`2.0`,id:n,error:{code:-32001,message:r.message,data:t(r)}},{status:401})}function Pe(e){let t;try{t=JSON.parse(e)}catch{return X(-32700,`Parse error`)}return t&&typeof t==`object`&&!Array.isArray(t)?null:X(-32600,`Invalid Request`)}function X(n,r){return Response.json({jsonrpc:`2.0`,id:null,error:{code:n,message:r,data:t(new e(`INVALID_ARGS`,r))}},{status:400})}function Z(e,n){let r=t(n),i=r.code===`INVALID_ARGS`;return Response.json({jsonrpc:`2.0`,id:e,error:{code:i?-32602:-32e3,message:r.message,data:r}},{status:i?400:500})}function Fe(e){let n=t(e);return Response.json({ok:!1,error:n.message,code:n.code},{status:n.code===`INVALID_ARGS`?400:500})}const Q=async({positionals:t,flags:n,host:r})=>{if(t.length>0)throw new e(`INVALID_ARGS`,`proxy does not accept positional arguments.`);let i=await Ie(n,r);return await ie(n,i,()=>Ve(i)),await He(),!0};async function Ie(t,n){let r=await g({stateDir:t.stateDir,host:n}),i=Le(r.httpPort),o=Re(t),s=O({upstreamBaseUrl:i,upstreamToken:r.token,clientToken:o});await ze(s,t.proxyHost?.trim()||`127.0.0.1`,t.proxyPort??0);let c=s.address();if(!c||typeof c==`string`)throw new e(`COMMAND_FAILED`,`Proxy did not bind to a TCP address.`);let l=`http://${Be(c.address)}:${c.port}`;return{proxyBaseUrl:l,agentDeviceBaseUrl:a(l),token:o,upstreamBaseUrl:i,stateDir:r.stateDir}}function Le(t){if(!t)throw new e(`COMMAND_FAILED`,`Local daemon HTTP endpoint is unavailable.`,{hint:`Retry after cleaning daemon state, or run proxy with a fresh --state-dir.`});return`http://127.0.0.1:${t}`}function Re(e){return e.daemonAuthToken?.trim()||ae(32).toString(`hex`)}function ze(e,t,n){return new Promise((r,i)=>{e.once(`error`,i),e.listen(n,t,()=>{e.off(`error`,i),r()})})}function Be(e){return e.includes(`:`)&&!e.startsWith(`[`)?`[${e}]`:e}function Ve(e,t={}){let n=t.useColor??ne(process.env,process.stdout),r=$(`✓`,`green`,n),i=$(e.proxyBaseUrl,`cyan`,n),a=$(`<tunnel URL>`,`cyan`,n),o=$(e.token,`yellow`,n);return[`${r} Proxy listening at ${i}`,``,`Provide this to the agent-device instance connecting:`,``,`Daemon base URL: ${a}`,`Daemon auth token: ${o}`].join(`
|
|
2
|
-
`)}function $(e,t,n){return n?re(e,t,{validateStream:!1}):e}function
|
|
1
|
+
import{_ as e,z as t}from"./sdk-contracts.js";import{S as n,a as r,c as i,d as a,h as o,i as s,l as c,m as l,n as u,o as d,r as f,s as ee,t as te,u as p,x as m,y as h}from"./daemon-http.js";import{u as g}from"./transport.js";import{r as _}from"./src4.js";import{n as ne,t as re}from"./color.js";import{n as ie}from"./shared.js";import{randomBytes as ae,randomUUID as v}from"node:crypto";import oe from"node:http";function se(e){let t=le(e);if(!t)return!1;let n=b(t.meta);return ue(n)?!1:y(t.source)||y(n?.installSource)}function ce(n){let r=new e(`INVALID_ARGS`,`Invalid params: an install source of kind "path" names a file on the daemon host and is not accepted through the proxy`,{hint:`Upload the artifact, or use a "url" or "github-actions-artifact" source.`});return Response.json({jsonrpc:`2.0`,id:n,error:{code:-32602,message:r.message,data:t(r)}},{status:400})}function le(e){if(e)try{return b(b(JSON.parse(e))?.params)}catch{return}}function ue(e){let t=e?.uploadedArtifactId;return typeof t==`string`&&t.trim().length>0}function y(e){return b(e)?.kind===`path`}function b(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:void 0}const x=Object.keys(p(`client`)),S=i,C=`${te}/`,w=[`content-type`,`content-range`,`x-artifact-type`,`x-artifact-filename`,`x-artifact-hash`,`x-artifact-hash-algorithm`,d],T=[`content-type`,`content-disposition`,`x-request-id`,f],E=[`range`,`x-upload-offset`],D=[`content-length`];function O(e){let t=he(e),n=v();return{instanceId:n,handle:async e=>{try{return await j(e,t,n)}catch(e){return Q(e)}}}}function k(e){return oe.createServer(A(O(e)))}function A(e){return(t,n)=>{import(`./node-http.js`).then(({serveProxyRequest:r})=>r(e,t,n)).catch(e=>{n.destroyed||n.destroy(e instanceof Error?e:void 0)})}}async function j(e,t,n){let r=_e(e.url);if(e.method===`GET`&&r===`/health`)return await R(e,t,n);if(!ve(r,e.method))return new Response(new TextEncoder().encode(`Not found`),{status:404});if(r!==`/rpc`)return await M(e,r,t,n);let i;try{i=await Ce(e,t.maxRpcBodyBytes,`Proxy request body is too large.`)}catch(e){return Z(null,e)}let a=Fe(i);if(a)return a;try{return await M(e,r,t,n,i)}catch(e){return Z(Y(i),e)}}async function M(e,t,n,r,i){let a=await N(e,n,i);return a?a.tenantId&&!F(t,a.tenantId)?Response.json({ok:!1,error:`Session is outside this tenant`,code:`UNAUTHORIZED`},{status:401}):a.tenantId&&t===`/rpc`&&!L(i)?Pe(Y(i)):je(e,t,Y(i),r)||(se(i)?ce(Y(i)):await B({request:e,route:t,options:n,rpcBody:i,caller:a})):Ne(t,Y(i))}async function N(t,r,i){if(!r.authenticate)return we(t,r.clientToken??``,i)?{uploadHeaders:p(r.clientToken)}:null;let a=await r.authenticate(new Request(t.url,{method:t.method,headers:t.headers,signal:t.signal,...i===void 0?{}:{body:i}}));if(!a)return null;let o=n(typeof a.tenantId==`string`?a.tenantId:void 0);if(!o)throw new e(`COMMAND_FAILED`,`Proxy authenticate returned an invalid tenantId`,{hint:`Return a tenantId of 1-128 letters, digits, ".", "_" or "-".`});return{tenantId:o,uploadHeaders:a.uploadHeaders??P(t)}}function P(e){let t={};for(let n of x){let r=e.headers.get(n);r!==null&&(t[n]=r)}return t}function F(e,t){if(!G(e))return!0;try{return h(t,decodeURIComponent(e.split(`/`)[2]??``))}catch{return!1}}const I=new Set([`agent_device.command`,`agent-device.command`,`agent_device.lease.allocate`,`agent-device.lease.allocate`,`agent_device.lease.heartbeat`,`agent-device.lease.heartbeat`,`agent_device.lease.release`,`agent-device.lease.release`]);function L(e){let t=ke(e);return t!==void 0&&I.has(t)}async function R(e,t,n){let[r,{readVersion:i},{readHostCpuArch:a}]=await Promise.all([z(e,t),import(`./version.js`).then(e=>e.t),import(`./sdk-io.js`).then(e=>e.r)]);return Response.json(c(`agent-device-proxy`,i(),{upstream:r,instanceId:n,hostArch:await a()}))}async function z(e,t){let n=await t.upstreamFetch(new Request(l(t.upstreamBaseUrl,`health`),{method:`GET`,headers:q(new Headers,t.upstreamToken,`/health`),signal:AbortSignal.any([e.signal,AbortSignal.timeout(5e3)])})),r=await n.text();try{return r?JSON.parse(r):{ok:n.ok,status:n.status}}catch{return{ok:n.ok,status:n.status}}}async function B(e){let{request:t,route:n,options:r,rpcBody:i,caller:a}=e,o=Se(t,n,i,r.upstreamToken,a.tenantId),s=await r.upstreamFetch(new Request(be(r.upstreamBaseUrl,n,t.url),{method:t.method,headers:q(t.headers,r.upstreamToken,n,a.tenantId),signal:V(t,r),...o?{body:o,duplex:`half`}:{}})),c=H(s,t,n);return K(n)?await de({request:t,upstreamResponse:s,headers:c,uploadHeaders:a.uploadHeaders,publicOrigin:r.publicOrigin}):new Response(s.body,{status:s.status,headers:c})}function V(e,t){return t.upstreamTimeoutMs===void 0?e.signal:AbortSignal.any([e.signal,AbortSignal.timeout(t.upstreamTimeoutMs)])}function H(e,t,n){let r=new Headers;for(let t of[...T,...U(n)]){let n=e.headers.get(t);n&&r.set(t,n)}return r.has(`x-request-id`)||r.set(`x-request-id`,Ae(t)),r}function U(e){return e.startsWith(`/upload/direct/`)?E:e.startsWith(`/artifacts/`)?D:[]}async function de(e){let{request:t,upstreamResponse:n,headers:r,uploadHeaders:i,publicOrigin:a}=e,o=await n.text();return r.set(`content-type`,n.headers.get(`content-type`)??`application/json`),new Response(fe(o,t,i,a,n.ok),{status:n.status,headers:r})}function fe(e,t,n,r,i){let a;try{a=JSON.parse(e)}catch{if(!i)return e;throw Error(`Invalid upstream upload ticket`)}if(!i&&(!a||typeof a!=`object`||!(`upload`in a)))return e;if(!a||typeof a!=`object`)throw Error(`Invalid upstream upload ticket`);let o=a;if(typeof o.uploadId!=`string`||!o.uploadId||o.uploadId.trim()!==o.uploadId||o.uploadId.includes(`/`)||!o.upload||typeof o.upload!=`object`)throw Error(`Invalid upstream upload ticket`);let s=typeof o.upload.url==`string`?me(o.upload.url,o.uploadId,t,r):null;if(!s)throw Error(`Invalid upstream upload ticket`);return JSON.stringify({...a,upload:{...o.upload,url:s,headers:{...pe(o.upload.headers),...n}}})}function pe(e){if(!e||typeof e!=`object`)return{};for(let[t,n]of Object.entries(e))if(t.toLowerCase()===`content-type`&&typeof n==`string`)return{"content-type":n};return{}}function me(e,t,n,r){let i;try{i=new URL(e)}catch{return null}if(![`http:`,`https:`].includes(i.protocol)||i.username||i.password||i.hash||i.pathname!==`/upload/direct/${t}`)return null;let a=new URL(n.url),o=a.pathname.lastIndexOf(`/upload/preflight`),s=o>=0?a.pathname.slice(0,o):``,c=new URL(r??a.origin);return c.pathname=`${s}${i.pathname}`,c.search=i.search,c.toString()}function he(e){let t=ge(e.upstreamBaseUrl,`upstreamBaseUrl`),n=W(e.upstreamToken,`upstreamToken`),r=e.authenticate?void 0:W(e.clientToken??``,`clientToken`);return{upstreamBaseUrl:t,publicOrigin:e.publicOrigin===void 0?void 0:m(e.publicOrigin),upstreamToken:n,clientToken:r,authenticate:e.authenticate,maxRpcBodyBytes:e.maxRpcBodyBytes??S,upstreamTimeoutMs:e.upstreamTimeoutMs,upstreamFetch:e.upstreamFetch??(e=>fetch(e))}}function ge(t,n){try{let e=new URL(t);if(e.protocol!==`http:`&&e.protocol!==`https:`)throw Error(`unsupported protocol`);return e.toString().replace(/\/+$/,``)}catch(r){throw new e(`INVALID_ARGS`,`Invalid ${n}`,{[n]:t},r)}}function W(t,n){let r=t.trim();if(!r)throw new e(`INVALID_ARGS`,`Proxy ${n} is required.`);return r}function _e(e){let t=new URL(e).pathname;return t===`/agent-device`?`/`:t.startsWith(C)?`/${t.slice(C.length)}`:t}function ve(e,t){return e===`/rpc`?t===`POST`:ye(e,t)?!0:e===`/artifacts`||e===`/artifacts/`||e.startsWith(`/artifacts/`)||G(e)?t===`GET`:!1}function G(e){let t=e.split(`/`);return t.length===6&&t[1]===`sessions`&&t[3]===`requests`&&t[5]===`diagnostics`&&t[2]!==``&&t[4]!==``}function ye(e,t){return e===`/upload`||K(e)||e===`/upload/finalize`?t===`POST`:e.startsWith(`/upload/direct/`)?t===`PUT`:!1}function K(e){return e===`/upload/preflight`}function be(e,t,n){let r=new URL(l(e,t));return r.search=new URL(n).search,r}function xe(e){let t=e.get(ee);return t===null?{}:{[u]:t}}function q(e,t,n,i){let a=new Headers;for(let t of w){let n=e.get(t);n?.trim()&&a.set(t,n)}if(i&&a.set(d,i),n===`/rpc`&&!a.has(`content-type`)&&a.set(`content-type`,`application/json`),n===`/rpc`){a.set(s,r);for(let[t,n]of Object.entries(xe(e)))a.set(t,n)}for(let[e,n]of Object.entries(p(t)))a.set(e,n);return a}function Se(e,t,n,r,i){return e.method===`GET`||e.method===`HEAD`?null:t===`/rpc`?Ee(n??``,r,i):e.body}async function Ce(t,n,r){if(!t.body)return``;let i=t.body.getReader(),a=[],o=0;for(;;){let{done:t,value:s}=await i.read();if(t)break;if(o+=s.byteLength,o>n)throw await i.cancel(),new e(`INVALID_ARGS`,r);a.push(s)}return Buffer.concat(a).toString(`utf8`)}function we(e,t,n){let r=Te(e,n);return r.length>0&&g(r,t)}function Te(e,t){let n=e.headers.get(`authorization`)??``;if(n.toLowerCase().startsWith(`bearer `))return n.slice(7);let r=e.headers.get(`x-agent-device-token`);if(r!==null)return r;if(t){let e=Oe(t);if(e)return e}return``}function Ee(e,t,n){let r=JSON.parse(e);return r.params={...r.params??{},token:t},n&&De(r.params,n),JSON.stringify(r)}function De(e,t){e.tenantId=t,e.meta={...J(e.meta),tenantId:t,sessionIsolation:`tenant`};let n=J(e.flags);n.tenant!==void 0&&(n.tenant=t),n.sessionIsolation!==void 0&&(n.sessionIsolation=`tenant`)}function J(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:{}}function Oe(e){try{let t=JSON.parse(e);return typeof t.params?.token==`string`?t.params.token:``}catch{return``}}function ke(e){if(e)try{let{method:t}=JSON.parse(e);return typeof t==`string`?t:void 0}catch{return}}function Y(e){if(!e)return null;try{return JSON.parse(e).id??null}catch{return null}}function Ae(e){let t=e.headers.get(`x-request-id`);return t?.trim()?t.trim().slice(0,128):v()}function je(e,t,n,r){if(t!==`/rpc`)return null;let i=e.headers.get(u);return i===null||i===r?null:Me(n)}function Me(n){return Response.json(o(n,`Proxy instance changed`,t(new e(`COMMAND_FAILED`,`Proxy instance changed`,{reason:`remote_instance_mismatch`}))),{status:409,headers:{[f]:`true`}})}function Ne(n,r){return n===`/rpc`?Response.json({jsonrpc:`2.0`,id:r,error:{code:-32001,message:`Invalid proxy token`,data:t(new e(`UNAUTHORIZED`,`Invalid proxy token`))}},{status:401}):Response.json({ok:!1,error:`Invalid proxy token`,code:`UNAUTHORIZED`},{status:401})}function Pe(n){let r=new e(`UNAUTHORIZED`,`This RPC method cannot act as an authenticated tenant through the proxy`,{hint:`Use agent_device.command or the agent_device.lease methods.`});return Response.json({jsonrpc:`2.0`,id:n,error:{code:-32001,message:r.message,data:t(r)}},{status:401})}function Fe(e){let t;try{t=JSON.parse(e)}catch{return X(-32700,`Parse error`)}return t&&typeof t==`object`&&!Array.isArray(t)?null:X(-32600,`Invalid Request`)}function X(n,r){return Response.json({jsonrpc:`2.0`,id:null,error:{code:n,message:r,data:t(new e(`INVALID_ARGS`,r))}},{status:400})}function Z(e,n){let r=t(n),i=r.code===`INVALID_ARGS`;return Response.json({jsonrpc:`2.0`,id:e,error:{code:i?-32602:-32e3,message:r.message,data:r}},{status:i?400:500})}function Q(e){let n=t(e);return Response.json({ok:!1,error:n.message,code:n.code},{status:n.code===`INVALID_ARGS`?400:500})}const Ie=async({positionals:t,flags:n,host:r})=>{if(t.length>0)throw new e(`INVALID_ARGS`,`proxy does not accept positional arguments.`);let i=await Le(n,r);return await ie(n,i,()=>He(i)),await Ue(),!0};async function Le(t,n){let r;if(t.publicOrigin!==void 0)try{r=m(t.publicOrigin)}catch(t){throw new e(`INVALID_ARGS`,`Invalid --public-origin`,{},t)}let i=await _({stateDir:t.stateDir,host:n}),o=Re(i.httpPort),s=ze(t),c=k({upstreamBaseUrl:o,upstreamToken:i.token,clientToken:s,publicOrigin:r});await Be(c,t.proxyHost?.trim()||`127.0.0.1`,t.proxyPort??0);let l=c.address();if(!l||typeof l==`string`)throw new e(`COMMAND_FAILED`,`Proxy did not bind to a TCP address.`);let u=`http://${Ve(l.address)}:${l.port}`;return{proxyBaseUrl:u,agentDeviceBaseUrl:a(u),token:s,upstreamBaseUrl:o,stateDir:i.stateDir}}function Re(t){if(!t)throw new e(`COMMAND_FAILED`,`Local daemon HTTP endpoint is unavailable.`,{hint:`Retry after cleaning daemon state, or run proxy with a fresh --state-dir.`});return`http://127.0.0.1:${t}`}function ze(e){return e.daemonAuthToken?.trim()||ae(32).toString(`hex`)}function Be(e,t,n){return new Promise((r,i)=>{e.once(`error`,i),e.listen(n,t,()=>{e.off(`error`,i),r()})})}function Ve(e){return e.includes(`:`)&&!e.startsWith(`[`)?`[${e}]`:e}function He(e,t={}){let n=t.useColor??ne(process.env,process.stdout),r=$(`✓`,`green`,n),i=$(e.proxyBaseUrl,`cyan`,n),a=$(`<tunnel URL>`,`cyan`,n),o=$(e.token,`yellow`,n);return[`${r} Proxy listening at ${i}`,``,`Provide this to the agent-device instance connecting:`,``,`Daemon base URL: ${a}`,`Daemon auth token: ${o}`].join(`
|
|
2
|
+
`)}function $(e,t,n){return n?re(e,t,{validateStream:!1}):e}function Ue(){return new Promise(()=>{})}export{Ie as proxyCommand};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{_ as e}from"./sdk-contracts.js";import{n as t}from"./metro-session-hints.js";import{createHash as n}from"node:crypto";import{parseArgs as r}from"node:util";const i={0:`unknown`,1:`class`,5:`function`,6:`forwardRef`,8:`memo`,15:`function`};function a(e){return Object.hasOwn(i,e)?i[e]:`unknown`}const o=/^([A-Za-z0-9_$]+)\((.+)\)$/;function s(e,t=!1){let n=[],r=e;for(let e=o.exec(r);e&&!(t&&e[1]!==`Memo`&&e[1]!==`ForwardRef`);e=o.exec(r))n.push(e[1]),r=e[2];return{name:r,wrappers:n}}function c(e){return s(e,!0).name}function l(e){return`@c${e.id}`}function u(e){let t=a(e);return t===`memo`||t===`class`||t===`forwardRef`?` [${t}]`:``}function d(e){return e.appId??e.description??e.title}async function f(t){let n=new URL(`json/list`,E(t)),r;try{r=await fetch(n,{signal:AbortSignal.timeout(3e3)})}catch(n){throw new e(`COMMAND_FAILED`,`Could not reach the React Native dev server at ${t.origin}.`,{hint:`Start Metro (or Expo/Re.Pack) for the app, or pass --metro-port/--metro-host when it does not run on localhost:8081.`},n)}if(!r.ok)throw new e(`COMMAND_FAILED`,`The dev server at ${t.origin} answered ${r.status} for /json/list.`);let i=await r.json().catch(()=>void 0);if(!Array.isArray(i))throw new e(`COMMAND_FAILED`,`The server at ${t.origin} is not a React Native dev server: /json/list returned no target list.`,{hint:`Pass --metro-port/--metro-host for the app's Metro, Expo, or Re.Pack dev server.`});return i.filter(p)}function p(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.id==`string`&&typeof t.webSocketDebuggerUrl==`string`}const m=/reanimated|worklet/i;function h(e){let t=Number.parseInt(e.id.slice(e.id.lastIndexOf(`-`)+1),10);return Number.isInteger(t)?t:2**53-1}function g(e){let t=e.id.lastIndexOf(`-`);return e.reactNative?.logicalDeviceId??(t>0?e.id.slice(0,t):void 0)??e.deviceName??e.id}function _(e){return e.reactNative!==void 0&&!m.test(e.description??``)}function v(e,t){let n=t.appId===void 0||d(e)===t.appId,r=t.device===void 0||e.deviceName===t.device||g(e)===t.device;return n&&r}function y(t,n){let r=t.map(e=>`${d(e)} on ${e.deviceName??g(e)}`);return new e(`COMMAND_FAILED`,n.appId||n.device?`No matching React Native runtime is connected to the dev server.`:`No React Native runtime is connected to the dev server.`,{hint:r.length>0?`Connected runtimes: ${[...new Set(r)].join(`, `)}.`:`Open the app from a development build so it loads its bundle from this dev server.`})}function b(e){let t=new Map;for(let n of e){let e=g(n),r=t.get(e);t.set(e,r&&h(r)<=h(n)?r:n)}return[...t.values()]}function x(e){let t=new Map;for(let{deviceName:n}of e)n&&t.set(n,(t.get(n)??0)+1);return e.map(e=>e.deviceName&&t.get(e.deviceName)===1?e.deviceName:g(e))}function S(t,n={}){let r=t.filter(_),i=r.filter(e=>v(e,n));if(i.length===0)throw y(r,n);let a=new Set(i.map(d));if(a.size>1)throw new e(`INVALID_ARGS`,`Several React Native apps are connected to the dev server.`,{hint:`Pass --app with one of: ${[...a].join(`, `)}.`});let o=b(i);if(o.length>1)throw new e(`INVALID_ARGS`,`The app is connected to the dev server from several devices.`,{hint:`Pass --metro-device with one of: ${x(o).join(`, `)}.`});return o[0]}const C=WebSocket;var w=class t{#e=1;#t=new Map;#n;constructor(t){this.#n=t,t.addEventListener(`message`,e=>this.#i(String(e.data))),t.addEventListener(`close`,()=>{for(let{reject:t}of this.#t.values())t(new e(`COMMAND_FAILED`,`The app runtime closed the debugger connection.`));this.#t.clear()})}static async connect(n){let r=new URL(n),i=`http://127.0.0.1:${r.port||(r.protocol===`wss:`?`443`:`80`)}`,a=new C(r,{headers:{origin:i}});return await new Promise((t,n)=>{let r=setTimeout(()=>{a.close(),n(new e(`COMMAND_FAILED`,`Timed out connecting to the app runtime debugger.`))},5e3);a.addEventListener(`open`,()=>{clearTimeout(r),t()},{once:!0}),a.addEventListener(`error`,()=>{clearTimeout(r),n(new e(`COMMAND_FAILED`,`The dev server refused the debugger connection to the app runtime.`))},{once:!0})}),new t(a)}async evaluate(t){let n=await this.#r(`Runtime.evaluate`,{expression:t,returnByValue:!0});if(n.exceptionDetails){let{text:t,exception:r}=n.exceptionDetails;throw new e(`COMMAND_FAILED`,`The profiler runtime threw inside the app.`,void 0,r?.description??t??`unknown exception`)}return n.result?.value}close(){this.#n.close()}#r(t,n){let r=this.#e++;return new Promise((i,a)=>{let o=setTimeout(()=>{this.#t.delete(r),a(new e(`COMMAND_FAILED`,`The app runtime did not answer ${t} in time.`))},3e4);this.#t.set(r,{resolve:e=>{clearTimeout(o),i(e)},reject:e=>{clearTimeout(o),a(e)}}),this.#n.send(JSON.stringify({id:r,method:t,params:n}))})}#i(t){let n;try{n=JSON.parse(t)}catch{return}if(typeof n.id!=`number`)return;let r=this.#t.get(n.id);r&&(this.#t.delete(n.id),n.error?r.reject(new e(`COMMAND_FAILED`,`Debugger protocol error: ${n.error.message??`unknown`}`)):r.resolve(n.result))}};function T(e,t){let n=new URL(t.webSocketDebuggerUrl),r=E(e);return r.protocol=e.protocol===`https:`?`wss:`:`ws:`,r.pathname=`${r.pathname.replace(/\/+$/,``)}${n.pathname}`,r.search=n.search,r.toString()}function E(e){let t=new URL(e);return t.pathname.endsWith(`/`)||(t.pathname=`${t.pathname}/`),t.search=``,t.hash=``,t}function D(e){return e.replaceAll(/[\u0000-\u001f\u007f-\u009f]/g,` `)}function O(e){return e.map(D).join(`
|
|
2
2
|
`)}const k=String.raw`
|
|
3
3
|
(function (VERSION) {
|
|
4
4
|
var g = globalThis;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{_ as e}from"./sdk-contracts.js";import{a as t,c as n,d as r,f as i,i as a,n as o,o as s,p as c,r as l,s as u,t as d}from"./react-devtools-connection.js";function f(e,t){return e.length>t?`${e.slice(0,t-1)}…`:e}var p=class{#e;constructor(e){this.#e=new Set([...e.cleaned,...e.unserializable].map(e=>JSON.stringify(e)))}format(e,t){if(this.#e.has(JSON.stringify(t))){let t=e;return t.preview_short??t.name??t.type??`…`}if(e===void 0)return`undefined`;if(typeof e!=`object`||!e)return typeof e==`string`?JSON.stringify(f(e,60)):String(e);if(Array.isArray(e)){let n=e.slice(0,4).map((e,n)=>this.format(e,[...t,n]));return e.length>4&&n.push(`…${e.length-4}`),`[${n.join(`, `)}]`}let n=Object.entries(e),r=n.slice(0,5).map(([e,n])=>`${e}: ${this.format(n,[...t,e])}`);return n.length>5&&r.push(`…${n.length-5}`),`{${r.join(`, `)}}`}};function m(e,t){if(!t||t.data===null||typeof t.data!=`object`)return[];let n=Object.entries(t.data);if(n.length===0)return[];let r=new p(t);return[`${e}:`,...n.map(([e,t])=>` ${e}: ${f(r.format(t,[e]),160)}`)]}function h(e){return!e.name||e.name===`anonymous`}function g(e){if(!e||!Array.isArray(e.data)||e.data.length===0)return[];let t=new p(e),n=[`hooks:`],r=(e,i,a)=>{e.forEach((e,o)=>{let s=[...i,o],c=` `.repeat(a+1);if(e.subHooks?.length>0&&h(e)){r(e.subHooks,[...s,`subHooks`],a);return}if(e.subHooks?.length>0){n.push(`${c}${e.name}:`),r(e.subHooks,[...s,`subHooks`],a+1);return}n.push(`${c}${e.name}: ${f(t.format(e.value,[...s,`value`]),160)}`)})};return r(e.data,[],0),n}function _(e,t){return t.map(([t,n])=>` ${e}: ${f(s(t.split(`
|
|
2
2
|
`)[0]??``),160)}${n>1?` (x${n})`:``}`)}function v(e){return[..._(`error`,e.errors),..._(`warning`,e.warnings)]}function y(e,t){let n=t.key===null?``:` key=${t.key}`,a=r(t.name??`Anonymous`),o=[`${i({id:e})} ${a}${c(t.type)}${n}`],s=(t.owners??[]).slice(0,4);if(s.length>0){let e=(t.owners?.length??0)>s.length?` < …`:``;o.push(`rendered by: ${s.map(e=>`${e.displayName??`Anonymous`} ${i(e)}`).join(` < `)}${e}`)}t.isErrored&&o.push(`error boundary: showing its error state`),o.push(...m(`props`,t.props),...m(`state`,t.state),...g(t.hooks),...m(`context`,t.context));let l=v(t);return l.length>0&&o.push(`logged while rendering:`,...l),u(o)}function b(e){let t=new Map;for(let[n,i,a,,o,c]of e.nodes){let[l,u]=e.logs[String(n)]??[0,0],d=r(s(i));t.set(n,{id:n,name:d,elementType:a,key:c===null?null:s(c),ownerId:o,children:[],errors:l,warnings:u})}let n=[];for(let[r,,,i]of e.nodes){let e=t.get(r),a=t.get(i);if(!a){n.push(e);continue}e.parent=a,a.children.push(e)}for(let[n,r]of Object.entries(e.order)){let e=t.get(Number(n));if(!e)continue;let i=new Map(r.map((e,t)=>[e,t]));e.children.sort((e,t)=>(i.get(e.id)??1/0)-(i.get(t.id)??1/0))}return{roots:n,byId:t,logsTracked:e.logsTracked}}function x(e,t){return`${e} ${t}${e===1?``:`s`}`}function S(e){let t=[];return e.errors>0&&t.push(x(e.errors,`error`)),e.warnings>0&&t.push(x(e.warnings,`warning`)),t.join(`, `)}function C(e){let t=e.key===null?``:` key=${e.key}`,n=S(e);return`${i(e)} ${e.name}${c(e.elementType)}${t}${n?` (${n})`:``}`}function w(e){return e.children.reduce((e,t)=>e+1+w(t),0)}function T(e){let t=[e];for(let n=e;n.children.length===1;n=n.children[0])t.push(n.children[0]);return t}function E(e){if(e.length<=5)return e.map(C).join(` > `);let t=e.length-2-2;return[...e.slice(0,2).map(C),`(${t} wrappers)`,...e.slice(-2).map(C)].join(` > `)}var D=class{#e=new Map;#t=new Map;of(e){let t=this.#t.get(e);if(t!==void 0)return t;let n=[e.name,e.elementType,e.errors,e.warnings,...e.children.map(e=>this.of(e))].join(`\0`),r=this.#e.get(n);return r===void 0&&(r=this.#e.size,this.#e.set(n,r)),this.#t.set(e,r),r}};function O(e,t){let n=[];for(let r of e){let e=n.at(-1),i=e?.[0];i&&t.of(i)===t.of(r)?e.push(r):n.push([r])}return n.flatMap(e=>e.length>=3?[e]:e.map(e=>[e]))}function k(e,t,n){let r=[],i=new D,a=0,o=e.reduce((e,t)=>e+1+w(t),0),s=(e,o)=>{if(r.length>=n)return;let c=T(e),l=c.at(-1);a+=c.length;let u=` `.repeat(o);if(o+1>=t&&l.children.length>0){r.push(`${u}${E(c)} (+${w(l)} below)`);return}r.push(`${u}${E(c)}`);for(let e of O(l.children,i)){if(r.length>=n)return;if(e.length===1){s(e[0],o+1);continue}a+=e.length;let t=e.reduce((e,t)=>e+w(t),0);r.push(`${` `.repeat(o+1)}${C(e[0])} x${e.length}${t>0?` (+${t} below)`:``}`)}};for(let t of e)s(t,0);return{lines:r,shown:a,total:o}}function A(e,t,n){let r=[];for(let i=e.byId.get(t.ownerId);i&&r.length<n;i=e.byId.get(i.ownerId))r.push(i.name);return r}function j(e,t){let n=A(e,t,2);return`${C(t)}${n.length>0?` in ${n.join(` < `)}`:``}`}function M(e,t,n){let r=t.toLowerCase();return[...e.byId.values()].filter(e=>n?e.name===t:e.name.toLowerCase().includes(r))}const N=/^@c(\d+)$/;function P(e){let t=N.exec(e);return t?Number(t[1]):void 0}function F(t,n){let r=P(n);if(r!==void 0){let i=t.byId.get(r);if(!i)throw new e(`COMMAND_FAILED`,`No mounted component has ref ${n}.`,{reason:`element-not-found`,hint:`Refs change when components remount or the app reloads; run react-devtools find or tree again.`});return i}let a=M(t,n,!0),o=n.toLowerCase(),s=a.length>0?a:[...t.byId.values()].filter(e=>e.name.toLowerCase()===o);if(s.length===1)return s[0];if(s.length===0)throw new e(`COMMAND_FAILED`,`No mounted component is named ${n}.`,{hint:`Run react-devtools find <part of the name> to search.`});let c=s.slice(0,5).map(i).join(`, `),l=s.length>5?` and ${s.length-5} more`:``;throw new e(`INVALID_ARGS`,`${s.length} mounted components are named ${n}: ${c}${l}.`,{hint:`Pick one by ref, or run react-devtools find ${n} --exact to list them.`})}const I=[`tree`,`find`,`inspect`,`errors`];function L(e){return I.includes(e)}const R={tree:{usage:`tree`,positionals:1,options:[...d,`depth`,`limit`]},find:{usage:`find <Name>`,positionals:1,options:[...d,`exact`,`limit`]},inspect:{usage:`inspect <@ref|Name>`,positionals:1,options:d},errors:{usage:`errors`,positionals:0,options:[...d,`limit`]}};async function z(e){let t=await o(e,`tree`);if(!t.ok)throw a(t);return b(t)}async function B(e,t){let n=await o(e,`inspect`,t);if(!n.ok)throw a(n);return n.elements}function V(e){if(!e||`missing`in e)throw a({ok:!1,reason:`element-not-found`});if(`error`in e)throw a({ok:!1,reason:`inspect-failed`,detail:e.error});return e}function H(t,n){let r=t.positionals[0];if(!r)throw new e(`INVALID_ARGS`,`react-devtools ${n} needs an argument.`);return r}const U={tree:async(e,r)=>{let{app:a,tree:o,root:s}=await t(e,r,async(t,r)=>{let i=await z(t),a=e.positionals[0]?F(i,e.positionals[0]):void 0;return{app:n(r),tree:i,root:a}}),c=k(s?[s]:o.roots,e.depth??8,e.limit??60),l=`React tree ${s?`under ${i(s)} ${s.name}`:`in ${a}`}: ${c.total} components`,u=c.total-c.shown,d=u>0?[`+${u} components not shown (raise --depth or --limit, or run tree <@ref> on a branch)`]:[];return{text:[l,...c.lines,...d].join(`
|
|
3
3
|
`),data:{app:a,root:s?i(s):null,total:c.total,shown:c.shown,lines:c.lines}}},find:async(e,n)=>{let r=H(e,`find <Name>`),i=await t(e,n,async e=>await z(e)),a=M(i,r,e.exact),o=e.limit??20,s=a.slice(0,o),c=a.length===0?`No mounted component name ${e.exact?`is`:`contains`} ${JSON.stringify(r)}.`:`${a.length} mounted ${a.length===1?`component matches`:`components match`} ${JSON.stringify(r)}:`,l=a.length>s.length?[` +${a.length-s.length} more (--limit ${a.length})`]:[];return{text:[c,...s.map(e=>` ${j(i,e)}`),...l].join(`
|
|
4
4
|
`),data:{total:a.length,matches:s.map(e=>G(e))}}},inspect:async(e,n)=>{let r=H(e,`inspect <@ref|Name>`),{id:a,component:o}=await t(e,n,async e=>{let t=P(r)??F(await z(e),r).id;return{id:t,component:V((await B(e,[t]))[String(t)])}});return{text:y(a,o),data:{ref:i({id:a}),...o}}},errors:async(e,n)=>{let r=e.limit??10,{logged:a,inspected:o,logsTracked:s}=await t(e,n,async e=>{let t=await z(e),n=[...t.byId.values()].filter(e=>e.errors+e.warnings>0).sort((e,t)=>t.errors-e.errors||t.warnings-e.warnings),i=n.slice(0,r).map(e=>e.id);return{logged:n,inspected:i.length>0?await B(e,i):{},logsTracked:t.logsTracked}}),c=s?[]:[`Note: this app's React DevTools backend does not attribute every console error and warning to a component, so this list can be incomplete; check agent-device logs as well.`];if(a.length===0)return{text:[`No mounted component logged an error or warning while rendering.`,...c].join(`
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{yi as e}from"./sdk-batch.js";import{at as t}from"./sdk-contracts.js";import{n,o as r,r as i,s as a,t as o}from"./react-native-overlay.js";const s=/\b(logbox|redbox|reload js|copy stack|component stack|call stack|runtime error|open debugger to view warnings)\b/,c=[/\b[\w.$<>/-]+\.(?:tsx?|jsx?):\d+(?::\d+)?\b/,/\b[\w.$<>/-]+\.(?:tsx?|jsx?)\s+\(\d+:\d+\)/],l=new Set([`x`,`×`,`✕`,`✖`,`⨯`]);function u(e){if(d(e).detected)return[`Hint: React Native warning/error overlay detected. It overlays part of the app and should be handled before interacting.`,`Run: agent-device react-native dismiss-overlay`,`The command verifies the overlay is gone. Run agent-device snapshot -i afterward only when you need fresh refs for the next action.`].join(`
|
|
2
2
|
`)}function d(e){let t=f(e),n=t.detected?p(t):null;return{detected:t.detected,dismissNodes:t.dismissNodes,minimizeNodes:t.minimizeNodes,collapsedNodes:t.collapsedNodes,primaryAction:n}}function f(e){let t=e.map(m).join(`
|
|
3
|
-
`).toLowerCase(),r=D(e,x),o=D(e,a),s=D(e,i,T),c=D(e,b),l=g(t),u=_(t);return{dismissNodes:r,minimizeNodes:o,collapsedNodes:s,detected:y({text:t,hasReactNativeStackFrame:l,hasOverlayControl:v(t,r,o),hasControllessRedBoxText:u,collapsedNodes:s,collapsedEvidenceNodes:D(s,n),openDebuggerWarningNodes:c})}}function p(e){let t=O(e.dismissNodes);if(t)return j(t,M(t));let n=N(e.collapsedNodes.filter(E));return n?.rect?{action:`close-collapsed-banner`,point:R(n),rect:n.rect,ref:n.ref,label:B(n)}:null}function m(e){return[e.label,e.value,e.identifier,e.type,e.role].filter(Boolean).join(` `)}function h(e){return s.test(e)}function g(e){return c.some(t=>t.test(e))}function _(e){return/\buncaught\b/.test(e)&&/unable to download asset/.test(e)}function v(e,t,n){return t.length>0||n.length>0||/\b(reload js|copy stack)\b/.test(e)}function y(e){let t=e.hasReactNativeStackFrame||h(e.text);return e.collapsedEvidenceNodes.length>0||e.collapsedNodes.length>0&&t||e.openDebuggerWarningNodes.length>0||e.hasControllessRedBoxText||e.hasOverlayControl&&(h(e.text)||e.hasReactNativeStackFrame)}function b(e){return e.includes(`open debugger to view warnings`)||/^!,\s+open debugger\b/.test(e)}function x(e){return r(e)||S(e)||C(e)}function S(e){return/^close(?:\s*\([^)]*\))?$/i.test(e)}function C(e){return l.has(e)}function w(e){return/^!,\s+/.test(e)}function T(e){return!e.rect||e.rect.height<=180}function E(e){let t=B(e)?.trim().toLowerCase()??``;return(b(t)||w(t))&&o(e)}function D(e,t,n=()=>!0){let r=[];for(let i of e)i.ref&&n(i)&&[i.label,i.value,i.identifier].map(e=>e?.trim().toLowerCase()).filter(e=>!!e).some(e=>t(e))&&r.push(i);return r}function O(e){return P(e,A)}function k(e){let t=[e.type,e.role,e.subrole].join(` `).toLowerCase();return/\b(button|menuitem|link)\b/.test(t)}function A(
|
|
3
|
+
`).toLowerCase(),r=D(e,x),o=D(e,a),s=D(e,i,T),c=D(e,b),l=g(t),u=_(t);return{dismissNodes:r,minimizeNodes:o,collapsedNodes:s,detected:y({text:t,hasReactNativeStackFrame:l,hasOverlayControl:v(t,r,o),hasControllessRedBoxText:u,collapsedNodes:s,collapsedEvidenceNodes:D(s,n),openDebuggerWarningNodes:c})}}function p(e){let t=O(e.dismissNodes);if(t)return j(t,M(t));let n=N(e.collapsedNodes.filter(E));return n?.rect?{action:`close-collapsed-banner`,point:R(n),rect:n.rect,ref:n.ref,label:B(n)}:null}function m(e){return[e.label,e.value,e.identifier,e.type,e.role].filter(Boolean).join(` `)}function h(e){return s.test(e)}function g(e){return c.some(t=>t.test(e))}function _(e){return/\buncaught\b/.test(e)&&/unable to download asset/.test(e)}function v(e,t,n){return t.length>0||n.length>0||/\b(reload js|copy stack)\b/.test(e)}function y(e){let t=e.hasReactNativeStackFrame||h(e.text);return e.collapsedEvidenceNodes.length>0||e.collapsedNodes.length>0&&t||e.openDebuggerWarningNodes.length>0||e.hasControllessRedBoxText||e.hasOverlayControl&&(h(e.text)||e.hasReactNativeStackFrame)}function b(e){return e.includes(`open debugger to view warnings`)||/^!,\s+open debugger\b/.test(e)}function x(e){return r(e)||S(e)||C(e)}function S(e){return/^close(?:\s*\([^)]*\))?$/i.test(e)}function C(e){return l.has(e)}function w(e){return/^!,\s+/.test(e)}function T(e){return!e.rect||e.rect.height<=180}function E(e){let t=B(e)?.trim().toLowerCase()??``;return(b(t)||w(t))&&o(e)}function D(e,t,n=()=>!0){let r=[];for(let i of e)i.ref&&n(i)&&[i.label,i.value,i.identifier].map(e=>e?.trim().toLowerCase()).filter(e=>!!e).some(e=>t(e))&&r.push(i);return r}function O(e){return P(e,A)}function k(e){let t=[e.type,e.role,e.subrole].join(` `).toLowerCase();return/\b(button|menuitem|link)\b/.test(t)}function A(t){return[I(k(t)),I(t.hittable),-(t.rect?e(t.rect):1/0)]}function j(e,n){if(!e.rect)throw Error(`React Native overlay target node must have rect`);return{action:n,point:t(e.rect),rect:e.rect,ref:e.ref,label:B(e)}}function M(e){let t=B(e)?.trim().toLowerCase();return t&&r(t)?`dismiss`:`close`}function N(e){return P(e,F)}function P(e,t){let n=e.filter(e=>e.rect);return n.length===0?null:n.sort((e,n)=>L(t(n),t(e)))[0]??null}function F(e){return[I(e.hittable),e.rect?.width??0,e.rect?.y??0]}function I(e){return+(e===!0)}function L(e,t){for(let n=0;n<e.length;n+=1){let r=e[n]-t[n];if(r!==0)return r}return 0}function R(e){if(!e.rect)throw Error(`Collapsed React Native warning node must have rect`);let t=Math.min(e.rect.height,52),n=Math.min(36,Math.max(18,t*.45));return{x:Math.round(z(e.rect.x+e.rect.width-n,e.rect.x+1,e.rect.x+e.rect.width-1)),y:Math.round(e.rect.y+t/2)}}function z(e,t,n){return Math.min(n,Math.max(t,e))}function B(e){return e.label??e.value??e.identifier}export{u as n,d as t};
|
package/dist/src/react-native.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{p as e,s as t,z as n}from"./sdk-contracts.js";import{N as r}from"./sdk-batch-runner.js";import{r as i}from"./success-text.js";import{n as a}from"./catalog.js";import{a as o}from"./snapshot-runtime-capture-input.js";import{n as s}from"./touch-reference-frame.js";import{t as c}from"./snapshot-quality-verdict.js";import{t as l}from"./react-native-overlay2.js";import{o as u,u as d}from"./interaction-ref-policy.js";import{captureSnapshotForSession as f}from"./interaction.js";import{n as p,t as m}from"./touch-runtime2.js";async function h(r){r=d(r);let{req:i,sessionStore:o}=r;if(i.command!==a.reactNative)return null;let s=g(i.positionals??[]);if(!s.ok)return s.response;let u=r.sessionRef?o.requireCurrent(r.sessionRef):void 0;if(!u)return e();let m=await p({device:u.device,command:`press`,requiresCapture:!1,inspectFacts:r.inspectFacts,platformServices:r.platformServices,bindDevice:r.bindDevice,unavailableResponse:e=>t(`UNSUPPORTED_OPERATION`,`react-native dismiss-overlay is not supported on this device`,void 0,e.hint?{hint:e.hint}:void 0)});if(!m.ok)return m.response;try{let e=await f(r.sessionRef,i.flags,o,r.contextFromFlags,{interactiveOnly:!0});if(c(e.snapshotQuality))return v(e.snapshotQuality);let t=l(e.nodes),n=t.primaryAction;return n?await y(r,u,e,n,m.runtime):_(t.detected)}catch(e){return{ok:!1,error:n(e)}}}function g(e){return e.length===1&&e[0]===`dismiss-overlay`?{ok:!0}:{ok:!1,response:t(`INVALID_ARGS`,`react-native supports only: dismiss-overlay`)}}function _(e){return e?t(`COMMAND_FAILED`,`React Native overlay detected, but no safe dismiss target was found`,{hint:`Use screenshot --overlay-refs for visual evidence and report the overlay instead of pressing the warning body.`}):{ok:!0,data:{action:`dismiss-overlay`,detected:!1,dismissed:!1,...i(`No React Native overlay detected`)}}}function v(e){return t(`COMMAND_FAILED`,`React Native overlay state could not be determined because the accessibility tree is unreadable`,{reason:e.reason,hint:`The snapshot quality verdict is sparse. Use screenshot as visual truth; if an overlay is visible, report it or navigate with coordinates, then retry snapshot or dismiss-overlay on a readable screen.`})}async function y(e,n,a,c,l){let{req:d,sessionStore:f}=e,p=e.contextFromFlags(d.flags,n.appBundleId,n.trace?.outPath),h=m(l,p).tapPoint;if(!h)return t(`UNSUPPORTED_OPERATION`,`react-native dismiss-overlay is not supported on this device`);let g=Date.now();o(n);let _=await h(c.point),v=Date.now(),y=await b(e),S=r({...s(a.nodes),..._,action:`dismiss-overlay`,overlayAction:c.action,x:c.point.x,y:c.point.y,ref:c.ref,label:c.label,warning:c.warning,dismissed:!0,verified:y.verified,verificationRequired:!y.verified,verificationWarning:y.verificationWarning,nextCommand:y.nextCommand,...i(x(y))});return u({ref:e.sessionRef,sessionStore:f,command:d.command,positionals:d.positionals??[],flags:d.flags,result:S,responseData:S,actionStartedAt:g,actionFinishedAt:v})}async function b(e){let{req:t,sessionStore:n}=e,r=await f(e.sessionRef,t.flags,n,e.contextFromFlags,{interactiveOnly:!0});return c(r.snapshotQuality)?{verified:!1,verificationWarning:`React Native overlay dismissal could not be verified because the post-dismiss accessibility tree is unreadable. Use screenshot as visual truth.`,nextCommand:`agent-device screenshot`}:l(r.nodes).detected?{verified:!1,verificationWarning:`React Native overlay is still detected after dismissal. Use screenshot --overlay-refs for visual evidence and report the overlay instead of pressing the warning body.`,nextCommand:`agent-device screenshot --overlay-refs`}:{verified:!0}}function x(e){return e.verified?`React Native overlay dismiss action sent and verified gone`:`React Native overlay dismiss action sent, but verification still detects an overlay`}export{h as handleReactNativeCommands};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{P as e}from"./sdk-contracts.js";import{pt as t}from"./sdk-io.js";import"./file.js";import{r as n}from"./session-paths.js";import{a as r,c as i,i as a,l as o,m as s,n as c,r as l,s as u,t as d,u as f}from"./react-devtools-connection.js";import p from"node:fs";import m from"node:path";const ee=new Set([`ActivityIndicator`,`CellRenderer`,`FlatList`,`Image`,`ImageBackground`,`InternalTextInput`,`KeyboardAvoidingView`,`Modal`,`Pressable`,`PressabilityDebugView`,`RefreshControl`,`SafeAreaView`,`ScrollView`,`SectionList`,`Switch`,`Text`,`TextInput`,`TouchableHighlight`,`TouchableOpacity`,`TouchableWithoutFeedback`,`View`,`VirtualizedList`,`VirtualizedListCellContextProvider`,`VirtualizedSectionList`]);function te(e){let t=s(e);return t.wrappers.includes(`Animated`)?{...t,name:e}:t}function h(e){let{name:t,wrappers:n}=s(e);return ee.has(t)||n.includes(`Animated`)}function g(e){return`${e.name}\0${e.kind}`}function _(e,t){return e.name===t.name&&e.kind===t.kind}function v(e,t){return e.elements[String(t)]}function y(e){let{name:t,wrappers:n}=te(e[0]);return{name:t,kind:n.includes(`Memo`)?`memo`:f(e[1])}}function b(e,t){let n=new Map;for(let r of t){let t=v(e,r);if(!t)continue;let i=y(t);n.set(g(i),i)}return[...n.values()]}function x(e,t){return v(e,t)?.[3]||void 0}function S(e,t){return(t??[]).map(t=>e.keys[t]??`#${t}`)}function C(e,t,n=1){e[t]=(e[t]??0)+n}function*w(e,t){for(let n=0;n+2<t.fibers.length;n+=3){let r=t.fibers[n],i=v(e,r);!i||!Object.hasOwn(o,i[1])||(yield{...y(i),id:r,actualMs:t.fibers[n+1],selfMs:t.fibers[n+2],causes:ne(t,r)})}}function ne(e,t){if(e.changes===null)return[];let n=e.changes[String(t)];if(n===void 0)return[`parent`];if(n===1)return[`mount`];let[r,i,a,o]=n,s=[];return i?.length&&s.push(`props`),a?.length&&s.push(`state`),(o?.length||r&2)&&s.push(`hooks`),r&1&&s.push(`context`),s.length>0?s:[`parent`]}function re(e){return{name:e.name,kind:e.kind,instances:0,renders:0,selfMs:0,maxSelfMs:0,causes:{mount:0,props:0,state:0,hooks:0,context:0,parent:0},changedProps:{},changedState:{},changedHooks:{},owners:{},propKinds:{},costliestCommits:[],ids:new Set,recentIds:[],commitCosts:new Map}}function ie(e,t,n,r,i){e.ids.add(t.id),e.recentIds=[...e.recentIds.filter(e=>e!==t.id),t.id].slice(-3),e.renders+=1,e.selfMs+=t.selfMs,e.maxSelfMs=Math.max(e.maxSelfMs,t.selfMs),e.commitCosts.set(i,(e.commitCosts.get(i)??0)+t.selfMs);for(let n of t.causes)e.causes[n]+=1;let a=r.changes?.[String(t.id)];if(Array.isArray(a)){for(let t of S(n,a[1]))C(e.changedProps,t);for(let t of S(n,a[2]))C(e.changedState,t);for(let t of a[3]??[])C(e.changedHooks,String(t))}let o=v(n,t.id)?.[2],s=o?v(n,o):void 0;s&&C(e.owners,y(s).name)}function T(e){let t=new Map;e.commits.forEach((n,r)=>{for(let i of w(e,n)){let a=g(i),o=t.get(a);o||(o=re(i),t.set(a,o)),ie(o,i,e,n,r)}});for(let e of t.values())e.instances=e.ids.size,e.costliestCommits=[...e.commitCosts.entries()].sort((e,t)=>t[1]-e[1]).slice(0,5).map(([e,t])=>({index:e,selfMs:t}));return t}function ae(e){let t=[...T(D(e)).values()].filter(e=>e.causes.props>0&&Object.keys(e.changedProps).length>0).sort((e,t)=>t.selfMs-e.selfMs).slice(0,8),n={};for(let e of t)for(let t of e.recentIds)n[String(t)]=Object.keys(e.changedProps);return n}function oe(e){let t=e.commits[0]?.timestamp??0;return e.commits.map((n,r)=>{let i=new Map,a=0,o=0;for(let t of w(e,n)){a+=1,t.causes.includes(`mount`)&&(o+=1);let e=g(t),n=i.get(e)??{name:t.name,kind:t.kind,instances:0,selfMs:0,actualMs:0,causes:[]};n.instances+=1,n.selfMs+=t.selfMs,n.actualMs+=t.actualMs;for(let e of t.causes)n.causes.includes(e)||n.causes.push(e);i.set(e,n)}return{index:r,atMs:Math.round(n.timestamp-t),durationMs:n.duration,rendered:a,mounts:o,updaters:b(e,n.updaters),components:[...i.values()].sort((e,t)=>t.selfMs-e.selfMs)}})}const E=e=>`${e.toFixed(e>=10?0:1)}ms`;function D(e){return{...e,commits:[...e.commits].sort((e,t)=>e.timestamp-t.timestamp)}}function se(e,t){let n={},r=new Set;for(let i of e)for(let[e,a]of Object.entries(t[String(i)]??{}))n[e]!==void 0&&n[e]!==a?r.add(e):n[e]=a;for(let e of r)delete n[e];return n}function ce(e,t={}){let n=T(e);for(let e of n.values())e.propKinds=se(e.ids,t);return{components:[...n.values()].map(({ids:e,recentIds:t,commitCosts:n,...r})=>r).sort((e,t)=>t.selfMs-e.selfMs),commits:oe(e)}}function O(e,t){return Object.entries(e).filter(([,e])=>e>=t).sort((e,t)=>t[1]-e[1]).map(([e])=>e)}function k(e){return O(e.owners,1)[0]}function A(e,t){return e.renders===0?0:e.selfMs*t/e.renders}const j=E;function M(e){return{component:e.name,componentKind:e.kind}}function N(e,t){return e.componentKind!==void 0&&_({name:e.component,kind:e.componentKind},t)}function P(e,t){return`${e} ${t}${e===1?``:`s`}`}function F(e){return e.instances>1?` across ${e.instances} instances`:``}function le(e){let t=e.selfMs/e.renders;return e.selfMs<32||t<4&&e.maxSelfMs<16||e.instances>20&&t<4?null:{kind:`slow-render`,...M(e),costMs:e.selfMs,evidence:`${j(t)} per render (max ${j(e.maxSelfMs)}), ${P(e.renders,`render`)}${F(e)}`,fix:`memoize or move the expensive work out of render`}}const ue=new Set([`boolean`,`number`,`string`,`null`,`undefined`,`bigint`,`symbol`]);function de(e){let t=e.renders-e.causes.mount;if(e.kind!==`memo`||t<10||e.causes.props<t*.5)return null;let n=O(e.changedProps,Math.ceil(e.causes.props*.8)),r=(n.length>0?n:O(e.changedProps,1).slice(0,3)).filter(t=>!ue.has(e.propKinds[t]??``));if(r.length===0)return null;let i=k(e),a=i?` from ${i}`:``,o=i?` in ${i}`:``,s=r.filter(t=>e.propKinds[t]!==void 0),c=t=>`${e.changedProps[t]}x`;return s.length===0?{kind:`memo-defeated`,...M(e),costMs:A(e,e.causes.props),evidence:`memo bypassed on ${e.causes.props}/${t} updates; changed ${r.map(e=>`${e} ${c(e)}`).join(`, `)}${a} (value kinds not inspected)`,fix:`check whether those props are recreated on each render${o}; stabilize them with useCallback/useMemo`}:{kind:`memo-defeated`,...M(e),costMs:A(e,e.causes.props),evidence:`memo bypassed on ${e.causes.props}/${t} updates; new ${s.map(t=>`${t} (${e.propKinds[t]}) ${c(t)}`).join(`, `)}${a}`,fix:`wrap those props in useCallback/useMemo${o}`}}function fe(e,t){let n=e.renders-e.causes.mount;return n<10||e.causes.context<n*.5?null:{kind:`context-cascade`,...M(e),costMs:A(e,e.causes.context),evidence:`${e.causes.context} context-driven renders${F(e)}${t.length?` after updates in ${t.join(`, `)}`:``}`,fix:`split the context so consumers subscribe only to what they read, or memoize the provider value`}}function pe(e){let t=e.renders-e.causes.mount;if(e.kind===`memo`||t<10||e.causes.parent<t*.5)return null;let n=k(e);return{kind:`parent-cascade`,...M(e),costMs:A(e,e.causes.parent),evidence:`${e.causes.parent}/${t} re-renders with unchanged props, state, and context${n?` when ${n} rendered`:``}${F(e)}`,fix:`wrap ${e.name} in React.memo or move state below ${n??`its parent`}`}}function me(e,t){let n=new Map;return e.commits.forEach((r,i)=>{let a=new Map,o=0;for(let t of w(e,r)){if(!t.causes.includes(`mount`)||(o+=1,h(t.name)))continue;let e=g(t),n=a.get(e)??{component:t,count:0,actualMs:0};n.count+=1,n.actualMs+=t.actualMs,a.set(e,n)}let s=t[i].durationMs;for(let[e,t]of a){if(t.count<200)continue;let r=Math.min(t.actualMs,s),a=n.get(e)??{component:t.component,mounts:[]};a.mounts.push({index:i,count:t.count,costMs:r,durationMs:s,mounted:o}),n.set(e,a)}}),[...n.values()].map(({component:e,mounts:t})=>{let n=t.reduce((e,t)=>t.costMs>e.costMs?t:e),r=t.reduce((e,t)=>e+t.costMs,0),i=t.length>1?`; ${t.length} such commits, ${j(r)} in all`:``;return{kind:`eager-mount`,...M(e),costMs:r,evidence:`${n.count} instances mounted at once in commit #${n.index}, ${j(n.costMs)} of its ${j(n.durationMs)} (${n.mounted} components mounted)${i}`,fix:`virtualize the list (FlatList/FlashList)`}})}function he(e,t,n){let r=new Set(t.fibers.filter((e,t)=>t%3==0)),i=new Set(t.updaters);return b(e,n.updaters.filter(e=>r.has(e)&&!i.has(e))).filter(e=>!h(e.name))}function I(e){let t=new Map;for(let n=1;n<e.commits.length;n+=1){let r=e.commits[n-1],i=e.commits[n];if(!(i.timestamp-i.duration-r.timestamp>16))for(let n of he(e,r,i)){let e=g(n),r=t.get(e)??{component:n,count:0,costMs:0};r.count+=1,r.costMs+=i.duration,t.set(e,r)}}return[...t.values()].filter(e=>e.count>=3).map(e=>({kind:`effect-chain`,...M(e.component),costMs:e.costMs,evidence:`${P(e.count,`follow-up commit`)} it triggered right after rendering, likely state set in an effect (${j(e.costMs)})`,fix:`if an effect copies derived state, compute it during render (useMemo) instead`}))}function L(e){let t=new Map;e.commits.forEach((n,r)=>{for(let i of b(e,n.updaters)){let e=g(i),n=t.get(e)??{component:i,indexes:[]};n.indexes.push(r),t.set(e,n)}});let n=[];for(let{component:r,indexes:i}of t.values()){if(i.length<20||h(r.name))continue;let t=e.commits[i[0]].timestamp,a=e.commits[i.at(-1)].timestamp,o=Math.max((a-t)/1e3,.001),s=(i.length-1)/o;if(s<20)continue;let c=i.reduce((t,n)=>t+e.commits[n].duration,0);n.push({kind:`render-storm`,...M(r),costMs:c,evidence:`${i.length} commits in ${o.toFixed(1)}s (${Math.round(s)}/s, ${j(c)} rendering)`,fix:`throttle the updates or animate outside React state (Animated/Reanimated)`})}return n}const R=new Set([`slow-render`,`effect-chain`,`render-storm`]);function ge(e){let t=new Map;for(let n of e){if(n.componentKind===void 0)continue;let e=g({name:n.component,kind:n.componentKind});R.has(n.kind)?t.has(e)||t.set(e,`self`):t.set(e,`subtree`)}return t}function _e(e,t,n){let r=[...w(e,t)],i=new Set(r.filter(e=>n.get(g(e))===`subtree`).map(e=>e.id)),a=t=>{let n=new Set;for(let r=x(e,t);r&&!n.has(r);r=x(e,r)){if(i.has(r))return!0;n.add(r)}return!1},o=0;for(let e of r){let t=n.get(g(e));!t||a(e.id)||(o+=t===`subtree`?e.actualMs:e.selfMs)}return o}function ve(e){let t=e.components.filter(t=>!h(t.name)&&t.actualMs>=e.durationMs*.8);return t.find(t=>e.updaters.some(e=>_(e,t)))??t.sort((e,t)=>e.actualMs-t.actualMs)[0]}function ye(e){let t=ve(e),n=e.components.slice(0,3).map(e=>`${e.name}${e.instances>1?` x${e.instances}`:``} ${j(e.selfMs)}`),r=e.mounts>0?` (${e.mounts} mounted)`:``,i=t&&!e.updaters.some(e=>_(e,t))?` inside ${t.name}`:``,a=e.updaters.length>0?` after ${e.updaters.map(e=>e.name).join(`, `)} updated`:``,o=t??e.updaters[0];return{kind:`slow-commit`,...o?M(o):{component:`#${e.index}`},costMs:e.durationMs,evidence:`commit #${e.index} took ${j(e.durationMs)} rendering ${e.rendered} components${r}${i}${a}; most time in ${n.join(`, `)}`,fix:`render less ${t?`under ${t.name} `:``}per update (memoize, virtualize, or defer)`}}function be(e,t,n){let r=ge(n);return t.filter(e=>e.durationMs>=48).filter(t=>_e(e,e.commits[t.index],r)<t.durationMs*.5).sort((e,t)=>t.durationMs-e.durationMs).slice(0,2).map(ye)}function xe(e,t){let n={};for(let r of e.commits){let i=!1;for(let n of w(e,r))if(_(n,t)&&n.causes.includes(`context`)){i=!0;break}if(i)for(let t of b(e,r.updaters))C(n,t.name)}return O(n,1).slice(0,2)}function z(e,t={},n=[]){let r=D(e),{components:i,commits:a}=ce(r,t),o=a.filter(e=>e.durationMs>16),s=a.reduce((e,t)=>e&&e.durationMs>=t.durationMs?e:t,null),c=[];for(let e of i){if(h(e.name))continue;let t=[de(e),fe(e,e.causes.context>0?xe(r,e):[]),pe(e)].filter(e=>e!==null),n=t.length===0||e.maxSelfMs>=16?le(e):null,i=n?[n,...t]:t;c.push(...i)}c.push(...me(r,a)),c.push(...I(r)),c.push(...L(r)),c.push(...be(r,a,c));let l=a.reduce((e,t)=>e+t.durationMs,0),u=Math.max(2,l*.03),d=c.filter(e=>e.costMs>=u).sort((e,t)=>t.costMs-e.costMs);return{wallMs:r.stoppedAt-r.startedAt,commitCount:a.length,renderMs:l,slowCommitCount:o.length,worstCommit:s?{index:s.index,durationMs:s.durationMs}:null,naming:r.naming,notes:n,components:i,commits:a,findings:d}}const B=E,V=e=>`${(e/1e3).toFixed(1)}s`,H=V;function Se(e){let t=[`React profile ${H(e.wallMs)}: ${e.commitCount} commits, ${B(e.renderMs)} rendering`];return e.worstCommit&&e.slowCommitCount>0&&t.push(`${e.slowCommitCount} over 16ms (worst #${e.worstCommit.index} ${B(e.worstCommit.durationMs)})`),t.join(`, `)}function Ce(e,t=5){let n=e.notes.map(e=>`Note: ${e}`);if(e.commitCount===0)return u([`React profile: no commits recorded. Start profiling, then perform the interaction before stopping.`,...n]);let r=[Se(e)],i=e.findings.slice(0,t);if(i.length===0)r.push(`No render problems above thresholds.`);else{i.forEach((e,t)=>{r.push(`${t+1}. ${e.kind} ${e.component}: ${e.evidence} -> ${e.fix}`)});let t=e.findings.length-i.length;t>0&&r.push(`+${t} smaller findings (--limit ${e.findings.length})`)}return r.push(...n),e.naming===`lookup`&&r.push(`Note: component names came from mounted elements; components unmounted during the profile are left out.`),r.push(`More: profile report [Component] | profile commit [N]`),u(r)}function U(e){return Object.entries(e).filter(([,e])=>e>0).sort((e,t)=>t[1]-e[1]).map(([e,t])=>`${e} ${t}`).join(`, `)||`unrecorded`}function W(e,t){return e<t?[` +${t-e} more (--limit ${t})`]:[]}function G(e,t=4){return Object.entries(e).sort((e,t)=>t[1]-e[1]).slice(0,t).map(([e,t])=>`${e} ${t}`).join(`, `)}function K(e){let t=e.renders>0?e.selfMs/e.renders:0,n=e.instances>1?` ${e.instances} inst`:``;return`${e.name} [${e.kind}] self ${B(e.selfMs)} avg ${B(t)} max ${B(e.maxSelfMs)} renders ${e.renders}${n}`}function we(e,t){if(e.components.length===0)return`No component renders recorded.`;let n=e.components.slice(0,t);return u([`Components by self time:`,...n.map(e=>{let t=G(e.changedProps);return` ${K(e)}: ${U(e.causes)}${t?`; changed props ${t}`:``}`}),...W(n.length,e.components.length)])}function Te(e,t){let n=e.components.filter(e=>e.name===t);return n.length>0?n:e.components.filter(e=>e.name.toLowerCase()===t.toLowerCase())}function Ee(e,t){let n=[K(t),`causes: ${U(t.causes)}`],r=Object.entries(t.changedProps).sort((e,t)=>t[1]-e[1]).map(([e,n])=>`${e} ${n}${t.propKinds[e]?` (${t.propKinds[e]})`:``}`);r.length>0&&n.push(`changed props: ${r.join(`, `)}`);let i=G(t.changedState,8);i&&n.push(`changed state: ${i}`);let a=G(t.changedHooks,8);a&&n.push(`changed hooks (by index): ${a}`);let o=G(t.owners,3);if(o&&n.push(`rendered by: ${o}`),t.costliestCommits.length>0){let r=t.costliestCommits.map(({index:t,selfMs:n})=>{let r=e.commits[t];return`#${t} ${B(n)}${r?` of ${B(r.durationMs)}`:``}`});n.push(`its costliest commits (self time of commit duration): ${r.join(`, `)}`)}return n}function De(e,t){return u(t.flatMap(t=>[...Ee(e,t),...e.findings.filter(e=>N(e,t)).map(e=>`finding ${e.kind}: ${e.evidence} -> ${e.fix}`)]))}function q(e){let t=e.updaters.length>0?` <- ${e.updaters.map(e=>e.name).join(`, `)}`:``,n=e.mounts>0?` (${e.mounts} mounted)`:``;return`#${e.index} +${H(e.atMs)} ${B(e.durationMs)} ${e.rendered} rendered${n}${t}`}function J(e,t){return e.commits.length<=t?e.commits:[...e.commits].sort((e,t)=>t.durationMs-e.durationMs).slice(0,t).sort((e,t)=>e.index-t.index)}function Oe(e,t){if(e.commits.length===0)return`No commits recorded.`;let n=J(e,t),r=n.length<e.commits.length?`Commits (${n.length} slowest of ${e.commits.length}, --limit ${e.commits.length} for all):`:`Commits:`;return u([r,...n.map(e=>` ${q(e)}`)])}function ke(e,t){let n=[q(e)],r=e.components.slice(0,t);for(let e of r){let t=e.instances>1?` x${e.instances}`:``;n.push(` ${e.name} [${e.kind}]${t} self ${B(e.selfMs)} ${e.causes.join(`+`)||`unrecorded`}`)}return n.push(...W(r.length,e.components.length)),u(n)}const Y=[`start`,`stop`,`report`,`commit`];function Ae(e){return Y.includes(e)}function X(e,t){switch(e){case`start`:return{usage:`profile start`,positionals:0,options:d};case`stop`:return{usage:`profile stop`,positionals:0,options:[...d,`limit`]};case`report`:return t===void 0?{usage:`profile report`,positionals:1,options:[`limit`]}:{usage:`profile report <Component>`,positionals:1,options:[]};case`commit`:return{usage:`profile commit`,positionals:1,options:[`limit`]}}}function je(t){let[n,...r]=t;if(!Ae(n))throw new e(`INVALID_ARGS`,`Unknown react-devtools profile command: ${n??`(none)`}.`,{hint:`Use one of: ${Y.join(`, `)}.`});let i=l(r,e=>X(n,e[0]));return{...i,subcommand:n,target:i.positionals[0]}}function Z(e){return m.join(e.stateDir,`react-profiles`,`${n(e.session)}.json`)}function Q(e,n){let r=Z(e);return p.mkdirSync(m.dirname(r),{recursive:!0}),t({destination:r,contents:`${JSON.stringify(n)}\n`}),r}function Me(e){return e?.version===2&&Array.isArray(e.profile?.commits)&&typeof e.profile.elements==`object`&&Array.isArray(e.notes)}function $(t){let n;try{n=p.readFileSync(Z(t),`utf8`)}catch{throw new e(`COMMAND_FAILED`,`No React profile saved for session ${t.session}.`,{hint:`Run react-devtools profile start, perform the interaction, then react-devtools profile stop.`})}let r;try{r=JSON.parse(n)}catch{r=void 0}if(!Me(r))throw new e(`COMMAND_FAILED`,`The saved React profile has an unsupported format.`,{hint:`Record a new profile with react-devtools profile start and stop.`});return z(r.profile,r.propKinds,r.notes)}const Ne=e=>V(Math.max(0,e));async function Pe(e,t){return await r(e,t,async(e,t)=>{let n=await c(e,`start`),r=i(t);if(!n.ok&&n.reason===`already-profiling`)return{app:r,alreadyProfiling:!0,message:`Already profiling ${r} for ${Ne(n.elapsedMs??0)}; run react-devtools profile stop to read it.`};if(!n.ok)throw a(n);return{app:r,attach:n.attach,message:`Profiling React renders in ${r}. Perform the interaction, then run react-devtools profile stop.`}})}async function Fe(e,t){let n=ae(t);if(Object.keys(n).length===0)return{propKinds:{},notes:[]};try{return{propKinds:await c(e,`describeProps`,n),notes:[]}}catch(e){return{propKinds:{},notes:[`Changed prop values could not be inspected: ${e instanceof Error?e.message:String(e)}`]}}}async function Ie(e,t){return await r(e,t,async(e,n)=>{let r=await c(e,`stop`);if(!r.ok)throw a(r);let{ok:o,failures:s,...l}=r,u=i(n),d={version:2,savedAt:new Date().toISOString(),appId:u,deviceName:n.deviceName,profile:l,propKinds:{},notes:s.map(e=>`A React renderer's profile could not be read: ${e}`)};Q(t,{...d,notes:[...d.notes,`Changed prop values have not been inspected; collection may have been interrupted.`]});let f=await Fe(e,l);return d.propKinds=f.propKinds,d.notes.push(...f.notes),Q(t,d),{appId:u,analysis:z(l,d.propKinds,d.notes)}})}function Le(t,n){let r=Te(t,n);if(r.length===0)throw new e(`COMMAND_FAILED`,`No renders of ${n} in the saved profile.`,{hint:`Use a name that react-devtools profile report lists.`});return r}function Re(t,n){let r=n.replace(/^#/,``),i=/^\d+$/.test(r)?t.commits[Number(r)]:void 0;if(!i)throw new e(`INVALID_ARGS`,`No commit ${n} in the saved profile.`,{hint:`Use a commit index from 0 to ${Math.max(t.commits.length-1,0)}.`});return i}const ze={start:async(e,t)=>{let n=await Pe(e,t);return{text:n.message,data:n}},stop:async(e,t)=>{let{appId:n,analysis:r}=await Ie(e,t);return{text:Ce(r,e.limit??5),data:{appId:n,wallMs:r.wallMs,commitCount:r.commitCount,renderMs:r.renderMs,slowCommitCount:r.slowCommitCount,worstCommit:r.worstCommit,findings:r.findings.slice(0,e.limit??r.findings.length),notes:r.notes,savedTo:Z(t)}}},report:async(e,t)=>{let n=$(t);if(e.target===void 0){let t=e.limit??10;return{text:we(n,t),data:{components:n.components.slice(0,t)}}}let r=Le(n,e.target);return{text:De(n,r),data:{components:r,findings:n.findings.filter(e=>r.some(t=>N(e,t)))}}},commit:async(e,t)=>{let n=$(t);if(e.target===void 0){let t=e.limit??20;return{text:Oe(n,t),data:{commits:J(n,t)}}}let r=Re(n,e.target),i=e.limit??10;return{text:ke(r,i),data:{...r,components:r.components.slice(0,i)}}}};async function Be(e,t){let n=je(e);return await ze[n.subcommand](n,t)}export{Be as runReactProfileCommand};
|
|
1
|
+
import{_ as e}from"./sdk-contracts.js";import{gt as t}from"./sdk-io.js";import"./file.js";import{r as n}from"./session-paths.js";import{a as r,c as i,i as a,l as o,m as s,n as c,r as l,s as u,t as d,u as f}from"./react-devtools-connection.js";import p from"node:fs";import m from"node:path";const ee=new Set([`ActivityIndicator`,`CellRenderer`,`FlatList`,`Image`,`ImageBackground`,`InternalTextInput`,`KeyboardAvoidingView`,`Modal`,`Pressable`,`PressabilityDebugView`,`RefreshControl`,`SafeAreaView`,`ScrollView`,`SectionList`,`Switch`,`Text`,`TextInput`,`TouchableHighlight`,`TouchableOpacity`,`TouchableWithoutFeedback`,`View`,`VirtualizedList`,`VirtualizedListCellContextProvider`,`VirtualizedSectionList`]);function te(e){let t=s(e);return t.wrappers.includes(`Animated`)?{...t,name:e}:t}function h(e){let{name:t,wrappers:n}=s(e);return ee.has(t)||n.includes(`Animated`)}function g(e){return`${e.name}\0${e.kind}`}function _(e,t){return e.name===t.name&&e.kind===t.kind}function v(e,t){return e.elements[String(t)]}function y(e){let{name:t,wrappers:n}=te(e[0]);return{name:t,kind:n.includes(`Memo`)?`memo`:f(e[1])}}function b(e,t){let n=new Map;for(let r of t){let t=v(e,r);if(!t)continue;let i=y(t);n.set(g(i),i)}return[...n.values()]}function x(e,t){return v(e,t)?.[3]||void 0}function S(e,t){return(t??[]).map(t=>e.keys[t]??`#${t}`)}function C(e,t,n=1){e[t]=(e[t]??0)+n}function*w(e,t){for(let n=0;n+2<t.fibers.length;n+=3){let r=t.fibers[n],i=v(e,r);!i||!Object.hasOwn(o,i[1])||(yield{...y(i),id:r,actualMs:t.fibers[n+1],selfMs:t.fibers[n+2],causes:ne(t,r)})}}function ne(e,t){if(e.changes===null)return[];let n=e.changes[String(t)];if(n===void 0)return[`parent`];if(n===1)return[`mount`];let[r,i,a,o]=n,s=[];return i?.length&&s.push(`props`),a?.length&&s.push(`state`),(o?.length||r&2)&&s.push(`hooks`),r&1&&s.push(`context`),s.length>0?s:[`parent`]}function re(e){return{name:e.name,kind:e.kind,instances:0,renders:0,selfMs:0,maxSelfMs:0,causes:{mount:0,props:0,state:0,hooks:0,context:0,parent:0},changedProps:{},changedState:{},changedHooks:{},owners:{},propKinds:{},costliestCommits:[],ids:new Set,recentIds:[],commitCosts:new Map}}function ie(e,t,n,r,i){e.ids.add(t.id),e.recentIds=[...e.recentIds.filter(e=>e!==t.id),t.id].slice(-3),e.renders+=1,e.selfMs+=t.selfMs,e.maxSelfMs=Math.max(e.maxSelfMs,t.selfMs),e.commitCosts.set(i,(e.commitCosts.get(i)??0)+t.selfMs);for(let n of t.causes)e.causes[n]+=1;let a=r.changes?.[String(t.id)];if(Array.isArray(a)){for(let t of S(n,a[1]))C(e.changedProps,t);for(let t of S(n,a[2]))C(e.changedState,t);for(let t of a[3]??[])C(e.changedHooks,String(t))}let o=v(n,t.id)?.[2],s=o?v(n,o):void 0;s&&C(e.owners,y(s).name)}function T(e){let t=new Map;e.commits.forEach((n,r)=>{for(let i of w(e,n)){let a=g(i),o=t.get(a);o||(o=re(i),t.set(a,o)),ie(o,i,e,n,r)}});for(let e of t.values())e.instances=e.ids.size,e.costliestCommits=[...e.commitCosts.entries()].sort((e,t)=>t[1]-e[1]).slice(0,5).map(([e,t])=>({index:e,selfMs:t}));return t}function ae(e){let t=[...T(D(e)).values()].filter(e=>e.causes.props>0&&Object.keys(e.changedProps).length>0).sort((e,t)=>t.selfMs-e.selfMs).slice(0,8),n={};for(let e of t)for(let t of e.recentIds)n[String(t)]=Object.keys(e.changedProps);return n}function oe(e){let t=e.commits[0]?.timestamp??0;return e.commits.map((n,r)=>{let i=new Map,a=0,o=0;for(let t of w(e,n)){a+=1,t.causes.includes(`mount`)&&(o+=1);let e=g(t),n=i.get(e)??{name:t.name,kind:t.kind,instances:0,selfMs:0,actualMs:0,causes:[]};n.instances+=1,n.selfMs+=t.selfMs,n.actualMs+=t.actualMs;for(let e of t.causes)n.causes.includes(e)||n.causes.push(e);i.set(e,n)}return{index:r,atMs:Math.round(n.timestamp-t),durationMs:n.duration,rendered:a,mounts:o,updaters:b(e,n.updaters),components:[...i.values()].sort((e,t)=>t.selfMs-e.selfMs)}})}const E=e=>`${e.toFixed(e>=10?0:1)}ms`;function D(e){return{...e,commits:[...e.commits].sort((e,t)=>e.timestamp-t.timestamp)}}function se(e,t){let n={},r=new Set;for(let i of e)for(let[e,a]of Object.entries(t[String(i)]??{}))n[e]!==void 0&&n[e]!==a?r.add(e):n[e]=a;for(let e of r)delete n[e];return n}function ce(e,t={}){let n=T(e);for(let e of n.values())e.propKinds=se(e.ids,t);return{components:[...n.values()].map(({ids:e,recentIds:t,commitCosts:n,...r})=>r).sort((e,t)=>t.selfMs-e.selfMs),commits:oe(e)}}function O(e,t){return Object.entries(e).filter(([,e])=>e>=t).sort((e,t)=>t[1]-e[1]).map(([e])=>e)}function k(e){return O(e.owners,1)[0]}function A(e,t){return e.renders===0?0:e.selfMs*t/e.renders}const j=E;function M(e){return{component:e.name,componentKind:e.kind}}function N(e,t){return e.componentKind!==void 0&&_({name:e.component,kind:e.componentKind},t)}function P(e,t){return`${e} ${t}${e===1?``:`s`}`}function F(e){return e.instances>1?` across ${e.instances} instances`:``}function le(e){let t=e.selfMs/e.renders;return e.selfMs<32||t<4&&e.maxSelfMs<16||e.instances>20&&t<4?null:{kind:`slow-render`,...M(e),costMs:e.selfMs,evidence:`${j(t)} per render (max ${j(e.maxSelfMs)}), ${P(e.renders,`render`)}${F(e)}`,fix:`memoize or move the expensive work out of render`}}const ue=new Set([`boolean`,`number`,`string`,`null`,`undefined`,`bigint`,`symbol`]);function de(e){let t=e.renders-e.causes.mount;if(e.kind!==`memo`||t<10||e.causes.props<t*.5)return null;let n=O(e.changedProps,Math.ceil(e.causes.props*.8)),r=(n.length>0?n:O(e.changedProps,1).slice(0,3)).filter(t=>!ue.has(e.propKinds[t]??``));if(r.length===0)return null;let i=k(e),a=i?` from ${i}`:``,o=i?` in ${i}`:``,s=r.filter(t=>e.propKinds[t]!==void 0),c=t=>`${e.changedProps[t]}x`;return s.length===0?{kind:`memo-defeated`,...M(e),costMs:A(e,e.causes.props),evidence:`memo bypassed on ${e.causes.props}/${t} updates; changed ${r.map(e=>`${e} ${c(e)}`).join(`, `)}${a} (value kinds not inspected)`,fix:`check whether those props are recreated on each render${o}; stabilize them with useCallback/useMemo`}:{kind:`memo-defeated`,...M(e),costMs:A(e,e.causes.props),evidence:`memo bypassed on ${e.causes.props}/${t} updates; new ${s.map(t=>`${t} (${e.propKinds[t]}) ${c(t)}`).join(`, `)}${a}`,fix:`wrap those props in useCallback/useMemo${o}`}}function fe(e,t){let n=e.renders-e.causes.mount;return n<10||e.causes.context<n*.5?null:{kind:`context-cascade`,...M(e),costMs:A(e,e.causes.context),evidence:`${e.causes.context} context-driven renders${F(e)}${t.length?` after updates in ${t.join(`, `)}`:``}`,fix:`split the context so consumers subscribe only to what they read, or memoize the provider value`}}function pe(e){let t=e.renders-e.causes.mount;if(e.kind===`memo`||t<10||e.causes.parent<t*.5)return null;let n=k(e);return{kind:`parent-cascade`,...M(e),costMs:A(e,e.causes.parent),evidence:`${e.causes.parent}/${t} re-renders with unchanged props, state, and context${n?` when ${n} rendered`:``}${F(e)}`,fix:`wrap ${e.name} in React.memo or move state below ${n??`its parent`}`}}function me(e,t){let n=new Map;return e.commits.forEach((r,i)=>{let a=new Map,o=0;for(let t of w(e,r)){if(!t.causes.includes(`mount`)||(o+=1,h(t.name)))continue;let e=g(t),n=a.get(e)??{component:t,count:0,actualMs:0};n.count+=1,n.actualMs+=t.actualMs,a.set(e,n)}let s=t[i].durationMs;for(let[e,t]of a){if(t.count<200)continue;let r=Math.min(t.actualMs,s),a=n.get(e)??{component:t.component,mounts:[]};a.mounts.push({index:i,count:t.count,costMs:r,durationMs:s,mounted:o}),n.set(e,a)}}),[...n.values()].map(({component:e,mounts:t})=>{let n=t.reduce((e,t)=>t.costMs>e.costMs?t:e),r=t.reduce((e,t)=>e+t.costMs,0),i=t.length>1?`; ${t.length} such commits, ${j(r)} in all`:``;return{kind:`eager-mount`,...M(e),costMs:r,evidence:`${n.count} instances mounted at once in commit #${n.index}, ${j(n.costMs)} of its ${j(n.durationMs)} (${n.mounted} components mounted)${i}`,fix:`virtualize the list (FlatList/FlashList)`}})}function he(e,t,n){let r=new Set(t.fibers.filter((e,t)=>t%3==0)),i=new Set(t.updaters);return b(e,n.updaters.filter(e=>r.has(e)&&!i.has(e))).filter(e=>!h(e.name))}function I(e){let t=new Map;for(let n=1;n<e.commits.length;n+=1){let r=e.commits[n-1],i=e.commits[n];if(!(i.timestamp-i.duration-r.timestamp>16))for(let n of he(e,r,i)){let e=g(n),r=t.get(e)??{component:n,count:0,costMs:0};r.count+=1,r.costMs+=i.duration,t.set(e,r)}}return[...t.values()].filter(e=>e.count>=3).map(e=>({kind:`effect-chain`,...M(e.component),costMs:e.costMs,evidence:`${P(e.count,`follow-up commit`)} it triggered right after rendering, likely state set in an effect (${j(e.costMs)})`,fix:`if an effect copies derived state, compute it during render (useMemo) instead`}))}function L(e){let t=new Map;e.commits.forEach((n,r)=>{for(let i of b(e,n.updaters)){let e=g(i),n=t.get(e)??{component:i,indexes:[]};n.indexes.push(r),t.set(e,n)}});let n=[];for(let{component:r,indexes:i}of t.values()){if(i.length<20||h(r.name))continue;let t=e.commits[i[0]].timestamp,a=e.commits[i.at(-1)].timestamp,o=Math.max((a-t)/1e3,.001),s=(i.length-1)/o;if(s<20)continue;let c=i.reduce((t,n)=>t+e.commits[n].duration,0);n.push({kind:`render-storm`,...M(r),costMs:c,evidence:`${i.length} commits in ${o.toFixed(1)}s (${Math.round(s)}/s, ${j(c)} rendering)`,fix:`throttle the updates or animate outside React state (Animated/Reanimated)`})}return n}const R=new Set([`slow-render`,`effect-chain`,`render-storm`]);function ge(e){let t=new Map;for(let n of e){if(n.componentKind===void 0)continue;let e=g({name:n.component,kind:n.componentKind});R.has(n.kind)?t.has(e)||t.set(e,`self`):t.set(e,`subtree`)}return t}function _e(e,t,n){let r=[...w(e,t)],i=new Set(r.filter(e=>n.get(g(e))===`subtree`).map(e=>e.id)),a=t=>{let n=new Set;for(let r=x(e,t);r&&!n.has(r);r=x(e,r)){if(i.has(r))return!0;n.add(r)}return!1},o=0;for(let e of r){let t=n.get(g(e));!t||a(e.id)||(o+=t===`subtree`?e.actualMs:e.selfMs)}return o}function ve(e){let t=e.components.filter(t=>!h(t.name)&&t.actualMs>=e.durationMs*.8);return t.find(t=>e.updaters.some(e=>_(e,t)))??t.sort((e,t)=>e.actualMs-t.actualMs)[0]}function ye(e){let t=ve(e),n=e.components.slice(0,3).map(e=>`${e.name}${e.instances>1?` x${e.instances}`:``} ${j(e.selfMs)}`),r=e.mounts>0?` (${e.mounts} mounted)`:``,i=t&&!e.updaters.some(e=>_(e,t))?` inside ${t.name}`:``,a=e.updaters.length>0?` after ${e.updaters.map(e=>e.name).join(`, `)} updated`:``,o=t??e.updaters[0];return{kind:`slow-commit`,...o?M(o):{component:`#${e.index}`},costMs:e.durationMs,evidence:`commit #${e.index} took ${j(e.durationMs)} rendering ${e.rendered} components${r}${i}${a}; most time in ${n.join(`, `)}`,fix:`render less ${t?`under ${t.name} `:``}per update (memoize, virtualize, or defer)`}}function be(e,t,n){let r=ge(n);return t.filter(e=>e.durationMs>=48).filter(t=>_e(e,e.commits[t.index],r)<t.durationMs*.5).sort((e,t)=>t.durationMs-e.durationMs).slice(0,2).map(ye)}function xe(e,t){let n={};for(let r of e.commits){let i=!1;for(let n of w(e,r))if(_(n,t)&&n.causes.includes(`context`)){i=!0;break}if(i)for(let t of b(e,r.updaters))C(n,t.name)}return O(n,1).slice(0,2)}function z(e,t={},n=[]){let r=D(e),{components:i,commits:a}=ce(r,t),o=a.filter(e=>e.durationMs>16),s=a.reduce((e,t)=>e&&e.durationMs>=t.durationMs?e:t,null),c=[];for(let e of i){if(h(e.name))continue;let t=[de(e),fe(e,e.causes.context>0?xe(r,e):[]),pe(e)].filter(e=>e!==null),n=t.length===0||e.maxSelfMs>=16?le(e):null,i=n?[n,...t]:t;c.push(...i)}c.push(...me(r,a)),c.push(...I(r)),c.push(...L(r)),c.push(...be(r,a,c));let l=a.reduce((e,t)=>e+t.durationMs,0),u=Math.max(2,l*.03),d=c.filter(e=>e.costMs>=u).sort((e,t)=>t.costMs-e.costMs);return{wallMs:r.stoppedAt-r.startedAt,commitCount:a.length,renderMs:l,slowCommitCount:o.length,worstCommit:s?{index:s.index,durationMs:s.durationMs}:null,naming:r.naming,notes:n,components:i,commits:a,findings:d}}const B=E,V=e=>`${(e/1e3).toFixed(1)}s`,H=V;function Se(e){let t=[`React profile ${H(e.wallMs)}: ${e.commitCount} commits, ${B(e.renderMs)} rendering`];return e.worstCommit&&e.slowCommitCount>0&&t.push(`${e.slowCommitCount} over 16ms (worst #${e.worstCommit.index} ${B(e.worstCommit.durationMs)})`),t.join(`, `)}function Ce(e,t=5){let n=e.notes.map(e=>`Note: ${e}`);if(e.commitCount===0)return u([`React profile: no commits recorded. Start profiling, then perform the interaction before stopping.`,...n]);let r=[Se(e)],i=e.findings.slice(0,t);if(i.length===0)r.push(`No render problems above thresholds.`);else{i.forEach((e,t)=>{r.push(`${t+1}. ${e.kind} ${e.component}: ${e.evidence} -> ${e.fix}`)});let t=e.findings.length-i.length;t>0&&r.push(`+${t} smaller findings (--limit ${e.findings.length})`)}return r.push(...n),e.naming===`lookup`&&r.push(`Note: component names came from mounted elements; components unmounted during the profile are left out.`),r.push(`More: profile report [Component] | profile commit [N]`),u(r)}function U(e){return Object.entries(e).filter(([,e])=>e>0).sort((e,t)=>t[1]-e[1]).map(([e,t])=>`${e} ${t}`).join(`, `)||`unrecorded`}function W(e,t){return e<t?[` +${t-e} more (--limit ${t})`]:[]}function G(e,t=4){return Object.entries(e).sort((e,t)=>t[1]-e[1]).slice(0,t).map(([e,t])=>`${e} ${t}`).join(`, `)}function K(e){let t=e.renders>0?e.selfMs/e.renders:0,n=e.instances>1?` ${e.instances} inst`:``;return`${e.name} [${e.kind}] self ${B(e.selfMs)} avg ${B(t)} max ${B(e.maxSelfMs)} renders ${e.renders}${n}`}function we(e,t){if(e.components.length===0)return`No component renders recorded.`;let n=e.components.slice(0,t);return u([`Components by self time:`,...n.map(e=>{let t=G(e.changedProps);return` ${K(e)}: ${U(e.causes)}${t?`; changed props ${t}`:``}`}),...W(n.length,e.components.length)])}function Te(e,t){let n=e.components.filter(e=>e.name===t);return n.length>0?n:e.components.filter(e=>e.name.toLowerCase()===t.toLowerCase())}function Ee(e,t){let n=[K(t),`causes: ${U(t.causes)}`],r=Object.entries(t.changedProps).sort((e,t)=>t[1]-e[1]).map(([e,n])=>`${e} ${n}${t.propKinds[e]?` (${t.propKinds[e]})`:``}`);r.length>0&&n.push(`changed props: ${r.join(`, `)}`);let i=G(t.changedState,8);i&&n.push(`changed state: ${i}`);let a=G(t.changedHooks,8);a&&n.push(`changed hooks (by index): ${a}`);let o=G(t.owners,3);if(o&&n.push(`rendered by: ${o}`),t.costliestCommits.length>0){let r=t.costliestCommits.map(({index:t,selfMs:n})=>{let r=e.commits[t];return`#${t} ${B(n)}${r?` of ${B(r.durationMs)}`:``}`});n.push(`its costliest commits (self time of commit duration): ${r.join(`, `)}`)}return n}function De(e,t){return u(t.flatMap(t=>[...Ee(e,t),...e.findings.filter(e=>N(e,t)).map(e=>`finding ${e.kind}: ${e.evidence} -> ${e.fix}`)]))}function q(e){let t=e.updaters.length>0?` <- ${e.updaters.map(e=>e.name).join(`, `)}`:``,n=e.mounts>0?` (${e.mounts} mounted)`:``;return`#${e.index} +${H(e.atMs)} ${B(e.durationMs)} ${e.rendered} rendered${n}${t}`}function J(e,t){return e.commits.length<=t?e.commits:[...e.commits].sort((e,t)=>t.durationMs-e.durationMs).slice(0,t).sort((e,t)=>e.index-t.index)}function Oe(e,t){if(e.commits.length===0)return`No commits recorded.`;let n=J(e,t),r=n.length<e.commits.length?`Commits (${n.length} slowest of ${e.commits.length}, --limit ${e.commits.length} for all):`:`Commits:`;return u([r,...n.map(e=>` ${q(e)}`)])}function ke(e,t){let n=[q(e)],r=e.components.slice(0,t);for(let e of r){let t=e.instances>1?` x${e.instances}`:``;n.push(` ${e.name} [${e.kind}]${t} self ${B(e.selfMs)} ${e.causes.join(`+`)||`unrecorded`}`)}return n.push(...W(r.length,e.components.length)),u(n)}const Y=[`start`,`stop`,`report`,`commit`];function Ae(e){return Y.includes(e)}function X(e,t){switch(e){case`start`:return{usage:`profile start`,positionals:0,options:d};case`stop`:return{usage:`profile stop`,positionals:0,options:[...d,`limit`]};case`report`:return t===void 0?{usage:`profile report`,positionals:1,options:[`limit`]}:{usage:`profile report <Component>`,positionals:1,options:[]};case`commit`:return{usage:`profile commit`,positionals:1,options:[`limit`]}}}function je(t){let[n,...r]=t;if(!Ae(n))throw new e(`INVALID_ARGS`,`Unknown react-devtools profile command: ${n??`(none)`}.`,{hint:`Use one of: ${Y.join(`, `)}.`});let i=l(r,e=>X(n,e[0]));return{...i,subcommand:n,target:i.positionals[0]}}function Z(e){return m.join(e.stateDir,`react-profiles`,`${n(e.session)}.json`)}function Q(e,n){let r=Z(e);return p.mkdirSync(m.dirname(r),{recursive:!0}),t({destination:r,contents:`${JSON.stringify(n)}\n`}),r}function Me(e){return e?.version===2&&Array.isArray(e.profile?.commits)&&typeof e.profile.elements==`object`&&Array.isArray(e.notes)}function $(t){let n;try{n=p.readFileSync(Z(t),`utf8`)}catch{throw new e(`COMMAND_FAILED`,`No React profile saved for session ${t.session}.`,{hint:`Run react-devtools profile start, perform the interaction, then react-devtools profile stop.`})}let r;try{r=JSON.parse(n)}catch{r=void 0}if(!Me(r))throw new e(`COMMAND_FAILED`,`The saved React profile has an unsupported format.`,{hint:`Record a new profile with react-devtools profile start and stop.`});return z(r.profile,r.propKinds,r.notes)}const Ne=e=>V(Math.max(0,e));async function Pe(e,t){return await r(e,t,async(e,t)=>{let n=await c(e,`start`),r=i(t);if(!n.ok&&n.reason===`already-profiling`)return{app:r,alreadyProfiling:!0,message:`Already profiling ${r} for ${Ne(n.elapsedMs??0)}; run react-devtools profile stop to read it.`};if(!n.ok)throw a(n);return{app:r,attach:n.attach,message:`Profiling React renders in ${r}. Perform the interaction, then run react-devtools profile stop.`}})}async function Fe(e,t){let n=ae(t);if(Object.keys(n).length===0)return{propKinds:{},notes:[]};try{return{propKinds:await c(e,`describeProps`,n),notes:[]}}catch(e){return{propKinds:{},notes:[`Changed prop values could not be inspected: ${e instanceof Error?e.message:String(e)}`]}}}async function Ie(e,t){return await r(e,t,async(e,n)=>{let r=await c(e,`stop`);if(!r.ok)throw a(r);let{ok:o,failures:s,...l}=r,u=i(n),d={version:2,savedAt:new Date().toISOString(),appId:u,deviceName:n.deviceName,profile:l,propKinds:{},notes:s.map(e=>`A React renderer's profile could not be read: ${e}`)};Q(t,{...d,notes:[...d.notes,`Changed prop values have not been inspected; collection may have been interrupted.`]});let f=await Fe(e,l);return d.propKinds=f.propKinds,d.notes.push(...f.notes),Q(t,d),{appId:u,analysis:z(l,d.propKinds,d.notes)}})}function Le(t,n){let r=Te(t,n);if(r.length===0)throw new e(`COMMAND_FAILED`,`No renders of ${n} in the saved profile.`,{hint:`Use a name that react-devtools profile report lists.`});return r}function Re(t,n){let r=n.replace(/^#/,``),i=/^\d+$/.test(r)?t.commits[Number(r)]:void 0;if(!i)throw new e(`INVALID_ARGS`,`No commit ${n} in the saved profile.`,{hint:`Use a commit index from 0 to ${Math.max(t.commits.length-1,0)}.`});return i}const ze={start:async(e,t)=>{let n=await Pe(e,t);return{text:n.message,data:n}},stop:async(e,t)=>{let{appId:n,analysis:r}=await Ie(e,t);return{text:Ce(r,e.limit??5),data:{appId:n,wallMs:r.wallMs,commitCount:r.commitCount,renderMs:r.renderMs,slowCommitCount:r.slowCommitCount,worstCommit:r.worstCommit,findings:r.findings.slice(0,e.limit??r.findings.length),notes:r.notes,savedTo:Z(t)}}},report:async(e,t)=>{let n=$(t);if(e.target===void 0){let t=e.limit??10;return{text:we(n,t),data:{components:n.components.slice(0,t)}}}let r=Le(n,e.target);return{text:De(n,r),data:{components:r,findings:n.findings.filter(e=>r.some(t=>N(e,t)))}}},commit:async(e,t)=>{let n=$(t);if(e.target===void 0){let t=e.limit??20;return{text:Oe(n,t),data:{commits:J(n,t)}}}let r=Re(n,e.target),i=e.limit??10;return{text:ke(r,i),data:{...r,components:r.components.slice(0,i)}}}};async function Be(e,t){let n=je(e);return await ze[n.subcommand](n,t)}export{Be as runReactProfileCommand};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{M as e,N as t,j as n}from"./sdk-batch.js";import{_ as r,f as i,z as a}from"./sdk-contracts.js";import{f as o}from"./screenshot.js";import"./capture.js";import{d as s}from"./sdk-device.js";import{i as c,n as l}from"./recording-export-quality.js";import{i as u}from"./recording-scope.js";import{o as d}from"./session-store.js";import{H as f}from"./parameterized-recorded-fill.js";import{_ as p}from"./daemon-http.js";import{i as m,r as h,t as g}from"./output-path.js";import{t as _}from"./screen-recording-resource-recovery.js";import{i as v,n as y,r as b,t as x}from"./screen-recording-session-resource.js";import{n as S}from"./device-selector-intent.js";import"./screen-recording-admission-ledger.js";import{n as C}from"./context.js";import{a as w}from"./session-routing.js";import{a as T,t as E}from"./session-capture-binding.js";import{n as D}from"./request-runtime-binding.js";import{n as ee,r as te,t as O}from"./screen-recording-stop-recovery.js";import{n as k}from"./request-device-resolution.js";import{a as A,i as j,n as M,r as N,t as P}from"./record-runtime-response.js";import{randomUUID as F}from"node:crypto";import I from"node:path";function L(e){return e.appBundleId!==void 0||e.deviceClaim!==void 0||e.lease!==void 0||e.appLog!==void 0||e.audioProbe!==void 0||e.perfCapture!==void 0||e.trace!==void 0}function R(e){let t=o(`record`,e.flags);if(t)throw new r(`INVALID_ARGS`,t);let n=e.flags?.fps;if(n!==void 0&&(!Number.isInteger(n)||n<1||n>120))throw new r(`INVALID_ARGS`,`fps must be an integer between 1 and 120`);let i=c(e.flags?.quality);if(e.flags?.quality!==void 0&&i===void 0)throw new r(`INVALID_ARGS`,`quality must be one of: ${l.join(`, `)} (legacy numeric values 5-10 are accepted)`);return{scope:z(e.flags?.recordingScope),...n===void 0?{}:{fps:n},...i===void 0?{}:{exportQuality:i},showTouches:e.flags?.hideTouches!==!0,hideTouchesRequested:e.flags?.hideTouches===!0}}function z(e){if(e===void 0)return`app`;if(e===`app`||e===`device`||e===`system`)return e;throw new r(`INVALID_ARGS`,`record scope must be app, device, or system`)}function B(e){return{ok:!1,error:{code:`INVALID_ARGS`,message:i(e)?`record start with app scope and an explicit session requires an active app session; run open <app> first, or use --scope device to record the full screen`:`record start defaults to app scope and requires an active app session; run open <app> first, or use --scope device to record the full screen`}}}async function V(e){try{return await H(e)}catch(e){return{ok:!1,error:a(e)}}}async function H(e){let{req:t,sessionName:n,sessionStore:r}=e,i=r.lookup(n),a=i?.session,{plan:o,scope:s}=U(t,a);if(o.kind===`start`&&!u(s)&&!a&&!K(t))return B(t);let c=await W(e,i,o),{session:l}=c;return o.kind===`start`?await J(e,l,c.ref,R(t),o.use,c.needsReadiness):await re(e,l,c.ref,o.kind,c.needsReadiness)}function U(e,t){let r=z(e.flags?.recordingScope);return{scope:r,plan:n({action:e.positionals?.[0],scope:r,hasLiveHandle:t?.screenRecording!==void 0})}}async function W(e,t,n){if(t)return{session:e.sessionStore.requireCurrent(t),ref:t,needsReadiness:!1};let r=await G(e,n);return await e.retainDeviceExecutionLock(r.id),{session:oe(e,r),needsReadiness:!0}}async function G(e,t){let{req:n,sessionName:r}=e;if(!K(n))return await k(n,{env:e.sessionStore.host.env});if(t.kind===`stop-recovery`){let t=ee({sessionName:r,sessionStore:e.sessionStore});if(t)return await q(e,t)}let{namedSessionNotFoundError:i}=await import(`./explicit-session-resolution.js`);throw i(r)}function K(e){return i(e)&&!S(e.flags)}async function q(e,t){let n={...e.req.flags??{},platform:t.family},r=s(t.family);return r&&(n[r]=t.id),await k(e.req,{env:e.sessionStore.host.env},n)}async function J(t,n,r,i,a,o){if(n.screenRecording)return{ok:!1,error:{code:`INVALID_ARGS`,message:`recording already in progress`}};let s=r?void 0:E(t.sessionStore,t.sessionName,n),c=r?T(t.sessionStore,r):s.binding;c.assertAdoptable();let l=await t.bindDevice(n.device,e);o&&await D(l,t.platformServices);let u=l.facts.screenRecordingStart;if(!u.available)return j(u);let f=await t.bindDevice(n.device,a);await v.settleStartConflicts({resourcePath:v.resourcePath(t.sessionStore,t.sessionName),device:n.device,holdsSession:e=>t.sessionStore.lookup(e)!==void 0,scope:t.requestScope,acquireControl:$(t,n.device,!1)});let{fence:p,outputPaths:m}=Y(t,n);c.assertAdoptable();let h=await f.operations.screenRecordingStart(Z(t,n,i,p,m)),g=n.lease?.tenantId??t.req.meta?.tenantId;await x({admissionLedger:t.admissionLedger,binding:c,device:n.device,owner:f.owner,fence:p,...h,envelope:t.req.internal?.publicNetworkOnly||g?{...h.envelope,metadata:{...h.envelope.metadata,...t.req.internal?.publicNetworkOnly?{remoteCaptureOutput:!0}:{},...g?{remoteCaptureTenantId:g}:{}}}:h.envelope,throwIfCanceled:t.throwIfCanceled});let _=r??s.requireRef(),y=c.read();if(!y)throw TypeError(`Screen recording adoption did not publish a live handle`);let b=y.handle.inspect();return d(t.sessionStore,_,t.req,t.req.command,M(b)),P(b,t.sessionStore.ensureSessionDir(t.sessionName),m.requestedPath)}function Y(e,t){let n=v.resourcePath(e.sessionStore,e.sessionName);return{fence:v.createNextFence({admissionLedger:e.admissionLedger,resourcePath:n,device:t.device}),outputPaths:X(e.req,t.device.platform,e.sessionStore.host.cwd,e.sessionStore.ensureSessionDir(e.sessionName))}}function X(e,t,n,r){let i=e.positionals?.[1],a=e.meta?.clientArtifactPaths?.outPath;if(e.internal?.publicNetworkOnly){let e=h(t);return{...m({requestedPath:I.join(r,`recording-${F()}${e}`),platform:t,cwd:n}),...a===void 0?{}:{clientOutputPath:g(a,e)}}}if(i===void 0&&a!==void 0){let e=h(t);return{...m({requestedPath:p(`recording`,e),platform:t,cwd:n}),clientOutputPath:g(a,e)}}return{...m({requestedPath:i,platform:t,cwd:C(e,{cwd:n})}),...a===void 0?{}:{clientOutputPath:a}}}function Z(e,t,n,r,i){return{sessionId:e.sessionName,requestId:e.req.meta?.requestId,outputPath:i.outputPath,clientOutputPath:i.clientOutputPath,scope:n.scope,showTouches:n.showTouches,hideTouchesRequested:n.hideTouchesRequested,recordOnlySession:t.recordOnlySession===!0,activeSessionApp:ne(t),exportQuality:n.exportQuality,fps:n.fps,fence:r}}function ne(e){if(e.appBundleId)return{bundleId:e.appBundleId,...e.appName?{name:e.appName}:{}}}async function re(e,t,n,r,i){let a;try{a=r===`stop-live`?{completion:await y({intent:`capture`,binding:T(e.sessionStore,n)}),recordsSessionAction:!0}:await ae(e,t,i)}catch(t){throw ie(e,n),t}let o=a.completion,s=N(o),c=v.resourcePath(e.sessionStore,e.sessionName),l=v.store.read(c),u=A(o,l.status===`decoded`&&l.envelope.metadata?.remoteCaptureOutput===!0),p=l.status===`decoded`&&typeof l.envelope.metadata?.remoteCaptureTenantId==`string`?l.envelope.metadata.remoteCaptureTenantId:t.lease?.tenantId;return a.recordsSessionAction&&d(e.sessionStore,n,e.req,e.req.command,{action:`stop`,outPath:o.outPath,...o.clientOutPath?{requestedFileName:I.basename(o.clientOutPath)}:{},showTouches:o.showTouches}),n&&Q(e.sessionStore,n),s.ok&&s.data?{...s,data:f(s.data,u?`daemon`:`caller`,p)}:s}function ie(e,t){t&&te(e)&&Q(e.sessionStore,t)}function Q(e,t){let n=e.resolveCurrent(t);n?.recordOnlySession&&(L(n)||e.retire(t))}async function ae(e,t,n){let i=O({sessionName:e.sessionName,sessionStore:e.sessionStore,device:t.device});if(i.kind===`completed`)return{completion:i.completion,recordsSessionAction:!1};if(i.kind===`none`)throw new r(`INVALID_ARGS`,`no active recording`);return{completion:await b({resourcePath:i.resourcePath,scope:e.requestScope,acquireControl:$(e,t.device,n)}),recordsSessionAction:!0}}function $(e,n,r){return async(i,a)=>{let o=await e.bindExactDevice(n,i.owner,i.fence,t,a);return r&&await D(o,e.platformServices),_({runtime:o,dispose:async()=>{}})}}function oe(e,t){return{name:e.sessionName,sessionScope:w(e.req),device:t,createdAt:Date.now(),recordOnlySession:!0,actions:[]}}export{V as t};
|
package/dist/src/record-trace.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{s as e}from"./sdk-contracts.js";import{a as t,n}from"./recording-scope.js";import{o as r}from"./session-store.js";import{
|
|
1
|
+
import{s as e}from"./sdk-contracts.js";import{a as t,n}from"./recording-scope.js";import{o as r}from"./session-store.js";import{H as i}from"./parameterized-recorded-fill.js";import{t as a}from"./session-paths.js";import"./screen-recording-admission-ledger.js";import{n as o}from"./context.js";import{t as s}from"./record-runtime.js";import c from"node:fs";import l from"node:path";function u(r){let i=t(r.req.positionals);if(!i)return e(`INVALID_ARGS`,n);let a=r.sessionStore.lookup(r.sessionName);return a?i===`start`?d(r.host,r.req,r.sessionStore,a):f(r.host,r.req,r.sessionStore,a):e(`SESSION_NOT_FOUND`,`No active session`)}function d(t,n,i,s){let u=i.requireCurrent(s);if(u.trace)return e(`INVALID_ARGS`,`trace already in progress`);let d=a(n.positionals?.[1]??i.defaultTracePath(u),o(n,t));return c.mkdirSync(l.dirname(d),{recursive:!0}),c.appendFileSync(d,``),u.trace={outPath:d,startedAt:Date.now(),clientOutPath:n.meta?.clientArtifactPaths?.outPath,...n.internal?.publicNetworkOnly?{remoteCaptureOutputPath:d}:{},remoteCaptureTenantId:u.lease?.tenantId??n.meta?.tenantId},r(i,s,n,n.command,{action:`start`,outPath:d}),{ok:!0,data:{trace:`started`,outPath:d}}}function f(t,n,a,s){let c=a.requireCurrent(s);if(!c.trace)return e(`INVALID_ARGS`,`no active trace`);let u=p(o(n,t),c.trace.outPath,n.positionals?.[1]),d=c.trace.remoteCaptureOutputPath===u,f=c.trace.remoteCaptureTenantId,m=n.meta?.clientArtifactPaths?.outPath??c.trace.clientOutPath??(n.internal?.publicNetworkOnly?void 0:u);return c.trace=void 0,r(a,s,n,n.command,{action:`stop`,outPath:u}),{ok:!0,data:i({trace:`stopped`,outPath:u,artifacts:[{field:`outPath`,artifactType:`trace-log`,path:u,localPath:m,fileName:l.basename(m??u)}]},d?`daemon`:`caller`,f)}}function p(e,t,n){if(!n)return t;let r=a(n,e);return c.mkdirSync(l.dirname(r),{recursive:!0}),c.existsSync(t)?c.renameSync(t,r):c.appendFileSync(r,``),r}async function m(e){let{req:t,sessionName:n,sessionStore:r}=e,i=t.command;return i===`record`?s({req:t,sessionName:n,sessionStore:r,bindDevice:e.bindDevice,platformServices:e.platformServices,bindExactDevice:e.bindExactDevice,admissionLedger:e.admissionLedger,requestScope:e.requestScope,retainDeviceExecutionLock:e.retainDeviceExecutionLock,throwIfCanceled:e.throwIfCanceled}):i===`trace`?u({host:e.host,req:t,sessionName:n,sessionStore:r}):null}export{m as handleRecordTraceCommands};
|