@inflatable-cookie/longhorn 0.7.0 → 0.7.1
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/dist/agent-control/generated/protocol.d.ts +260 -0
- package/{src/config/generated/protocol.ts → dist/agent-control/generated/protocol.js} +1 -2
- package/dist/agent-control/index.d.ts +3 -0
- package/dist/agent-control/index.js +2 -0
- package/dist/agent-control/inject.d.ts +1 -0
- package/{src/agent-control/inject.ts → dist/agent-control/inject.js} +2 -4
- package/dist/agent-control/selection.d.ts +50 -0
- package/dist/agent-control/selection.js +75 -0
- package/dist/agent-control/shim.d.ts +61 -0
- package/dist/agent-control/shim.js +913 -0
- package/dist/bridge/direct.d.ts +9 -0
- package/dist/bridge/direct.js +12 -0
- package/dist/bridge/generated/fields.d.ts +28 -0
- package/dist/bridge/generated/fields.js +32 -0
- package/dist/bridge/generated/protocol.d.ts +276 -0
- package/dist/bridge/generated/protocol.js +84 -0
- package/dist/bridge/generated/variant-fields.d.ts +2 -0
- package/{src/bridge/generated/variant-fields.ts → dist/bridge/generated/variant-fields.js} +2 -6
- package/dist/bridge/index.d.ts +10 -0
- package/{src/bridge/index.ts → dist/bridge/index.js} +10 -10
- package/dist/bridge/job.d.ts +17 -0
- package/dist/bridge/job.js +65 -0
- package/dist/bridge/loopback.d.ts +17 -0
- package/dist/bridge/loopback.js +46 -0
- package/dist/bridge/operation.d.ts +28 -0
- package/dist/bridge/operation.js +71 -0
- package/dist/bridge/router.d.ts +11 -0
- package/dist/bridge/router.js +36 -0
- package/dist/bridge/runtime/connection.d.ts +19 -0
- package/dist/bridge/runtime/connection.js +180 -0
- package/dist/bridge/runtime/policy.d.ts +17 -0
- package/dist/bridge/runtime/policy.js +43 -0
- package/dist/bridge/runtime/retry.d.ts +8 -0
- package/dist/bridge/runtime/retry.js +30 -0
- package/dist/bridge/runtime.d.ts +3 -0
- package/dist/bridge/runtime.js +3 -0
- package/dist/bridge/session.d.ts +17 -0
- package/dist/bridge/session.js +31 -0
- package/dist/bridge/stream/connection.d.ts +23 -0
- package/dist/bridge/stream/connection.js +71 -0
- package/dist/bridge/stream/source.d.ts +19 -0
- package/dist/bridge/stream/source.js +40 -0
- package/dist/bridge/stream/tracker.d.ts +11 -0
- package/dist/bridge/stream/tracker.js +91 -0
- package/dist/bridge/stream.d.ts +6 -0
- package/dist/bridge/stream.js +6 -0
- package/dist/bridge/supervision.d.ts +61 -0
- package/dist/bridge/supervision.js +140 -0
- package/dist/bridge/validation/base.d.ts +19 -0
- package/dist/bridge/validation/base.js +68 -0
- package/dist/bridge/validation/jobs.d.ts +5 -0
- package/dist/bridge/validation/jobs.js +58 -0
- package/dist/bridge/validation/negotiation.d.ts +4 -0
- package/dist/bridge/validation/negotiation.js +135 -0
- package/dist/bridge/validation/operations.d.ts +10 -0
- package/dist/bridge/validation/operations.js +116 -0
- package/dist/bridge/validation/streams.d.ts +5 -0
- package/dist/bridge/validation/streams.js +25 -0
- package/dist/bridge/validation.d.ts +5 -0
- package/dist/bridge/validation.js +5 -0
- package/dist/commands/client.d.ts +21 -0
- package/dist/commands/client.js +79 -0
- package/dist/commands/controller.d.ts +78 -0
- package/dist/commands/controller.js +339 -0
- package/dist/commands/generated/fields.d.ts +39 -0
- package/dist/commands/generated/fields.js +43 -0
- package/dist/commands/generated/protocol.d.ts +958 -0
- package/dist/commands/generated/protocol.js +24 -0
- package/dist/commands/generated/variant-fields.d.ts +2 -0
- package/dist/commands/generated/variant-fields.js +86 -0
- package/dist/commands/index.d.ts +8 -0
- package/{src/commands/index.ts → dist/commands/index.js} +8 -8
- package/dist/commands/keyboard.d.ts +40 -0
- package/dist/commands/keyboard.js +246 -0
- package/dist/commands/physical-code.d.ts +2 -0
- package/dist/commands/physical-code.js +8 -0
- package/dist/commands/ports.d.ts +46 -0
- package/dist/commands/ports.js +1 -0
- package/dist/commands/projectors.d.ts +37 -0
- package/dist/commands/projectors.js +220 -0
- package/dist/commands/validation.d.ts +17 -0
- package/dist/commands/validation.js +481 -0
- package/dist/config/client.d.ts +19 -0
- package/dist/config/client.js +108 -0
- package/dist/config/generated/base.d.ts +750 -0
- package/dist/config/generated/base.js +20 -0
- package/dist/config/generated/fields.d.ts +50 -0
- package/dist/config/generated/fields.js +54 -0
- package/dist/config/generated/label-template.d.ts +1 -0
- package/{src/config/generated/label-template.ts → dist/config/generated/label-template.js} +2 -8
- package/dist/config/generated/labels.d.ts +4 -0
- package/dist/config/generated/labels.js +25 -0
- package/dist/config/generated/protocol.d.ts +2 -0
- package/dist/config/generated/protocol.js +3 -0
- package/dist/config/generated/restore.d.ts +731 -0
- package/dist/config/generated/restore.js +21 -0
- package/dist/config/generated/variant-fields.d.ts +2 -0
- package/dist/config/generated/variant-fields.js +127 -0
- package/dist/config/index.d.ts +7 -0
- package/{src/config/index.ts → dist/config/index.js} +7 -7
- package/dist/config/names.d.ts +13 -0
- package/dist/config/validation/commands.d.ts +14 -0
- package/dist/config/validation/commands.js +70 -0
- package/dist/config/validation/outcomes.d.ts +13 -0
- package/dist/config/validation/outcomes.js +195 -0
- package/dist/config/validation/primitives.d.ts +19 -0
- package/dist/config/validation/primitives.js +86 -0
- package/dist/config/validation/projection.d.ts +9 -0
- package/dist/config/validation/projection.js +226 -0
- package/dist/config/validation.d.ts +4 -0
- package/dist/config/validation.js +4 -0
- package/dist/core/connection.d.ts +69 -0
- package/dist/core/connection.js +291 -0
- package/dist/core/controller-lifecycle.d.ts +39 -0
- package/dist/core/controller-lifecycle.js +116 -0
- package/dist/core/generated/identifiers.d.ts +4 -0
- package/dist/core/generated/identifiers.js +3 -0
- package/dist/core/identifiers.d.ts +11 -0
- package/dist/core/identifiers.js +21 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.js +4 -0
- package/dist/core/json-value.d.ts +8 -0
- package/dist/core/json-value.js +54 -0
- package/dist/core/listeners.d.ts +17 -0
- package/dist/core/listeners.js +29 -0
- package/dist/core/record.d.ts +8 -0
- package/dist/core/record.js +57 -0
- package/dist/core/transport.d.ts +12 -0
- package/dist/core/transport.js +3 -0
- package/dist/core/wire-copy.d.ts +1 -0
- package/dist/core/wire-copy.js +7 -0
- package/dist/history/client.d.ts +12 -0
- package/dist/history/client.js +36 -0
- package/dist/history/controller.d.ts +62 -0
- package/dist/history/controller.js +302 -0
- package/dist/history/direct.d.ts +9 -0
- package/dist/history/direct.js +9 -0
- package/dist/history/generated/fields.d.ts +14 -0
- package/dist/history/generated/fields.js +18 -0
- package/dist/history/generated/protocol.d.ts +390 -0
- package/dist/history/generated/protocol.js +12 -0
- package/dist/history/generated/variant-fields.d.ts +2 -0
- package/dist/history/generated/variant-fields.js +25 -0
- package/dist/history/index.d.ts +8 -0
- package/{src/history-tree/index.ts → dist/history/index.js} +8 -8
- package/dist/history/ports.d.ts +18 -0
- package/dist/history/ports.js +1 -0
- package/dist/history/serialized.d.ts +11 -0
- package/dist/history/serialized.js +25 -0
- package/dist/history/validation.d.ts +11 -0
- package/dist/history/validation.js +253 -0
- package/dist/history-tree/client.d.ts +16 -0
- package/dist/history-tree/client.js +60 -0
- package/dist/history-tree/controller.d.ts +112 -0
- package/dist/history-tree/controller.js +408 -0
- package/dist/history-tree/direct.d.ts +3 -0
- package/dist/history-tree/direct.js +3 -0
- package/dist/history-tree/generated/fields.d.ts +23 -0
- package/dist/history-tree/generated/fields.js +27 -0
- package/dist/history-tree/generated/protocol.d.ts +759 -0
- package/dist/history-tree/generated/protocol.js +14 -0
- package/dist/history-tree/generated/variant-fields.d.ts +2 -0
- package/dist/history-tree/generated/variant-fields.js +43 -0
- package/dist/history-tree/index.d.ts +8 -0
- package/{src/history/index.ts → dist/history-tree/index.js} +8 -8
- package/dist/history-tree/ports.d.ts +26 -0
- package/dist/history-tree/ports.js +1 -0
- package/dist/history-tree/serialized.d.ts +15 -0
- package/dist/history-tree/serialized.js +37 -0
- package/dist/history-tree/validation.d.ts +26 -0
- package/dist/history-tree/validation.js +389 -0
- package/dist/layout/generated/protocol.d.ts +381 -0
- package/dist/layout/generated/protocol.js +7 -0
- package/dist/layout/generated/variant-fields.d.ts +2 -0
- package/dist/layout/generated/variant-fields.js +45 -0
- package/dist/layout/index.d.ts +4 -0
- package/dist/layout/index.js +4 -0
- package/dist/layout/ratio.d.ts +4 -0
- package/dist/layout/ratio.js +16 -0
- package/dist/layout/validation.d.ts +12 -0
- package/dist/layout/validation.js +104 -0
- package/dist/layout/visibility.d.ts +3 -0
- package/dist/layout/visibility.js +14 -0
- package/dist/licence/client.d.ts +14 -0
- package/dist/licence/client.js +51 -0
- package/dist/licence/controller.d.ts +138 -0
- package/dist/licence/controller.js +289 -0
- package/dist/licence/direct.d.ts +3 -0
- package/dist/licence/direct.js +3 -0
- package/dist/licence/generated/fields.d.ts +13 -0
- package/dist/licence/generated/fields.js +17 -0
- package/dist/licence/generated/protocol.d.ts +267 -0
- package/dist/licence/generated/protocol.js +10 -0
- package/dist/licence/generated/variant-fields.d.ts +2 -0
- package/dist/licence/generated/variant-fields.js +32 -0
- package/dist/licence/index.d.ts +10 -0
- package/dist/licence/index.js +14 -0
- package/dist/licence/key.d.ts +65 -0
- package/dist/licence/key.js +120 -0
- package/dist/licence/ports.d.ts +29 -0
- package/dist/licence/ports.js +1 -0
- package/dist/licence/serialized.d.ts +13 -0
- package/dist/licence/serialized.js +31 -0
- package/dist/licence/validation.d.ts +13 -0
- package/dist/licence/validation.js +247 -0
- package/dist/native-content/client.d.ts +51 -0
- package/dist/native-content/client.js +336 -0
- package/dist/native-content/direct.d.ts +10 -0
- package/dist/native-content/direct.js +3 -0
- package/dist/native-content/generated/fields.d.ts +27 -0
- package/dist/native-content/generated/fields.js +31 -0
- package/dist/native-content/generated/protocol.d.ts +675 -0
- package/dist/native-content/generated/protocol.js +26 -0
- package/dist/native-content/generated/variant-fields.d.ts +2 -0
- package/dist/native-content/generated/variant-fields.js +75 -0
- package/dist/native-content/index.d.ts +7 -0
- package/{src/native-content/index.ts → dist/native-content/index.js} +7 -7
- package/dist/native-content/ports.d.ts +19 -0
- package/dist/native-content/ports.js +1 -0
- package/dist/native-content/serialized.d.ts +12 -0
- package/dist/native-content/serialized.js +28 -0
- package/dist/native-content/validation/base.d.ts +21 -0
- package/dist/native-content/validation/base.js +118 -0
- package/dist/native-content/validation/messages.d.ts +9 -0
- package/dist/native-content/validation/messages.js +115 -0
- package/dist/native-content/validation/state.d.ts +12 -0
- package/dist/native-content/validation/state.js +319 -0
- package/dist/native-content/validation.d.ts +3 -0
- package/dist/native-content/validation.js +3 -0
- package/dist/notifications/client.d.ts +28 -0
- package/dist/notifications/client.js +92 -0
- package/dist/notifications/controller.d.ts +104 -0
- package/dist/notifications/controller.js +381 -0
- package/dist/notifications/direct.d.ts +8 -0
- package/dist/notifications/direct.js +3 -0
- package/dist/notifications/generated/fields.d.ts +15 -0
- package/dist/notifications/generated/fields.js +19 -0
- package/dist/notifications/generated/labels.d.ts +4 -0
- package/dist/notifications/generated/labels.js +14 -0
- package/dist/notifications/generated/protocol.d.ts +535 -0
- package/dist/notifications/generated/protocol.js +13 -0
- package/dist/notifications/generated/variant-fields.d.ts +2 -0
- package/dist/notifications/generated/variant-fields.js +35 -0
- package/dist/notifications/index.d.ts +11 -0
- package/dist/notifications/index.js +16 -0
- package/dist/notifications/ports.d.ts +15 -0
- package/dist/notifications/ports.js +1 -0
- package/dist/notifications/serialized.d.ts +10 -0
- package/dist/notifications/serialized.js +22 -0
- package/dist/notifications/toast.d.ts +27 -0
- package/{src/notifications/toast.ts → dist/notifications/toast.js} +6 -15
- package/{src/notifications/tone.ts → dist/notifications/tone.d.ts} +2 -8
- package/dist/notifications/tone.js +15 -0
- package/dist/notifications/validation.d.ts +11 -0
- package/dist/notifications/validation.js +248 -0
- package/dist/operation/bridge.d.ts +46 -0
- package/dist/operation/bridge.js +155 -0
- package/dist/operation/client.d.ts +29 -0
- package/dist/operation/client.js +97 -0
- package/dist/operation/controller.d.ts +62 -0
- package/dist/operation/controller.js +211 -0
- package/dist/operation/direct.d.ts +9 -0
- package/dist/operation/direct.js +3 -0
- package/dist/operation/generated/fields.d.ts +16 -0
- package/dist/operation/generated/fields.js +20 -0
- package/dist/operation/generated/labels.d.ts +2 -0
- package/dist/operation/generated/labels.js +12 -0
- package/dist/operation/generated/protocol.d.ts +794 -0
- package/dist/operation/generated/protocol.js +17 -0
- package/dist/operation/generated/variant-fields.d.ts +2 -0
- package/dist/operation/generated/variant-fields.js +58 -0
- package/dist/operation/index.d.ts +9 -0
- package/dist/operation/index.js +14 -0
- package/dist/operation/ports.d.ts +17 -0
- package/dist/operation/ports.js +1 -0
- package/dist/operation/serialized.d.ts +11 -0
- package/dist/operation/serialized.js +25 -0
- package/dist/operation/validation.d.ts +14 -0
- package/dist/operation/validation.js +431 -0
- package/dist/settings/client.d.ts +13 -0
- package/dist/settings/client.js +52 -0
- package/dist/settings/connection.d.ts +29 -0
- package/dist/settings/connection.js +140 -0
- package/dist/settings/generated/fields.d.ts +30 -0
- package/dist/settings/generated/fields.js +34 -0
- package/dist/settings/generated/protocol.d.ts +663 -0
- package/dist/settings/generated/protocol.js +16 -0
- package/dist/settings/generated/variant-fields.d.ts +2 -0
- package/dist/settings/generated/variant-fields.js +24 -0
- package/dist/settings/index.d.ts +7 -0
- package/{src/settings/index.ts → dist/settings/index.js} +7 -7
- package/dist/settings/names.d.ts +6 -0
- package/dist/settings/registry.d.ts +43 -0
- package/dist/settings/registry.js +70 -0
- package/dist/settings/validation/authority.d.ts +2 -0
- package/dist/settings/validation/authority.js +42 -0
- package/dist/settings/validation/command.d.ts +8 -0
- package/dist/settings/validation/command.js +95 -0
- package/dist/settings/validation/error.d.ts +7 -0
- package/dist/settings/validation/error.js +13 -0
- package/dist/settings/validation/primitives.d.ts +19 -0
- package/dist/settings/validation/primitives.js +109 -0
- package/dist/settings/validation/projection.d.ts +4 -0
- package/dist/settings/validation/projection.js +26 -0
- package/dist/settings/validation/registry.d.ts +2 -0
- package/dist/settings/validation/registry.js +85 -0
- package/dist/settings/validation.d.ts +4 -0
- package/dist/settings/validation.js +4 -0
- package/dist/surface-transfer/client.d.ts +10 -0
- package/dist/surface-transfer/client.js +23 -0
- package/dist/surface-transfer/generated/fields.d.ts +7 -0
- package/dist/surface-transfer/generated/fields.js +11 -0
- package/dist/surface-transfer/generated/protocol.d.ts +99 -0
- package/dist/surface-transfer/generated/protocol.js +7 -0
- package/dist/surface-transfer/generated/variant-fields.d.ts +2 -0
- package/dist/surface-transfer/generated/variant-fields.js +28 -0
- package/dist/surface-transfer/index.d.ts +4 -0
- package/{src/surfaces/index.ts → dist/surface-transfer/index.js} +4 -4
- package/dist/surface-transfer/validation.d.ts +11 -0
- package/dist/surface-transfer/validation.js +128 -0
- package/dist/surfaces/client.d.ts +18 -0
- package/dist/surfaces/client.js +69 -0
- package/dist/surfaces/generated/fields.d.ts +14 -0
- package/dist/surfaces/generated/fields.js +18 -0
- package/dist/surfaces/generated/protocol.d.ts +280 -0
- package/dist/surfaces/generated/protocol.js +6 -0
- package/dist/surfaces/generated/variant-fields.d.ts +2 -0
- package/dist/surfaces/generated/variant-fields.js +40 -0
- package/dist/surfaces/index.d.ts +4 -0
- package/{src/surface-transfer/index.ts → dist/surfaces/index.js} +4 -4
- package/dist/surfaces/validation.d.ts +17 -0
- package/dist/surfaces/validation.js +222 -0
- package/dist/transfer/client.d.ts +19 -0
- package/dist/transfer/client.js +50 -0
- package/dist/transfer/connection.d.ts +11 -0
- package/dist/transfer/connection.js +38 -0
- package/dist/transfer/generated/fields.d.ts +19 -0
- package/dist/transfer/generated/fields.js +23 -0
- package/dist/transfer/generated/protocol.d.ts +251 -0
- package/dist/transfer/generated/protocol.js +16 -0
- package/dist/transfer/generated/variant-fields.d.ts +2 -0
- package/dist/transfer/generated/variant-fields.js +43 -0
- package/dist/transfer/index.d.ts +6 -0
- package/dist/transfer/index.js +11 -0
- package/dist/transfer/payload.d.ts +9 -0
- package/dist/transfer/payload.js +46 -0
- package/dist/transfer/validation.d.ts +24 -0
- package/dist/transfer/validation.js +204 -0
- package/dist/update/client.d.ts +22 -0
- package/dist/update/client.js +86 -0
- package/dist/update/controller.d.ts +153 -0
- package/dist/update/controller.js +369 -0
- package/dist/update/direct.d.ts +3 -0
- package/dist/update/direct.js +3 -0
- package/dist/update/generated/fields.d.ts +14 -0
- package/dist/update/generated/fields.js +18 -0
- package/dist/update/generated/protocol.d.ts +352 -0
- package/dist/update/generated/protocol.js +14 -0
- package/dist/update/generated/variant-fields.d.ts +2 -0
- package/dist/update/generated/variant-fields.js +44 -0
- package/dist/update/index.d.ts +9 -0
- package/{src/update/index.ts → dist/update/index.js} +9 -9
- package/dist/update/ports.d.ts +33 -0
- package/dist/update/ports.js +1 -0
- package/dist/update/serialized.d.ts +15 -0
- package/dist/update/serialized.js +41 -0
- package/dist/update/validation.d.ts +25 -0
- package/dist/update/validation.js +251 -0
- package/package.json +110 -107
- package/src/agent-control/generated/protocol.ts +0 -228
- package/src/agent-control/index.ts +0 -34
- package/src/agent-control/selection.ts +0 -130
- package/src/agent-control/shim.ts +0 -1094
- package/src/bridge/direct.ts +0 -22
- package/src/bridge/generated/fields.ts +0 -33
- package/src/bridge/generated/protocol.ts +0 -273
- package/src/bridge/job.ts +0 -88
- package/src/bridge/loopback.ts +0 -66
- package/src/bridge/operation.ts +0 -136
- package/src/bridge/router.ts +0 -58
- package/src/bridge/runtime/connection.ts +0 -287
- package/src/bridge/runtime/policy.ts +0 -69
- package/src/bridge/runtime/retry.ts +0 -48
- package/src/bridge/runtime.ts +0 -3
- package/src/bridge/session.ts +0 -57
- package/src/bridge/stream/connection.ts +0 -115
- package/src/bridge/stream/source.ts +0 -57
- package/src/bridge/stream/tracker.ts +0 -109
- package/src/bridge/stream.ts +0 -6
- package/src/bridge/supervision.ts +0 -211
- package/src/bridge/validation/base.ts +0 -122
- package/src/bridge/validation/jobs.ts +0 -91
- package/src/bridge/validation/negotiation.ts +0 -227
- package/src/bridge/validation/operations.ts +0 -177
- package/src/bridge/validation/streams.ts +0 -40
- package/src/bridge/validation.ts +0 -5
- package/src/commands/client.ts +0 -133
- package/src/commands/controller.ts +0 -434
- package/src/commands/generated/fields.ts +0 -44
- package/src/commands/generated/protocol.ts +0 -903
- package/src/commands/generated/variant-fields.ts +0 -88
- package/src/commands/keyboard.ts +0 -355
- package/src/commands/physical-code.ts +0 -11
- package/src/commands/ports.ts +0 -77
- package/src/commands/projectors.ts +0 -331
- package/src/commands/validation.ts +0 -637
- package/src/config/client.ts +0 -202
- package/src/config/generated/base.ts +0 -730
- package/src/config/generated/fields.ts +0 -55
- package/src/config/generated/labels.ts +0 -30
- package/src/config/generated/restore.ts +0 -681
- package/src/config/generated/variant-fields.ts +0 -129
- package/src/config/validation/commands.ts +0 -141
- package/src/config/validation/outcomes.ts +0 -336
- package/src/config/validation/primitives.ts +0 -129
- package/src/config/validation/projection.ts +0 -323
- package/src/config/validation.ts +0 -7
- package/src/core/connection.ts +0 -356
- package/src/core/controller-lifecycle.ts +0 -144
- package/src/core/generated/identifiers.ts +0 -4
- package/src/core/identifiers.ts +0 -40
- package/src/core/index.ts +0 -11
- package/src/core/json-value.ts +0 -58
- package/src/core/listeners.ts +0 -35
- package/src/core/record.ts +0 -80
- package/src/core/transport.ts +0 -22
- package/src/core/wire-copy.ts +0 -7
- package/src/history/client.ts +0 -63
- package/src/history/controller.ts +0 -383
- package/src/history/direct.ts +0 -19
- package/src/history/generated/fields.ts +0 -19
- package/src/history/generated/protocol.ts +0 -392
- package/src/history/generated/variant-fields.ts +0 -27
- package/src/history/ports.ts +0 -34
- package/src/history/serialized.ts +0 -34
- package/src/history/validation.ts +0 -328
- package/src/history-tree/client.ts +0 -94
- package/src/history-tree/controller.ts +0 -483
- package/src/history-tree/direct.ts +0 -5
- package/src/history-tree/generated/fields.ts +0 -28
- package/src/history-tree/generated/protocol.ts +0 -747
- package/src/history-tree/generated/variant-fields.ts +0 -45
- package/src/history-tree/ports.ts +0 -50
- package/src/history-tree/serialized.ts +0 -43
- package/src/history-tree/validation.ts +0 -477
- package/src/layout/generated/protocol.ts +0 -290
- package/src/layout/generated/variant-fields.ts +0 -47
- package/src/layout/index.ts +0 -4
- package/src/layout/ratio.ts +0 -23
- package/src/layout/validation.ts +0 -176
- package/src/layout/visibility.ts +0 -29
- package/src/licence/client.ts +0 -73
- package/src/licence/controller.ts +0 -381
- package/src/licence/direct.ts +0 -5
- package/src/licence/generated/fields.ts +0 -18
- package/src/licence/generated/key-conformance.json +0 -70
- package/src/licence/generated/protocol.ts +0 -253
- package/src/licence/generated/variant-fields.ts +0 -34
- package/src/licence/index.ts +0 -14
- package/src/licence/key.ts +0 -149
- package/src/licence/ports.ts +0 -46
- package/src/licence/serialized.ts +0 -36
- package/src/licence/validation.ts +0 -317
- package/src/native-content/client.ts +0 -447
- package/src/native-content/direct.ts +0 -16
- package/src/native-content/generated/fields.ts +0 -32
- package/src/native-content/generated/protocol.ts +0 -509
- package/src/native-content/generated/variant-fields.ts +0 -77
- package/src/native-content/ports.ts +0 -41
- package/src/native-content/serialized.ts +0 -43
- package/src/native-content/validation/base.ts +0 -171
- package/src/native-content/validation/messages.ts +0 -181
- package/src/native-content/validation/state.ts +0 -402
- package/src/native-content/validation.ts +0 -7
- package/src/notifications/client.ts +0 -140
- package/src/notifications/controller.ts +0 -495
- package/src/notifications/direct.ts +0 -14
- package/src/notifications/generated/fields.ts +0 -20
- package/src/notifications/generated/labels.ts +0 -20
- package/src/notifications/generated/protocol.ts +0 -526
- package/src/notifications/generated/variant-fields.ts +0 -37
- package/src/notifications/index.ts +0 -16
- package/src/notifications/ports.ts +0 -27
- package/src/notifications/serialized.ts +0 -29
- package/src/notifications/validation.ts +0 -340
- package/src/operation/bridge.ts +0 -295
- package/src/operation/client.ts +0 -153
- package/src/operation/controller.ts +0 -291
- package/src/operation/direct.ts +0 -13
- package/src/operation/generated/fields.ts +0 -21
- package/src/operation/generated/labels.ts +0 -15
- package/src/operation/generated/protocol.ts +0 -766
- package/src/operation/generated/variant-fields.ts +0 -60
- package/src/operation/index.ts +0 -14
- package/src/operation/ports.ts +0 -31
- package/src/operation/serialized.ts +0 -38
- package/src/operation/validation.ts +0 -564
- package/src/settings/client.ts +0 -109
- package/src/settings/connection.ts +0 -228
- package/src/settings/generated/fields.ts +0 -35
- package/src/settings/generated/protocol.ts +0 -677
- package/src/settings/generated/variant-fields.ts +0 -26
- package/src/settings/registry.ts +0 -139
- package/src/settings/validation/authority.ts +0 -68
- package/src/settings/validation/command.ts +0 -146
- package/src/settings/validation/error.ts +0 -27
- package/src/settings/validation/primitives.ts +0 -152
- package/src/settings/validation/projection.ts +0 -34
- package/src/settings/validation/registry.ts +0 -124
- package/src/settings/validation.ts +0 -4
- package/src/surface-transfer/client.ts +0 -42
- package/src/surface-transfer/generated/fields.ts +0 -12
- package/src/surface-transfer/generated/protocol.ts +0 -61
- package/src/surface-transfer/generated/variant-fields.ts +0 -30
- package/src/surface-transfer/validation.ts +0 -214
- package/src/surfaces/client.ts +0 -118
- package/src/surfaces/generated/fields.ts +0 -19
- package/src/surfaces/generated/protocol.ts +0 -217
- package/src/surfaces/generated/variant-fields.ts +0 -42
- package/src/surfaces/validation.ts +0 -327
- package/src/transfer/client.ts +0 -99
- package/src/transfer/connection.ts +0 -65
- package/src/transfer/generated/fields.ts +0 -24
- package/src/transfer/generated/protocol.ts +0 -179
- package/src/transfer/generated/variant-fields.ts +0 -45
- package/src/transfer/index.ts +0 -18
- package/src/transfer/payload.ts +0 -56
- package/src/transfer/validation.ts +0 -332
- package/src/update/client.ts +0 -115
- package/src/update/controller.ts +0 -486
- package/src/update/direct.ts +0 -5
- package/src/update/generated/fields.ts +0 -19
- package/src/update/generated/protocol.ts +0 -323
- package/src/update/generated/variant-fields.ts +0 -46
- package/src/update/ports.ts +0 -53
- package/src/update/serialized.ts +0 -48
- package/src/update/validation.ts +0 -317
- /package/{src/config/names.ts → dist/config/names.js} +0 -0
- /package/{src/settings/names.ts → dist/settings/names.js} +0 -0
|
@@ -1,1094 +0,0 @@
|
|
|
1
|
-
//! In-page semantic surface for contract 022: tree, live-DOM refs, synthetic
|
|
2
|
-
//! input, wait_for predicates, and a bounded page-event ring.
|
|
3
|
-
//!
|
|
4
|
-
//! Pure page mechanics. No transport, no timers, no animation-frame waits.
|
|
5
|
-
//! Refs live as attributes on the elements they name — there is no shim-side
|
|
6
|
-
//! table that outlives the DOM. Truncation is a sentinel child with role
|
|
7
|
-
//! `truncated` (the core vocabulary has no truncation field; a silent cap
|
|
8
|
-
//! is forbidden). Synthetic events are untrusted: `isTrusted` stays false.
|
|
9
|
-
//! Every shape that crosses to Rust is a generated binding (contract 010).
|
|
10
|
-
|
|
11
|
-
import type {
|
|
12
|
-
FileInputFile,
|
|
13
|
-
PageEvent,
|
|
14
|
-
PageEventBatch,
|
|
15
|
-
PageState,
|
|
16
|
-
SemanticNode,
|
|
17
|
-
ToolError,
|
|
18
|
-
WaitPredicate,
|
|
19
|
-
} from "./generated/protocol.ts";
|
|
20
|
-
|
|
21
|
-
export const REF_ATTR = "data-longhorn-agent-ref";
|
|
22
|
-
export const REF_SEQ_ATTR = "data-longhorn-agent-ref-seq";
|
|
23
|
-
export const REF_PREFIX_GLOBAL = "__longhornAgentRefPrefix";
|
|
24
|
-
export const TRUNCATED_ROLE = "truncated";
|
|
25
|
-
export const TRUNCATED_REF = "truncated";
|
|
26
|
-
export const MAX_DEPTH = 24;
|
|
27
|
-
export const MAX_NODES = 200;
|
|
28
|
-
export const EVENT_BUFFER_LIMIT = 64;
|
|
29
|
-
export const SHIM_GLOBAL = "__longhornAgentControl";
|
|
30
|
-
|
|
31
|
-
const SKIP_TAGS = new Set([
|
|
32
|
-
"SCRIPT",
|
|
33
|
-
"STYLE",
|
|
34
|
-
"NOSCRIPT",
|
|
35
|
-
"TEMPLATE",
|
|
36
|
-
"HEAD",
|
|
37
|
-
"META",
|
|
38
|
-
"LINK",
|
|
39
|
-
"TITLE",
|
|
40
|
-
"IFRAME",
|
|
41
|
-
]);
|
|
42
|
-
|
|
43
|
-
function prop<T>(element: Element, name: string): T | undefined {
|
|
44
|
-
// DOM access is structural across webviews and test windows. Callers select each property by element role.
|
|
45
|
-
// oxlint-disable-next-line quality/no-reflect-get,typescript/no-unsafe-type-assertion -- The selected DOM interface is the contract for the property.
|
|
46
|
-
return Reflect.get(element, name) as T | undefined;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** The tool failures the page itself can report. */
|
|
50
|
-
export type ToolErrorBody = Extract<ToolError, { error: "unresolvedRef" | "unsupported" }>;
|
|
51
|
-
|
|
52
|
-
export type ShimOk<T> = { ok: true } & T;
|
|
53
|
-
export type ShimErr = { ok: false; error: ToolErrorBody };
|
|
54
|
-
export type ShimResult<T> = ShimOk<T> | ShimErr;
|
|
55
|
-
export type ActionOk = ShimOk<Record<string, never>>;
|
|
56
|
-
|
|
57
|
-
export type AgentControlApi = {
|
|
58
|
-
snapshot: () => ShimResult<{ page: PageState; root: SemanticNode }>;
|
|
59
|
-
click: (element: string) => ShimResult<Record<string, never>>;
|
|
60
|
-
type: (element: string, text: string) => ShimResult<Record<string, never>>;
|
|
61
|
-
press: (
|
|
62
|
-
key: string,
|
|
63
|
-
modifiers?: Array<string>,
|
|
64
|
-
element?: string | null,
|
|
65
|
-
) => ShimResult<Record<string, never>>;
|
|
66
|
-
scroll: (
|
|
67
|
-
deltaX: number,
|
|
68
|
-
deltaY: number,
|
|
69
|
-
element?: string | null,
|
|
70
|
-
) => ShimResult<Record<string, never>>;
|
|
71
|
-
drag: (source: string, target: string) => ShimResult<Record<string, never>>;
|
|
72
|
-
setFileInput: (element: string, files: Array<FileInputFile>) => ShimResult<Record<string, never>>;
|
|
73
|
-
waitFor: (predicate: WaitPredicate) => ShimResult<{ holds: boolean }>;
|
|
74
|
-
markAgentOrigin: () => void;
|
|
75
|
-
isAgentOriginated: () => boolean;
|
|
76
|
-
readEvents: (sinceSeq?: number, sinceEpoch?: string | null) => PageEventBatch;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export type ShimWorld = {
|
|
80
|
-
[SHIM_GLOBAL]?: AgentControlApi;
|
|
81
|
-
document: Document;
|
|
82
|
-
location: { href: string };
|
|
83
|
-
console: Pick<Console, "log" | "info" | "warn" | "error" | "debug">;
|
|
84
|
-
history: History;
|
|
85
|
-
MouseEvent: typeof MouseEvent;
|
|
86
|
-
KeyboardEvent: typeof KeyboardEvent;
|
|
87
|
-
Event: typeof Event;
|
|
88
|
-
InputEvent?: typeof InputEvent;
|
|
89
|
-
File?: typeof File;
|
|
90
|
-
DataTransfer?: typeof DataTransfer;
|
|
91
|
-
addEventListener: (
|
|
92
|
-
type: string,
|
|
93
|
-
listener: (event: Event) => void,
|
|
94
|
-
options?: boolean | { capture?: boolean },
|
|
95
|
-
) => void;
|
|
96
|
-
onunhandledrejection?: ((event: Event) => void) | null;
|
|
97
|
-
} & Record<string, unknown>;
|
|
98
|
-
|
|
99
|
-
type Budget = { nodes: number; truncated: boolean };
|
|
100
|
-
|
|
101
|
-
function unresolved(element: string): ShimResult<never> {
|
|
102
|
-
return { ok: false, error: { error: "unresolvedRef", element } };
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function unsupported(message: string): ShimResult<never> {
|
|
106
|
-
return { ok: false, error: { error: "unsupported", message } };
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function ok(): ActionOk {
|
|
110
|
-
// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- The wire success marker has no payload; the public ActionOk type represents that as Record<string, never>.
|
|
111
|
-
return { ok: true } as ActionOk;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function resolveRef(document: Document, element: string): Element | null {
|
|
115
|
-
if (element === TRUNCATED_REF || element.length === 0) {
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
return findByAttribute(document.querySelectorAll(`[${REF_ATTR}]`), REF_ATTR, element);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function findByAttribute(
|
|
122
|
-
candidates: NodeListOf<Element>,
|
|
123
|
-
attribute: string,
|
|
124
|
-
value: string,
|
|
125
|
-
): Element | null {
|
|
126
|
-
// Attribute values are data and may contain characters that CSS normalizes.
|
|
127
|
-
for (const candidate of candidates) {
|
|
128
|
-
if (candidate.getAttribute(attribute) === value) {
|
|
129
|
-
return candidate;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function refPrefix(document: Document): string {
|
|
136
|
-
const view = document.defaultView;
|
|
137
|
-
// oxlint-disable-next-line quality/no-reflect-get -- The prefix is stamped on this window by the Rust host.
|
|
138
|
-
const value: unknown = view ? Reflect.get(view, REF_PREFIX_GLOBAL) : undefined;
|
|
139
|
-
return typeof value === "string" ? value : "";
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function allocRef(document: Document): string {
|
|
143
|
-
const root = document.documentElement;
|
|
144
|
-
const current = Number(root.getAttribute(REF_SEQ_ATTR) ?? "0");
|
|
145
|
-
const next = Number.isFinite(current) ? current + 1 : 1;
|
|
146
|
-
root.setAttribute(REF_SEQ_ATTR, String(next));
|
|
147
|
-
const id = `e${next}`;
|
|
148
|
-
const prefix = refPrefix(document);
|
|
149
|
-
return prefix.length > 0 ? `${prefix}:${id}` : id;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function stamp(element: Element, document: Document): string {
|
|
153
|
-
const existing = element.getAttribute(REF_ATTR);
|
|
154
|
-
if (existing) {
|
|
155
|
-
return existing;
|
|
156
|
-
}
|
|
157
|
-
const id = allocRef(document);
|
|
158
|
-
element.setAttribute(REF_ATTR, id);
|
|
159
|
-
return id;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function computedStyle(element: Element): CSSStyleDeclaration | null {
|
|
163
|
-
const view = element.ownerDocument.defaultView;
|
|
164
|
-
return view ? view.getComputedStyle(element) : null;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function isVisible(element: Element): boolean {
|
|
168
|
-
if (element.hasAttribute("hidden")) {
|
|
169
|
-
return false;
|
|
170
|
-
}
|
|
171
|
-
if (element.getAttribute("aria-hidden") === "true") {
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
174
|
-
const style = computedStyle(element);
|
|
175
|
-
if (!style) {
|
|
176
|
-
return true;
|
|
177
|
-
}
|
|
178
|
-
return style.display !== "none" && style.visibility !== "hidden";
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Whether this element itself declares an editable host. `false` and invalid
|
|
183
|
-
* values do not: `contenteditable="false"` is how a page opts a region out.
|
|
184
|
-
*/
|
|
185
|
-
function declaresEditable(element: Element): boolean {
|
|
186
|
-
const value = element.getAttribute("contenteditable")?.toLowerCase();
|
|
187
|
-
return value === "" || value === "true" || value === "plaintext-only";
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function implicitRole(element: Element): string | null {
|
|
191
|
-
const tag = element.tagName;
|
|
192
|
-
if (tag === "A") {
|
|
193
|
-
return element.hasAttribute("href") ? "link" : null;
|
|
194
|
-
}
|
|
195
|
-
if (tag === "BUTTON") {
|
|
196
|
-
return "button";
|
|
197
|
-
}
|
|
198
|
-
if (tag === "TEXTAREA") {
|
|
199
|
-
return "textbox";
|
|
200
|
-
}
|
|
201
|
-
if (tag === "SELECT") {
|
|
202
|
-
return "combobox";
|
|
203
|
-
}
|
|
204
|
-
if (tag === "OPTION") {
|
|
205
|
-
return "option";
|
|
206
|
-
}
|
|
207
|
-
if (tag === "SUMMARY") {
|
|
208
|
-
return "button";
|
|
209
|
-
}
|
|
210
|
-
if (tag === "DETAILS") {
|
|
211
|
-
return "group";
|
|
212
|
-
}
|
|
213
|
-
if (tag === "NAV") {
|
|
214
|
-
return "navigation";
|
|
215
|
-
}
|
|
216
|
-
if (tag === "MAIN") {
|
|
217
|
-
return "main";
|
|
218
|
-
}
|
|
219
|
-
if (tag === "HEADER") {
|
|
220
|
-
return "banner";
|
|
221
|
-
}
|
|
222
|
-
if (tag === "FOOTER") {
|
|
223
|
-
return "contentinfo";
|
|
224
|
-
}
|
|
225
|
-
if (tag === "FORM") {
|
|
226
|
-
return "form";
|
|
227
|
-
}
|
|
228
|
-
if (tag === "UL" || tag === "OL") {
|
|
229
|
-
return "list";
|
|
230
|
-
}
|
|
231
|
-
if (tag === "LI") {
|
|
232
|
-
return "listitem";
|
|
233
|
-
}
|
|
234
|
-
if (tag === "TABLE") {
|
|
235
|
-
return "table";
|
|
236
|
-
}
|
|
237
|
-
if (tag === "DIALOG") {
|
|
238
|
-
return "dialog";
|
|
239
|
-
}
|
|
240
|
-
if (tag === "IMG") {
|
|
241
|
-
return "image";
|
|
242
|
-
}
|
|
243
|
-
if (
|
|
244
|
-
tag === "H1" ||
|
|
245
|
-
tag === "H2" ||
|
|
246
|
-
tag === "H3" ||
|
|
247
|
-
tag === "H4" ||
|
|
248
|
-
tag === "H5" ||
|
|
249
|
-
tag === "H6"
|
|
250
|
-
) {
|
|
251
|
-
return "heading";
|
|
252
|
-
}
|
|
253
|
-
if (tag === "INPUT") {
|
|
254
|
-
const type = (element.getAttribute("type") ?? "text").toLowerCase();
|
|
255
|
-
if (type === "checkbox") {
|
|
256
|
-
return "checkbox";
|
|
257
|
-
}
|
|
258
|
-
if (type === "radio") {
|
|
259
|
-
return "radio";
|
|
260
|
-
}
|
|
261
|
-
if (type === "number") {
|
|
262
|
-
return "spinbutton";
|
|
263
|
-
}
|
|
264
|
-
if (type === "range") {
|
|
265
|
-
return "slider";
|
|
266
|
-
}
|
|
267
|
-
if (type === "button" || type === "submit" || type === "reset" || type === "file") {
|
|
268
|
-
return "button";
|
|
269
|
-
}
|
|
270
|
-
if (type === "hidden") {
|
|
271
|
-
return null;
|
|
272
|
-
}
|
|
273
|
-
return "textbox";
|
|
274
|
-
}
|
|
275
|
-
if (declaresEditable(element)) {
|
|
276
|
-
return "textbox";
|
|
277
|
-
}
|
|
278
|
-
return null;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
function roleOf(element: Element): string | null {
|
|
282
|
-
const explicit = element.getAttribute("role");
|
|
283
|
-
if (explicit === "none" || explicit === "presentation") {
|
|
284
|
-
return null;
|
|
285
|
-
}
|
|
286
|
-
if (explicit) {
|
|
287
|
-
return explicit;
|
|
288
|
-
}
|
|
289
|
-
return implicitRole(element);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
function labelledByText(element: Element): string | undefined {
|
|
293
|
-
const ids = element.getAttribute("aria-labelledby");
|
|
294
|
-
if (!ids) {
|
|
295
|
-
return undefined;
|
|
296
|
-
}
|
|
297
|
-
const document = element.ownerDocument;
|
|
298
|
-
const text = ids
|
|
299
|
-
.split(/\s+/)
|
|
300
|
-
.map((id) => document.getElementById(id)?.textContent ?? "")
|
|
301
|
-
.join(" ")
|
|
302
|
-
.replaceAll(/\s+/g, " ")
|
|
303
|
-
.trim();
|
|
304
|
-
return text.length > 0 ? text : undefined;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
function associatedLabel(element: Element): string | undefined {
|
|
308
|
-
const id = element.id;
|
|
309
|
-
const document = element.ownerDocument;
|
|
310
|
-
if (id) {
|
|
311
|
-
const label = findByAttribute(document.querySelectorAll("label[for]"), "for", id);
|
|
312
|
-
const text = label?.textContent?.replaceAll(/\s+/g, " ").trim();
|
|
313
|
-
if (text) {
|
|
314
|
-
return text;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
const parent = element.closest("label");
|
|
318
|
-
if (parent) {
|
|
319
|
-
const text = parent.textContent?.replaceAll(/\s+/g, " ").trim();
|
|
320
|
-
if (text) {
|
|
321
|
-
return text;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
return undefined;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
function accessibleName(element: Element): string | undefined {
|
|
328
|
-
const labelled = labelledByText(element);
|
|
329
|
-
if (labelled) {
|
|
330
|
-
return labelled;
|
|
331
|
-
}
|
|
332
|
-
const aria = element.getAttribute("aria-label")?.trim();
|
|
333
|
-
if (aria) {
|
|
334
|
-
return aria;
|
|
335
|
-
}
|
|
336
|
-
const label = associatedLabel(element);
|
|
337
|
-
if (label) {
|
|
338
|
-
return label;
|
|
339
|
-
}
|
|
340
|
-
if (element.tagName === "IMG") {
|
|
341
|
-
const alt = element.getAttribute("alt")?.trim();
|
|
342
|
-
if (alt) {
|
|
343
|
-
return alt;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
const role = roleOf(element);
|
|
347
|
-
if (
|
|
348
|
-
role === "button" ||
|
|
349
|
-
role === "link" ||
|
|
350
|
-
role === "heading" ||
|
|
351
|
-
role === "option" ||
|
|
352
|
-
role === "tab" ||
|
|
353
|
-
role === "listitem"
|
|
354
|
-
) {
|
|
355
|
-
const text = element.textContent?.replaceAll(/\s+/g, " ").trim();
|
|
356
|
-
if (text) {
|
|
357
|
-
return text;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
const title = element.getAttribute("title")?.trim();
|
|
361
|
-
if (title) {
|
|
362
|
-
return title;
|
|
363
|
-
}
|
|
364
|
-
const placeholder = element.getAttribute("placeholder")?.trim();
|
|
365
|
-
if (placeholder) {
|
|
366
|
-
return placeholder;
|
|
367
|
-
}
|
|
368
|
-
return undefined;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
function valueOf(element: Element): string | undefined {
|
|
372
|
-
const now = element.getAttribute("aria-valuenow");
|
|
373
|
-
if (now) {
|
|
374
|
-
return now;
|
|
375
|
-
}
|
|
376
|
-
if (element.tagName === "INPUT") {
|
|
377
|
-
const type = (prop<string>(element, "type") ?? "text").toLowerCase();
|
|
378
|
-
if (type === "checkbox" || type === "radio") {
|
|
379
|
-
return undefined;
|
|
380
|
-
}
|
|
381
|
-
return prop<string>(element, "value");
|
|
382
|
-
}
|
|
383
|
-
if (element.tagName === "TEXTAREA") {
|
|
384
|
-
return prop<string>(element, "value");
|
|
385
|
-
}
|
|
386
|
-
if (element.tagName === "SELECT") {
|
|
387
|
-
const selected = prop<ArrayLike<Element>>(element, "selectedOptions");
|
|
388
|
-
const first = selected && selected.length > 0 ? selected[0] : undefined;
|
|
389
|
-
return first?.textContent?.trim() ?? prop<string>(element, "value");
|
|
390
|
-
}
|
|
391
|
-
if (declaresEditable(element)) {
|
|
392
|
-
return element.textContent ?? undefined;
|
|
393
|
-
}
|
|
394
|
-
return undefined;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
function statesOf(element: Element, document: Document): Array<string> {
|
|
398
|
-
const states: Array<string> = [];
|
|
399
|
-
if (isVisible(element)) {
|
|
400
|
-
states.push("visible");
|
|
401
|
-
}
|
|
402
|
-
if (
|
|
403
|
-
element.hasAttribute("disabled") ||
|
|
404
|
-
element.getAttribute("aria-disabled") === "true" ||
|
|
405
|
-
prop<boolean>(element, "disabled") === true
|
|
406
|
-
) {
|
|
407
|
-
states.push("disabled");
|
|
408
|
-
}
|
|
409
|
-
if (
|
|
410
|
-
prop<boolean>(element, "checked") === true ||
|
|
411
|
-
element.getAttribute("aria-checked") === "true"
|
|
412
|
-
) {
|
|
413
|
-
states.push("checked");
|
|
414
|
-
}
|
|
415
|
-
if (document.activeElement === element) {
|
|
416
|
-
states.push("focused");
|
|
417
|
-
}
|
|
418
|
-
if (element.getAttribute("aria-expanded") === "true") {
|
|
419
|
-
states.push("expanded");
|
|
420
|
-
}
|
|
421
|
-
if (element.getAttribute("aria-pressed") === "true") {
|
|
422
|
-
states.push("pressed");
|
|
423
|
-
}
|
|
424
|
-
if (
|
|
425
|
-
element.getAttribute("aria-selected") === "true" ||
|
|
426
|
-
prop<boolean>(element, "selected") === true
|
|
427
|
-
) {
|
|
428
|
-
states.push("selected");
|
|
429
|
-
}
|
|
430
|
-
if (
|
|
431
|
-
element.getAttribute("aria-readonly") === "true" ||
|
|
432
|
-
prop<boolean>(element, "readOnly") === true
|
|
433
|
-
) {
|
|
434
|
-
states.push("readonly");
|
|
435
|
-
}
|
|
436
|
-
return states;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
function isInteresting(element: Element): boolean {
|
|
440
|
-
if (SKIP_TAGS.has(element.tagName)) {
|
|
441
|
-
return false;
|
|
442
|
-
}
|
|
443
|
-
// Labels contribute their text to the control's name; they are not nodes.
|
|
444
|
-
if (element.tagName === "LABEL") {
|
|
445
|
-
return false;
|
|
446
|
-
}
|
|
447
|
-
if (roleOf(element)) {
|
|
448
|
-
return true;
|
|
449
|
-
}
|
|
450
|
-
if (accessibleName(element)) {
|
|
451
|
-
return true;
|
|
452
|
-
}
|
|
453
|
-
if (element.tagName === "INPUT") {
|
|
454
|
-
return true;
|
|
455
|
-
}
|
|
456
|
-
if (element.hasAttribute("tabindex")) {
|
|
457
|
-
return true;
|
|
458
|
-
}
|
|
459
|
-
return false;
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
function truncatedNode(): SemanticNode {
|
|
463
|
-
return {
|
|
464
|
-
elementRef: TRUNCATED_REF,
|
|
465
|
-
role: TRUNCATED_ROLE,
|
|
466
|
-
name: null,
|
|
467
|
-
value: null,
|
|
468
|
-
states: [],
|
|
469
|
-
children: [],
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
function walk(
|
|
474
|
-
element: Element,
|
|
475
|
-
document: Document,
|
|
476
|
-
depth: number,
|
|
477
|
-
budget: Budget,
|
|
478
|
-
): Array<SemanticNode> {
|
|
479
|
-
if (SKIP_TAGS.has(element.tagName) || !isVisible(element)) {
|
|
480
|
-
return [];
|
|
481
|
-
}
|
|
482
|
-
const interesting = isInteresting(element) || depth === 0;
|
|
483
|
-
if (!interesting) {
|
|
484
|
-
const promoted: Array<SemanticNode> = [];
|
|
485
|
-
for (const child of Array.from(element.children)) {
|
|
486
|
-
promoted.push(...walk(child, document, depth, budget));
|
|
487
|
-
if (budget.truncated) {
|
|
488
|
-
break;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
return promoted;
|
|
492
|
-
}
|
|
493
|
-
if (budget.nodes >= MAX_NODES) {
|
|
494
|
-
budget.truncated = true;
|
|
495
|
-
return [truncatedNode()];
|
|
496
|
-
}
|
|
497
|
-
budget.nodes += 1;
|
|
498
|
-
const node: SemanticNode = {
|
|
499
|
-
elementRef: stamp(element, document),
|
|
500
|
-
role: roleOf(element) ?? element.tagName.toLowerCase(),
|
|
501
|
-
name: accessibleName(element) ?? null,
|
|
502
|
-
// An empty value is reported the same way as no value.
|
|
503
|
-
value: valueOf(element) || null,
|
|
504
|
-
states: statesOf(element, document),
|
|
505
|
-
children: [],
|
|
506
|
-
};
|
|
507
|
-
if (depth >= MAX_DEPTH) {
|
|
508
|
-
if (element.children.length > 0) {
|
|
509
|
-
budget.truncated = true;
|
|
510
|
-
node.children.push(truncatedNode());
|
|
511
|
-
}
|
|
512
|
-
return [node];
|
|
513
|
-
}
|
|
514
|
-
for (const child of Array.from(element.children)) {
|
|
515
|
-
if (budget.nodes >= MAX_NODES) {
|
|
516
|
-
budget.truncated = true;
|
|
517
|
-
node.children.push(truncatedNode());
|
|
518
|
-
break;
|
|
519
|
-
}
|
|
520
|
-
node.children.push(...walk(child, document, depth + 1, budget));
|
|
521
|
-
}
|
|
522
|
-
return [node];
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
function snapshot(world: ShimWorld): ShimResult<{ page: PageState; root: SemanticNode }> {
|
|
526
|
-
const document = world.document;
|
|
527
|
-
const rootElement = document.body ?? document.documentElement;
|
|
528
|
-
const budget: Budget = { nodes: 0, truncated: false };
|
|
529
|
-
const [root] = walk(rootElement, document, 0, budget);
|
|
530
|
-
return {
|
|
531
|
-
ok: true,
|
|
532
|
-
page: { url: world.location.href, title: document.title },
|
|
533
|
-
root: root ?? truncatedNode(),
|
|
534
|
-
};
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
function centerOf(element: Element) {
|
|
538
|
-
const rect = element.getBoundingClientRect();
|
|
539
|
-
return { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 };
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
function dispatchMouse(
|
|
543
|
-
world: ShimWorld,
|
|
544
|
-
element: Element,
|
|
545
|
-
type: string,
|
|
546
|
-
point?: { x: number; y: number },
|
|
547
|
-
): void {
|
|
548
|
-
const coords = point ?? centerOf(element);
|
|
549
|
-
element.dispatchEvent(
|
|
550
|
-
new world.MouseEvent(type, {
|
|
551
|
-
bubbles: true,
|
|
552
|
-
cancelable: true,
|
|
553
|
-
composed: true,
|
|
554
|
-
button: 0,
|
|
555
|
-
clientX: coords.x,
|
|
556
|
-
clientY: coords.y,
|
|
557
|
-
screenX: coords.x,
|
|
558
|
-
screenY: coords.y,
|
|
559
|
-
}),
|
|
560
|
-
);
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
function dispatchKey(
|
|
564
|
-
world: ShimWorld,
|
|
565
|
-
element: Element,
|
|
566
|
-
type: string,
|
|
567
|
-
key: string,
|
|
568
|
-
modifiers: Array<string>,
|
|
569
|
-
): boolean {
|
|
570
|
-
const event = new world.KeyboardEvent(type, {
|
|
571
|
-
bubbles: true,
|
|
572
|
-
cancelable: true,
|
|
573
|
-
composed: true,
|
|
574
|
-
key,
|
|
575
|
-
altKey: modifiers.includes("alt"),
|
|
576
|
-
ctrlKey: modifiers.includes("control"),
|
|
577
|
-
metaKey: modifiers.includes("meta"),
|
|
578
|
-
shiftKey: modifiers.includes("shift"),
|
|
579
|
-
});
|
|
580
|
-
return element.dispatchEvent(event);
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
function dispatchInput(world: ShimWorld, element: Element, data: string): void {
|
|
584
|
-
const InputEvent = world.InputEvent;
|
|
585
|
-
if (InputEvent) {
|
|
586
|
-
element.dispatchEvent(
|
|
587
|
-
new InputEvent("input", {
|
|
588
|
-
bubbles: true,
|
|
589
|
-
cancelable: true,
|
|
590
|
-
data,
|
|
591
|
-
inputType: "insertText",
|
|
592
|
-
}),
|
|
593
|
-
);
|
|
594
|
-
return;
|
|
595
|
-
}
|
|
596
|
-
element.dispatchEvent(new world.Event("input", { bubbles: true }));
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
function focus(element: Element): void {
|
|
600
|
-
const focusFn = prop<(this: Element) => void>(element, "focus");
|
|
601
|
-
focusFn?.call(element);
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
function click(world: ShimWorld, element: string): ShimResult<Record<string, never>> {
|
|
605
|
-
const node = resolveRef(world.document, element);
|
|
606
|
-
if (!node) {
|
|
607
|
-
return unresolved(element);
|
|
608
|
-
}
|
|
609
|
-
focus(node);
|
|
610
|
-
dispatchMouse(world, node, "pointerdown");
|
|
611
|
-
dispatchMouse(world, node, "mousedown");
|
|
612
|
-
dispatchMouse(world, node, "pointerup");
|
|
613
|
-
dispatchMouse(world, node, "mouseup");
|
|
614
|
-
// Native click() fires the click event and runs default actions
|
|
615
|
-
// (submit, checkbox toggle, link navigation) that a synthetic MouseEvent
|
|
616
|
-
// does not. isTrusted stays false.
|
|
617
|
-
const nativeClick = prop<(this: Element) => void>(node, "click");
|
|
618
|
-
if (nativeClick) {
|
|
619
|
-
nativeClick.call(node);
|
|
620
|
-
} else {
|
|
621
|
-
dispatchMouse(world, node, "click");
|
|
622
|
-
}
|
|
623
|
-
return ok();
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
/** Input types whose value is not typed text. Keys reach them; nothing is inserted. */
|
|
627
|
-
const UNTYPED_INPUT_TYPES = new Set([
|
|
628
|
-
"button",
|
|
629
|
-
"checkbox",
|
|
630
|
-
"hidden",
|
|
631
|
-
"image",
|
|
632
|
-
"radio",
|
|
633
|
-
"reset",
|
|
634
|
-
"submit",
|
|
635
|
-
]);
|
|
636
|
-
|
|
637
|
-
/** Input types that hold one structured value, which typed text replaces. */
|
|
638
|
-
const REPLACED_INPUT_TYPES = new Set([
|
|
639
|
-
"color",
|
|
640
|
-
"date",
|
|
641
|
-
"datetime-local",
|
|
642
|
-
"month",
|
|
643
|
-
"range",
|
|
644
|
-
"time",
|
|
645
|
-
"week",
|
|
646
|
-
]);
|
|
647
|
-
|
|
648
|
-
function inputType(element: Element): string {
|
|
649
|
-
return (prop<string>(element, "type") ?? element.getAttribute("type") ?? "text").toLowerCase();
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
/**
|
|
653
|
-
* Returns the function that types one character into the element, which
|
|
654
|
-
* answers whether the element took it.
|
|
655
|
-
*/
|
|
656
|
-
function textInserter(element: Element): (text: string) => boolean {
|
|
657
|
-
if (element.tagName !== "INPUT" && element.tagName !== "TEXTAREA") {
|
|
658
|
-
return (text) => {
|
|
659
|
-
if (!declaresEditable(element) && prop<boolean>(element, "isContentEditable") !== true) {
|
|
660
|
-
return false;
|
|
661
|
-
}
|
|
662
|
-
element.textContent = `${element.textContent ?? ""}${text}`;
|
|
663
|
-
return true;
|
|
664
|
-
};
|
|
665
|
-
}
|
|
666
|
-
const type = element.tagName === "INPUT" ? inputType(element) : "textarea";
|
|
667
|
-
if (UNTYPED_INPUT_TYPES.has(type)) {
|
|
668
|
-
return () => false;
|
|
669
|
-
}
|
|
670
|
-
const read = () => prop<string>(element, "value") ?? "";
|
|
671
|
-
// Types without a selection (email, number, date, ...) report a null
|
|
672
|
-
// `selectionStart` and throw from `setSelectionRange`. They also blank a value
|
|
673
|
-
// that is not complete yet, so the typed text is held here and assigned whole.
|
|
674
|
-
let held = REPLACED_INPUT_TYPES.has(type) ? "" : read();
|
|
675
|
-
let seen = read();
|
|
676
|
-
return (text) => {
|
|
677
|
-
const current = read();
|
|
678
|
-
const start = prop<number | null>(element, "selectionStart");
|
|
679
|
-
if (typeof start !== "number") {
|
|
680
|
-
// The page rewrote the field between keys; continue from what it wrote.
|
|
681
|
-
if (current !== seen) {
|
|
682
|
-
held = current;
|
|
683
|
-
}
|
|
684
|
-
held += text;
|
|
685
|
-
Object.assign(element, { value: held });
|
|
686
|
-
seen = read();
|
|
687
|
-
return true;
|
|
688
|
-
}
|
|
689
|
-
const end = prop<number | null>(element, "selectionEnd") ?? start;
|
|
690
|
-
Object.assign(element, { value: `${current.slice(0, start)}${text}${current.slice(end)}` });
|
|
691
|
-
const cursor = start + text.length;
|
|
692
|
-
prop<(this: Element, start: number, end: number) => void>(element, "setSelectionRange")?.call(
|
|
693
|
-
element,
|
|
694
|
-
cursor,
|
|
695
|
-
cursor,
|
|
696
|
-
);
|
|
697
|
-
return true;
|
|
698
|
-
};
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
function typeInto(
|
|
702
|
-
world: ShimWorld,
|
|
703
|
-
element: string,
|
|
704
|
-
text: string,
|
|
705
|
-
): ShimResult<Record<string, never>> {
|
|
706
|
-
const node = resolveRef(world.document, element);
|
|
707
|
-
if (!node) {
|
|
708
|
-
return unresolved(element);
|
|
709
|
-
}
|
|
710
|
-
if (node.tagName === "INPUT" && inputType(node) === "file") {
|
|
711
|
-
return unsupported("type cannot set an input type=file; use set_file_input");
|
|
712
|
-
}
|
|
713
|
-
focus(node);
|
|
714
|
-
const insert = textInserter(node);
|
|
715
|
-
let changed = false;
|
|
716
|
-
for (const char of text) {
|
|
717
|
-
// A cancelled keydown suppresses the text, as it does for a real key.
|
|
718
|
-
if (dispatchKey(world, node, "keydown", char, []) && insert(char)) {
|
|
719
|
-
changed = true;
|
|
720
|
-
dispatchInput(world, node, char);
|
|
721
|
-
}
|
|
722
|
-
dispatchKey(world, node, "keyup", char, []);
|
|
723
|
-
}
|
|
724
|
-
if (changed) {
|
|
725
|
-
node.dispatchEvent(new world.Event("change", { bubbles: true }));
|
|
726
|
-
}
|
|
727
|
-
return ok();
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
function press(
|
|
731
|
-
world: ShimWorld,
|
|
732
|
-
key: string,
|
|
733
|
-
modifiers: Array<string> = [],
|
|
734
|
-
element?: string | null,
|
|
735
|
-
): ShimResult<Record<string, never>> {
|
|
736
|
-
let node: Element | null;
|
|
737
|
-
if (element) {
|
|
738
|
-
node = resolveRef(world.document, element);
|
|
739
|
-
if (!node) {
|
|
740
|
-
return unresolved(element);
|
|
741
|
-
}
|
|
742
|
-
} else {
|
|
743
|
-
node = world.document.activeElement ?? world.document.body ?? world.document.documentElement;
|
|
744
|
-
}
|
|
745
|
-
focus(node);
|
|
746
|
-
dispatchKey(world, node, "keydown", key, modifiers);
|
|
747
|
-
dispatchKey(world, node, "keyup", key, modifiers);
|
|
748
|
-
return ok();
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
function scroll(
|
|
752
|
-
world: ShimWorld,
|
|
753
|
-
deltaX: number,
|
|
754
|
-
deltaY: number,
|
|
755
|
-
element?: string | null,
|
|
756
|
-
): ShimResult<Record<string, never>> {
|
|
757
|
-
if (element) {
|
|
758
|
-
const node = resolveRef(world.document, element);
|
|
759
|
-
if (!node) {
|
|
760
|
-
return unresolved(element);
|
|
761
|
-
}
|
|
762
|
-
node.scrollTop += deltaY;
|
|
763
|
-
node.scrollLeft += deltaX;
|
|
764
|
-
node.dispatchEvent(new world.Event("scroll", { bubbles: true }));
|
|
765
|
-
return ok();
|
|
766
|
-
}
|
|
767
|
-
const scrolling = world.document.scrollingElement ?? world.document.documentElement;
|
|
768
|
-
scrolling.scrollTop += deltaY;
|
|
769
|
-
scrolling.scrollLeft += deltaX;
|
|
770
|
-
world.document.dispatchEvent(new world.Event("scroll", { bubbles: true }));
|
|
771
|
-
return ok();
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
function drag(
|
|
775
|
-
world: ShimWorld,
|
|
776
|
-
sourceRef: string,
|
|
777
|
-
targetRef: string,
|
|
778
|
-
): ShimResult<Record<string, never>> {
|
|
779
|
-
const source = resolveRef(world.document, sourceRef);
|
|
780
|
-
if (!source) {
|
|
781
|
-
return unresolved(sourceRef);
|
|
782
|
-
}
|
|
783
|
-
const target = resolveRef(world.document, targetRef);
|
|
784
|
-
if (!target) {
|
|
785
|
-
return unresolved(targetRef);
|
|
786
|
-
}
|
|
787
|
-
const from = centerOf(source);
|
|
788
|
-
const to = centerOf(target);
|
|
789
|
-
// Two-point untrusted path: pointer/mouse at the source center, then the
|
|
790
|
-
// target center. There is no interpolated pixel trail — drag is ref-to-ref.
|
|
791
|
-
dispatchMouse(world, source, "pointerdown", from);
|
|
792
|
-
dispatchMouse(world, source, "mousedown", from);
|
|
793
|
-
dispatchMouse(world, target, "pointermove", to);
|
|
794
|
-
dispatchMouse(world, target, "mousemove", to);
|
|
795
|
-
// Only the two methods are read, so a page without DataTransfer gets a stand-in with just those.
|
|
796
|
-
const transfer: Pick<DataTransfer, "setData" | "getData"> = world.DataTransfer
|
|
797
|
-
? new world.DataTransfer()
|
|
798
|
-
: { setData() {}, getData: () => "" };
|
|
799
|
-
const dragEvent = (type: string, current: Element, point: { x: number; y: number }) => {
|
|
800
|
-
const event = new world.MouseEvent(type, {
|
|
801
|
-
bubbles: true,
|
|
802
|
-
cancelable: true,
|
|
803
|
-
composed: true,
|
|
804
|
-
clientX: point.x,
|
|
805
|
-
clientY: point.y,
|
|
806
|
-
});
|
|
807
|
-
Object.defineProperty(event, "dataTransfer", { value: transfer });
|
|
808
|
-
current.dispatchEvent(event);
|
|
809
|
-
};
|
|
810
|
-
dragEvent("dragstart", source, from);
|
|
811
|
-
dragEvent("dragenter", target, to);
|
|
812
|
-
dragEvent("dragover", target, to);
|
|
813
|
-
dragEvent("drop", target, to);
|
|
814
|
-
dragEvent("dragend", source, from);
|
|
815
|
-
dispatchMouse(world, target, "pointerup", to);
|
|
816
|
-
dispatchMouse(world, target, "mouseup", to);
|
|
817
|
-
return ok();
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
function decodeBase64(content: string): Uint8Array<ArrayBuffer> | null {
|
|
821
|
-
try {
|
|
822
|
-
const binary = atob(content);
|
|
823
|
-
const bytes = new Uint8Array(binary.length);
|
|
824
|
-
for (let i = 0; i < binary.length; i += 1) {
|
|
825
|
-
bytes[i] = binary.charCodeAt(i);
|
|
826
|
-
}
|
|
827
|
-
return bytes;
|
|
828
|
-
} catch {
|
|
829
|
-
return null;
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
function acceptMatches(fileName: string, mediaType: string, accept: string): boolean {
|
|
834
|
-
const tokens = accept
|
|
835
|
-
.split(",")
|
|
836
|
-
.map((token) => token.trim())
|
|
837
|
-
.filter((token) => token.length > 0);
|
|
838
|
-
if (tokens.length === 0) {
|
|
839
|
-
return true;
|
|
840
|
-
}
|
|
841
|
-
const name = fileName.toLowerCase();
|
|
842
|
-
const type = mediaType.toLowerCase();
|
|
843
|
-
return tokens.some((token) => {
|
|
844
|
-
const needle = token.toLowerCase();
|
|
845
|
-
if (needle.startsWith(".")) {
|
|
846
|
-
return name.endsWith(needle);
|
|
847
|
-
}
|
|
848
|
-
if (needle.endsWith("/*")) {
|
|
849
|
-
return type.startsWith(needle.slice(0, -1));
|
|
850
|
-
}
|
|
851
|
-
return type === needle;
|
|
852
|
-
});
|
|
853
|
-
}
|
|
854
|
-
|
|
855
|
-
function setFileInput(
|
|
856
|
-
world: ShimWorld,
|
|
857
|
-
element: string,
|
|
858
|
-
files: Array<FileInputFile>,
|
|
859
|
-
): ShimResult<Record<string, never>> {
|
|
860
|
-
const node = resolveRef(world.document, element);
|
|
861
|
-
if (!node) {
|
|
862
|
-
return unresolved(element);
|
|
863
|
-
}
|
|
864
|
-
if (node.tagName !== "INPUT" || inputType(node) !== "file") {
|
|
865
|
-
return unsupported("set_file_input requires an input type=file");
|
|
866
|
-
}
|
|
867
|
-
if (!Array.isArray(files) || files.length === 0) {
|
|
868
|
-
return unsupported("set_file_input requires at least one file");
|
|
869
|
-
}
|
|
870
|
-
const multiple = prop<boolean>(node, "multiple") === true || node.hasAttribute("multiple");
|
|
871
|
-
if (files.length > 1 && !multiple) {
|
|
872
|
-
return unsupported("set_file_input received multiple files for an input without multiple");
|
|
873
|
-
}
|
|
874
|
-
// Constructed in the page's own realm, or the input refuses the FileList.
|
|
875
|
-
const { File: FileCtor, DataTransfer: DataTransferCtor } = world;
|
|
876
|
-
if (!FileCtor || !DataTransferCtor) {
|
|
877
|
-
return unsupported("set_file_input needs File and DataTransfer in the page");
|
|
878
|
-
}
|
|
879
|
-
const accept = node.getAttribute("accept") ?? "";
|
|
880
|
-
const transfer = new DataTransferCtor();
|
|
881
|
-
for (const file of files) {
|
|
882
|
-
if (!file.name) {
|
|
883
|
-
return unsupported("set_file_input file name must be non-empty");
|
|
884
|
-
}
|
|
885
|
-
const bytes = decodeBase64(file.contentBase64);
|
|
886
|
-
if (!bytes) {
|
|
887
|
-
return unsupported(`set_file_input file ${JSON.stringify(file.name)} is not valid base64`);
|
|
888
|
-
}
|
|
889
|
-
const mediaType = file.mediaType ?? "";
|
|
890
|
-
if (!acceptMatches(file.name, mediaType, accept)) {
|
|
891
|
-
return unsupported(`set_file_input file ${JSON.stringify(file.name)} does not match accept`);
|
|
892
|
-
}
|
|
893
|
-
transfer.items.add(
|
|
894
|
-
new FileCtor([bytes], file.name, mediaType ? { type: mediaType } : undefined),
|
|
895
|
-
);
|
|
896
|
-
}
|
|
897
|
-
try {
|
|
898
|
-
Object.assign(node, { files: transfer.files });
|
|
899
|
-
} catch (error) {
|
|
900
|
-
return unsupported(
|
|
901
|
-
`the page refused FileList assignment from a constructed DataTransfer: ${String(error)}`,
|
|
902
|
-
);
|
|
903
|
-
}
|
|
904
|
-
const assigned = prop<ArrayLike<unknown>>(node, "files");
|
|
905
|
-
if (!assigned || assigned.length !== files.length) {
|
|
906
|
-
return unsupported("the page refused FileList assignment from a constructed DataTransfer");
|
|
907
|
-
}
|
|
908
|
-
node.dispatchEvent(new world.Event("input", { bubbles: true }));
|
|
909
|
-
node.dispatchEvent(new world.Event("change", { bubbles: true }));
|
|
910
|
-
return ok();
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
function waitFor(world: ShimWorld, predicate: WaitPredicate): ShimResult<{ holds: boolean }> {
|
|
914
|
-
switch (predicate.predicate) {
|
|
915
|
-
case "refResolve":
|
|
916
|
-
return { ok: true, holds: resolveRef(world.document, predicate.element) !== null };
|
|
917
|
-
case "refAbsent":
|
|
918
|
-
return { ok: true, holds: resolveRef(world.document, predicate.element) === null };
|
|
919
|
-
case "pageUrlContains":
|
|
920
|
-
return { ok: true, holds: world.location.href.includes(predicate.needle) };
|
|
921
|
-
case "pageTitleContains":
|
|
922
|
-
return { ok: true, holds: world.document.title.includes(predicate.needle) };
|
|
923
|
-
default:
|
|
924
|
-
return {
|
|
925
|
-
ok: false,
|
|
926
|
-
error: {
|
|
927
|
-
error: "unsupported",
|
|
928
|
-
message: "wait_for admits only the four DOM-relative predicates",
|
|
929
|
-
},
|
|
930
|
-
};
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
/**
|
|
935
|
-
* Text for a value the page logged or threw. `String` throws for a
|
|
936
|
-
* prototype-less object or a throwing `toString`, and that must not escape into
|
|
937
|
-
* the page's own `console` call.
|
|
938
|
-
*/
|
|
939
|
-
function describeValue(value: unknown): string {
|
|
940
|
-
try {
|
|
941
|
-
return String(value);
|
|
942
|
-
} catch {
|
|
943
|
-
return "[unprintable]";
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
function installEventRing(world: ShimWorld): AgentControlApi["readEvents"] {
|
|
948
|
-
const existing = world[SHIM_GLOBAL];
|
|
949
|
-
if (existing) {
|
|
950
|
-
return existing.readEvents.bind(existing);
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
const epoch =
|
|
954
|
-
typeof crypto !== "undefined" && typeof crypto.randomUUID === "function"
|
|
955
|
-
? crypto.randomUUID()
|
|
956
|
-
: `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
957
|
-
const ring: Array<PageEvent> = [];
|
|
958
|
-
let nextSeq = 1;
|
|
959
|
-
let dropped = 0;
|
|
960
|
-
|
|
961
|
-
const push = (event: PageEvent) => {
|
|
962
|
-
const recorded = event;
|
|
963
|
-
nextSeq += 1;
|
|
964
|
-
if (ring.length >= EVENT_BUFFER_LIMIT) {
|
|
965
|
-
ring.shift();
|
|
966
|
-
dropped += 1;
|
|
967
|
-
}
|
|
968
|
-
ring.push(recorded);
|
|
969
|
-
};
|
|
970
|
-
|
|
971
|
-
const wrap = (level: "log" | "info" | "warn" | "error" | "debug") => {
|
|
972
|
-
const original = world.console[level]?.bind(world.console);
|
|
973
|
-
world.console[level] = (...args: Array<unknown>) => {
|
|
974
|
-
push({
|
|
975
|
-
seq: nextSeq,
|
|
976
|
-
kind: "console",
|
|
977
|
-
level,
|
|
978
|
-
text: args.map(describeValue).join(" "),
|
|
979
|
-
});
|
|
980
|
-
original?.(...args);
|
|
981
|
-
};
|
|
982
|
-
};
|
|
983
|
-
wrap("log");
|
|
984
|
-
wrap("info");
|
|
985
|
-
wrap("warn");
|
|
986
|
-
wrap("error");
|
|
987
|
-
wrap("debug");
|
|
988
|
-
|
|
989
|
-
world.addEventListener("error", (event) => {
|
|
990
|
-
const message =
|
|
991
|
-
"message" in event && typeof event.message === "string"
|
|
992
|
-
? event.message
|
|
993
|
-
: describeValue(event);
|
|
994
|
-
push({ seq: nextSeq, kind: "error", message });
|
|
995
|
-
});
|
|
996
|
-
world.addEventListener("unhandledrejection", (event) => {
|
|
997
|
-
const reason = "reason" in event ? describeValue(event.reason) : "unhandledrejection";
|
|
998
|
-
push({ seq: nextSeq, kind: "error", message: reason });
|
|
999
|
-
});
|
|
1000
|
-
|
|
1001
|
-
const notifyNavigation = () => {
|
|
1002
|
-
push({ seq: nextSeq, kind: "navigation", url: world.location.href });
|
|
1003
|
-
};
|
|
1004
|
-
// Record the initial document load so full-document navigations and reloads
|
|
1005
|
-
// are observable through `longhorn://agent-control/navigation` as seq 1.
|
|
1006
|
-
notifyNavigation();
|
|
1007
|
-
world.addEventListener("hashchange", notifyNavigation);
|
|
1008
|
-
world.addEventListener("popstate", notifyNavigation);
|
|
1009
|
-
const history = world.history;
|
|
1010
|
-
const pushState = history.pushState.bind(history);
|
|
1011
|
-
const replaceState = history.replaceState.bind(history);
|
|
1012
|
-
history.pushState = ((...args: Parameters<History["pushState"]>) => {
|
|
1013
|
-
pushState(...args);
|
|
1014
|
-
notifyNavigation();
|
|
1015
|
-
}) as History["pushState"];
|
|
1016
|
-
history.replaceState = ((...args: Parameters<History["replaceState"]>) => {
|
|
1017
|
-
replaceState(...args);
|
|
1018
|
-
notifyNavigation();
|
|
1019
|
-
}) as History["replaceState"];
|
|
1020
|
-
|
|
1021
|
-
return (sinceSeq = 0, sinceEpoch?: string | null) => {
|
|
1022
|
-
const effectiveSince =
|
|
1023
|
-
sinceEpoch !== undefined && sinceEpoch !== null && sinceEpoch !== epoch ? 0 : sinceSeq;
|
|
1024
|
-
return {
|
|
1025
|
-
epoch,
|
|
1026
|
-
events: ring.filter((event) => event.seq > effectiveSince),
|
|
1027
|
-
nextSeq,
|
|
1028
|
-
dropped,
|
|
1029
|
-
};
|
|
1030
|
-
};
|
|
1031
|
-
}
|
|
1032
|
-
|
|
1033
|
-
function installOriginTracking(
|
|
1034
|
-
world: ShimWorld,
|
|
1035
|
-
): Pick<AgentControlApi, "markAgentOrigin" | "isAgentOriginated"> {
|
|
1036
|
-
let agentOriginSeq = 0;
|
|
1037
|
-
let humanOriginSeq = 0;
|
|
1038
|
-
const markHuman = (event: Event) => {
|
|
1039
|
-
if (event.isTrusted) {
|
|
1040
|
-
humanOriginSeq = agentOriginSeq + 1;
|
|
1041
|
-
}
|
|
1042
|
-
};
|
|
1043
|
-
world.addEventListener("pointerdown", markHuman, true);
|
|
1044
|
-
world.addEventListener("keydown", markHuman, true);
|
|
1045
|
-
world.addEventListener("click", markHuman, true);
|
|
1046
|
-
return {
|
|
1047
|
-
markAgentOrigin: () => {
|
|
1048
|
-
agentOriginSeq = humanOriginSeq + 1;
|
|
1049
|
-
},
|
|
1050
|
-
isAgentOriginated: () => agentOriginSeq > humanOriginSeq,
|
|
1051
|
-
};
|
|
1052
|
-
}
|
|
1053
|
-
|
|
1054
|
-
export function installAgentControlShim(world: ShimWorld): AgentControlApi {
|
|
1055
|
-
const existing = world[SHIM_GLOBAL];
|
|
1056
|
-
if (existing) {
|
|
1057
|
-
return existing;
|
|
1058
|
-
}
|
|
1059
|
-
const readEvents = installEventRing(world);
|
|
1060
|
-
const origin = installOriginTracking(world);
|
|
1061
|
-
const api: AgentControlApi = {
|
|
1062
|
-
snapshot: () => snapshot(world),
|
|
1063
|
-
click: (element) => {
|
|
1064
|
-
origin.markAgentOrigin();
|
|
1065
|
-
return click(world, element);
|
|
1066
|
-
},
|
|
1067
|
-
type: (element, text) => {
|
|
1068
|
-
origin.markAgentOrigin();
|
|
1069
|
-
return typeInto(world, element, text);
|
|
1070
|
-
},
|
|
1071
|
-
press: (key, modifiers, element) => {
|
|
1072
|
-
origin.markAgentOrigin();
|
|
1073
|
-
return press(world, key, modifiers, element);
|
|
1074
|
-
},
|
|
1075
|
-
scroll: (deltaX, deltaY, element) => {
|
|
1076
|
-
origin.markAgentOrigin();
|
|
1077
|
-
return scroll(world, deltaX, deltaY, element);
|
|
1078
|
-
},
|
|
1079
|
-
drag: (source, target) => {
|
|
1080
|
-
origin.markAgentOrigin();
|
|
1081
|
-
return drag(world, source, target);
|
|
1082
|
-
},
|
|
1083
|
-
setFileInput: (element, files) => {
|
|
1084
|
-
origin.markAgentOrigin();
|
|
1085
|
-
return setFileInput(world, element, files);
|
|
1086
|
-
},
|
|
1087
|
-
waitFor: (predicate) => waitFor(world, predicate),
|
|
1088
|
-
markAgentOrigin: origin.markAgentOrigin,
|
|
1089
|
-
isAgentOriginated: origin.isAgentOriginated,
|
|
1090
|
-
readEvents,
|
|
1091
|
-
};
|
|
1092
|
-
world[SHIM_GLOBAL] = api;
|
|
1093
|
-
return api;
|
|
1094
|
-
}
|