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