pi-agent-browser-native 0.9.5 → 0.9.6
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/CHANGELOG.md +19 -0
- package/README.md +3 -0
- package/dist/extensions/agent-browser/index.js +1214 -583
- package/dist/packaged/lib/browser-session-conversion.js +2810 -0
- package/dist/packaged/lib/config-policy.js +599 -0
- package/dist/packaged/lib/parsing.js +34 -0
- package/dist/packaged/lib/playbook.js +694 -0
- package/dist/packaged/lib/results/snapshot.js +2671 -0
- package/dist/packaged/lib/runtime.js +3027 -0
- package/docs/ARCHITECTURE.md +11 -1
- package/docs/CODE_QUALITY.md +11 -0
- package/docs/COMMAND_REFERENCE.md +2 -2
- package/docs/PERFORMANCE.md +243 -0
- package/docs/REFERENCE.md +3 -3
- package/docs/SESSION_STORAGE.md +11 -3
- package/docs/SUPPORT_MATRIX.md +8 -4
- package/docs/TOOL_CONTRACT.md +4 -4
- package/docs/performance/2026-10-12.json +7257 -0
- package/package.json +13 -2
- package/scripts/build.mjs +16 -5
- package/scripts/config.mjs +1 -1
- package/scripts/convert-browser-session.mjs +1 -1
- package/dist/extensions/agent-browser/lib/argv-descriptor.js +0 -123
- package/dist/extensions/agent-browser/lib/argv-grammar.js +0 -320
- package/dist/extensions/agent-browser/lib/bash-guard.js +0 -193
- package/dist/extensions/agent-browser/lib/batch-lifecycle.js +0 -131
- package/dist/extensions/agent-browser/lib/browser-execution-claim-codec.js +0 -61
- package/dist/extensions/agent-browser/lib/browser-execution-claim-storage.js +0 -232
- package/dist/extensions/agent-browser/lib/browser-execution-claims.js +0 -202
- package/dist/extensions/agent-browser/lib/browser-execution-identity.js +0 -77
- package/dist/extensions/agent-browser/lib/browser-journal-branch.js +0 -98
- package/dist/extensions/agent-browser/lib/browser-journal-contracts.js +0 -1
- package/dist/extensions/agent-browser/lib/browser-journal-projection.js +0 -221
- package/dist/extensions/agent-browser/lib/browser-journal-reader.js +0 -89
- package/dist/extensions/agent-browser/lib/browser-journal-replay.js +0 -246
- package/dist/extensions/agent-browser/lib/browser-journal.js +0 -148
- package/dist/extensions/agent-browser/lib/browser-legacy-pages.js +0 -220
- package/dist/extensions/agent-browser/lib/browser-legacy-projection.js +0 -282
- package/dist/extensions/agent-browser/lib/browser-legacy-types.js +0 -1
- package/dist/extensions/agent-browser/lib/browser-session-conversion-stream.js +0 -217
- package/dist/extensions/agent-browser/lib/browser-session-conversion.js +0 -126
- package/dist/extensions/agent-browser/lib/browser-transcript-contracts.js +0 -35
- package/dist/extensions/agent-browser/lib/browser-transcript-validation.js +0 -166
- package/dist/extensions/agent-browser/lib/browser-transcript.js +0 -189
- package/dist/extensions/agent-browser/lib/browser-value-parsing.js +0 -15
- package/dist/extensions/agent-browser/lib/command-capabilities.js +0 -340
- package/dist/extensions/agent-browser/lib/command-policy.js +0 -155
- package/dist/extensions/agent-browser/lib/command-taxonomy.js +0 -105
- package/dist/extensions/agent-browser/lib/config-policy.js +0 -450
- package/dist/extensions/agent-browser/lib/config-providers.js +0 -71
- package/dist/extensions/agent-browser/lib/config-validation.js +0 -231
- package/dist/extensions/agent-browser/lib/config.js +0 -69
- package/dist/extensions/agent-browser/lib/electron/cdp.js +0 -62
- package/dist/extensions/agent-browser/lib/electron/cleanup.js +0 -274
- package/dist/extensions/agent-browser/lib/electron/discovery-darwin.js +0 -109
- package/dist/extensions/agent-browser/lib/electron/discovery-desktop.js +0 -136
- package/dist/extensions/agent-browser/lib/electron/discovery-evidence.js +0 -90
- package/dist/extensions/agent-browser/lib/electron/discovery-linux.js +0 -93
- package/dist/extensions/agent-browser/lib/electron/discovery-packages.js +0 -162
- package/dist/extensions/agent-browser/lib/electron/discovery-types.js +0 -2
- package/dist/extensions/agent-browser/lib/electron/discovery.js +0 -217
- package/dist/extensions/agent-browser/lib/electron/launch-monitor.js +0 -102
- package/dist/extensions/agent-browser/lib/electron/launch-process.js +0 -209
- package/dist/extensions/agent-browser/lib/electron/launch-types.js +0 -2
- package/dist/extensions/agent-browser/lib/electron/launch.js +0 -340
- package/dist/extensions/agent-browser/lib/executable-path.js +0 -29
- package/dist/extensions/agent-browser/lib/execution-cwd.js +0 -67
- package/dist/extensions/agent-browser/lib/fs-utils.js +0 -10
- package/dist/extensions/agent-browser/lib/input-modes/electron.js +0 -201
- package/dist/extensions/agent-browser/lib/input-modes/job.js +0 -198
- package/dist/extensions/agent-browser/lib/input-modes/lookup-network-evidence.js +0 -116
- package/dist/extensions/agent-browser/lib/input-modes/lookup-plan.js +0 -132
- package/dist/extensions/agent-browser/lib/input-modes/lookup-redaction.js +0 -57
- package/dist/extensions/agent-browser/lib/input-modes/lookup-source-evidence.js +0 -151
- package/dist/extensions/agent-browser/lib/input-modes/lookup-workspace.js +0 -142
- package/dist/extensions/agent-browser/lib/input-modes/lookups.js +0 -84
- package/dist/extensions/agent-browser/lib/input-modes/params.js +0 -195
- package/dist/extensions/agent-browser/lib/input-modes/qa-analysis.js +0 -268
- package/dist/extensions/agent-browser/lib/input-modes/qa-presentation.js +0 -117
- package/dist/extensions/agent-browser/lib/input-modes/script-child.js +0 -396
- package/dist/extensions/agent-browser/lib/input-modes/script-protocol.js +0 -86
- package/dist/extensions/agent-browser/lib/input-modes/script-types.js +0 -1
- package/dist/extensions/agent-browser/lib/input-modes/script-validation.js +0 -60
- package/dist/extensions/agent-browser/lib/input-modes/script.js +0 -108
- package/dist/extensions/agent-browser/lib/input-modes/semantic-action.js +0 -243
- package/dist/extensions/agent-browser/lib/input-modes/shared.js +0 -48
- package/dist/extensions/agent-browser/lib/input-modes/types.js +0 -65
- package/dist/extensions/agent-browser/lib/json-schema.js +0 -65
- package/dist/extensions/agent-browser/lib/launch-scoped-flags.js +0 -212
- package/dist/extensions/agent-browser/lib/managed-session-policy-lock.js +0 -165
- package/dist/extensions/agent-browser/lib/managed-session-posix-storage.js +0 -58
- package/dist/extensions/agent-browser/lib/managed-session-project-identity.js +0 -244
- package/dist/extensions/agent-browser/lib/managed-session-restore-context.js +0 -84
- package/dist/extensions/agent-browser/lib/managed-session-restore-policy.js +0 -119
- package/dist/extensions/agent-browser/lib/managed-session-restore-state.js +0 -83
- package/dist/extensions/agent-browser/lib/managed-session-restore.js +0 -212
- package/dist/extensions/agent-browser/lib/managed-session-snapshot-records.js +0 -277
- package/dist/extensions/agent-browser/lib/managed-session-snapshots.js +0 -181
- package/dist/extensions/agent-browser/lib/managed-session-storage.js +0 -126
- package/dist/extensions/agent-browser/lib/native-confirmation.js +0 -140
- package/dist/extensions/agent-browser/lib/native-output.js +0 -81
- package/dist/extensions/agent-browser/lib/orchestration/batch-stdin.js +0 -182
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/artifact-merge.js +0 -30
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/artifact-paths.js +0 -188
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/browser-observation-result.js +0 -82
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/click-dispatch.js +0 -406
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/diagnostic-values.js +0 -31
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/diagnostics.js +0 -240
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/electron-observation.js +0 -203
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/electron-text-diagnostics.js +0 -109
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/fill-diagnostics.js +0 -119
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-action-recovery.js +0 -147
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-actions.js +0 -144
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-content.js +0 -123
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-contracts.js +0 -1
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-details.js +0 -156
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-electron.js +0 -187
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-evidence.js +0 -39
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-missing-binary.js +0 -89
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-recovery.js +0 -97
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-redaction.js +0 -106
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-timeout.js +0 -110
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result.js +0 -53
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/index.js +0 -224
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/interaction-diagnostics.js +0 -290
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/managed-session-close.js +0 -167
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/managed-session-daemon-inspection.js +0 -108
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/managed-session-daemon-policy.js +0 -174
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/native-helper-observation.js +0 -65
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/observation-types.js +0 -1
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/overlay-diagnostics.js +0 -120
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/network-page-filter.js +0 -192
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/scroll-shims.js +0 -225
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/snapshot-filter-data.js +0 -150
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/snapshot-filter.js +0 -174
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/snapshot-rendered-text.js +0 -147
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/wait-timeouts.js +0 -145
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-artifacts.js +0 -159
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-command.js +0 -131
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-contracts.js +0 -1
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-daemon.js +0 -93
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-failure.js +0 -42
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-guards.js +0 -242
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-input.js +0 -75
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-observations.js +0 -92
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-page-selection.js +0 -254
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-page-state.js +0 -121
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-refs.js +0 -130
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-resources.js +0 -114
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-semantic.js +0 -121
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-session-plan.js +0 -222
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-timeouts.js +0 -68
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare.js +0 -202
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-analysis.js +0 -191
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-confirmation.js +0 -152
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-diagnostics.js +0 -182
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-electron.js +0 -150
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-lifecycle-contracts.js +0 -1
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-lifecycle-phase-contracts.js +0 -1
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-lifecycle-phase.js +0 -115
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-lifecycle.js +0 -256
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-managed-contracts.js +0 -1
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-managed.js +0 -256
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-native-phase-contracts.js +0 -1
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-native-phase.js +0 -93
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-native.js +0 -113
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-navigation-contracts.js +0 -1
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-navigation.js +0 -316
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-ownership.js +0 -28
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-page-phase-contracts.js +0 -1
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-page-phase.js +0 -142
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-presentation-contracts.js +0 -1
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-presentation.js +0 -333
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-publication-phase-contracts.js +0 -1
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-publication-phase.js +0 -71
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-publication.js +0 -201
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-receipts.js +0 -183
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-refs.js +0 -200
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-tabs.js +0 -142
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output.js +0 -25
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prompt-guards.js +0 -50
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/recording-receipt-reconciliation.js +0 -198
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/recording-recovery-contracts.js +0 -1
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/recording-recovery-presentation.js +0 -154
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/recording-recovery.js +0 -80
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/screenshot-capture.js +0 -14
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/screenshot-observation.js +0 -206
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-state-commands.js +0 -130
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-state-electron.js +0 -212
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-state-observations.js +0 -61
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-state-outcomes.js +0 -187
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-state-refs.js +0 -169
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-state-tabs.js +0 -228
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-state.js +0 -117
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/text-visibility-diagnostics.js +0 -182
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/timeout-diagnostics.js +0 -256
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/timeout-progress.js +0 -108
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/types.js +0 -1
- package/dist/extensions/agent-browser/lib/orchestration/code-artifact-observation.js +0 -39
- package/dist/extensions/agent-browser/lib/orchestration/code-image-observation.js +0 -119
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/branch.js +0 -93
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/cleanup-result.js +0 -58
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/cleanup.js +0 -78
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/contracts.js +0 -1
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/discovery.js +0 -106
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/index.js +0 -60
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/policy.js +0 -86
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/probe-collection.js +0 -68
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/probe-data.js +0 -169
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/probe-presentation.js +0 -182
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/probe.js +0 -161
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/status.js +0 -167
- package/dist/extensions/agent-browser/lib/orchestration/execution-queue.js +0 -98
- package/dist/extensions/agent-browser/lib/orchestration/extension-artifact-preflight.js +0 -211
- package/dist/extensions/agent-browser/lib/orchestration/extension-artifacts.js +0 -23
- package/dist/extensions/agent-browser/lib/orchestration/extension-attachment-replay.js +0 -99
- package/dist/extensions/agent-browser/lib/orchestration/extension-branch-restore.js +0 -275
- package/dist/extensions/agent-browser/lib/orchestration/extension-code.js +0 -280
- package/dist/extensions/agent-browser/lib/orchestration/extension-command-admission.js +0 -303
- package/dist/extensions/agent-browser/lib/orchestration/extension-command-output.js +0 -36
- package/dist/extensions/agent-browser/lib/orchestration/extension-command-result.js +0 -335
- package/dist/extensions/agent-browser/lib/orchestration/extension-command-run.js +0 -227
- package/dist/extensions/agent-browser/lib/orchestration/extension-command-state.js +0 -1
- package/dist/extensions/agent-browser/lib/orchestration/extension-electron-ownership.js +0 -204
- package/dist/extensions/agent-browser/lib/orchestration/extension-execution-locks.js +0 -139
- package/dist/extensions/agent-browser/lib/orchestration/extension-execution-queue.js +0 -24
- package/dist/extensions/agent-browser/lib/orchestration/extension-host-coordination.js +0 -98
- package/dist/extensions/agent-browser/lib/orchestration/extension-host-run.js +0 -295
- package/dist/extensions/agent-browser/lib/orchestration/extension-intent-replay.js +0 -41
- package/dist/extensions/agent-browser/lib/orchestration/extension-invocation.js +0 -7
- package/dist/extensions/agent-browser/lib/orchestration/extension-lifecycle.js +0 -102
- package/dist/extensions/agent-browser/lib/orchestration/extension-managed-ownership.js +0 -133
- package/dist/extensions/agent-browser/lib/orchestration/extension-observation.js +0 -120
- package/dist/extensions/agent-browser/lib/orchestration/extension-prompt.js +0 -180
- package/dist/extensions/agent-browser/lib/orchestration/extension-recording.js +0 -290
- package/dist/extensions/agent-browser/lib/orchestration/extension-resource-contracts.js +0 -1
- package/dist/extensions/agent-browser/lib/orchestration/extension-resource-replay.js +0 -269
- package/dist/extensions/agent-browser/lib/orchestration/extension-result-state.js +0 -113
- package/dist/extensions/agent-browser/lib/orchestration/extension-runtime.js +0 -146
- package/dist/extensions/agent-browser/lib/orchestration/extension-script-leases.js +0 -58
- package/dist/extensions/agent-browser/lib/orchestration/extension-tool-boundary.js +0 -62
- package/dist/extensions/agent-browser/lib/orchestration/extension-version-check.js +0 -54
- package/dist/extensions/agent-browser/lib/orchestration/input-plan-types.js +0 -1
- package/dist/extensions/agent-browser/lib/orchestration/input-plan.js +0 -313
- package/dist/extensions/agent-browser/lib/orchestration/input-redaction.js +0 -62
- package/dist/extensions/agent-browser/lib/orchestration/native-config.js +0 -144
- package/dist/extensions/agent-browser/lib/orchestration/native-root-launch.js +0 -77
- package/dist/extensions/agent-browser/lib/orchestration/native-session-defaults.js +0 -231
- package/dist/extensions/agent-browser/lib/orchestration/operation-paths.js +0 -142
- package/dist/extensions/agent-browser/lib/orchestration/output-file.js +0 -276
- package/dist/extensions/agent-browser/lib/orchestration/script-mode.js +0 -220
- package/dist/extensions/agent-browser/lib/owned-managed-session-context.js +0 -55
- package/dist/extensions/agent-browser/lib/page-target-batch.js +0 -118
- package/dist/extensions/agent-browser/lib/page-target-guards.js +0 -50
- package/dist/extensions/agent-browser/lib/page-target-navigation.js +0 -104
- package/dist/extensions/agent-browser/lib/page-target-validation.js +0 -90
- package/dist/extensions/agent-browser/lib/parsing.js +0 -30
- package/dist/extensions/agent-browser/lib/pi-tool-rendering.js +0 -343
- package/dist/extensions/agent-browser/lib/playbook.js +0 -146
- package/dist/extensions/agent-browser/lib/process-child.js +0 -284
- package/dist/extensions/agent-browser/lib/process-environment.js +0 -48
- package/dist/extensions/agent-browser/lib/process-errors.js +0 -23
- package/dist/extensions/agent-browser/lib/process-identity.js +0 -127
- package/dist/extensions/agent-browser/lib/process-socket-storage.js +0 -256
- package/dist/extensions/agent-browser/lib/process-stdout.js +0 -74
- package/dist/extensions/agent-browser/lib/process.js +0 -216
- package/dist/extensions/agent-browser/lib/prompt-artifacts.js +0 -287
- package/dist/extensions/agent-browser/lib/prompt-policy.js +0 -54
- package/dist/extensions/agent-browser/lib/read-command.js +0 -41
- package/dist/extensions/agent-browser/lib/read-confirmation.js +0 -162
- package/dist/extensions/agent-browser/lib/recording-reservations.js +0 -208
- package/dist/extensions/agent-browser/lib/redaction-fields.js +0 -75
- package/dist/extensions/agent-browser/lib/redaction-json.js +0 -149
- package/dist/extensions/agent-browser/lib/redaction-url.js +0 -88
- package/dist/extensions/agent-browser/lib/results/action-contracts.js +0 -1
- package/dist/extensions/agent-browser/lib/results/action-recommendations.js +0 -38
- package/dist/extensions/agent-browser/lib/results/artifact-contracts.js +0 -1
- package/dist/extensions/agent-browser/lib/results/artifact-manifest-validation.js +0 -133
- package/dist/extensions/agent-browser/lib/results/artifact-manifest.js +0 -173
- package/dist/extensions/agent-browser/lib/results/artifact-recommendations.js +0 -73
- package/dist/extensions/agent-browser/lib/results/categories.js +0 -152
- package/dist/extensions/agent-browser/lib/results/confirmation.js +0 -75
- package/dist/extensions/agent-browser/lib/results/contracts.js +0 -1
- package/dist/extensions/agent-browser/lib/results/editable-ref-evidence.js +0 -99
- package/dist/extensions/agent-browser/lib/results/electron-recommendations.js +0 -83
- package/dist/extensions/agent-browser/lib/results/envelope-decoding.js +0 -48
- package/dist/extensions/agent-browser/lib/results/envelope.js +0 -198
- package/dist/extensions/agent-browser/lib/results/evidence-contracts.js +0 -1
- package/dist/extensions/agent-browser/lib/results/failure-recommendations.js +0 -180
- package/dist/extensions/agent-browser/lib/results/network-routes.js +0 -133
- package/dist/extensions/agent-browser/lib/results/network.js +0 -89
- package/dist/extensions/agent-browser/lib/results/next-actions.js +0 -111
- package/dist/extensions/agent-browser/lib/results/presentation/artifact-files.js +0 -320
- package/dist/extensions/agent-browser/lib/results/presentation/artifact-format.js +0 -138
- package/dist/extensions/agent-browser/lib/results/presentation/artifact-images.js +0 -113
- package/dist/extensions/agent-browser/lib/results/presentation/artifact-verification.js +0 -145
- package/dist/extensions/agent-browser/lib/results/presentation/artifacts.js +0 -165
- package/dist/extensions/agent-browser/lib/results/presentation/batch-contracts.js +0 -1
- package/dist/extensions/agent-browser/lib/results/presentation/batch-recording.js +0 -118
- package/dist/extensions/agent-browser/lib/results/presentation/batch-redaction.js +0 -68
- package/dist/extensions/agent-browser/lib/results/presentation/batch-rendering.js +0 -135
- package/dist/extensions/agent-browser/lib/results/presentation/batch-step.js +0 -227
- package/dist/extensions/agent-browser/lib/results/presentation/batch-summary.js +0 -91
- package/dist/extensions/agent-browser/lib/results/presentation/batch.js +0 -123
- package/dist/extensions/agent-browser/lib/results/presentation/browser-profile-recovery.js +0 -54
- package/dist/extensions/agent-browser/lib/results/presentation/command-presenters.js +0 -216
- package/dist/extensions/agent-browser/lib/results/presentation/common.js +0 -81
- package/dist/extensions/agent-browser/lib/results/presentation/content.js +0 -119
- package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-a11y.js +0 -67
- package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-health.js +0 -79
- package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-identity.js +0 -199
- package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-logs.js +0 -75
- package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-network-actions.js +0 -216
- package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-network.js +0 -124
- package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-redaction.js +0 -64
- package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-storage.js +0 -209
- package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-stream.js +0 -69
- package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-summary.js +0 -222
- package/dist/extensions/agent-browser/lib/results/presentation/diagnostics.js +0 -124
- package/dist/extensions/agent-browser/lib/results/presentation/early-result.js +0 -70
- package/dist/extensions/agent-browser/lib/results/presentation/errors.js +0 -285
- package/dist/extensions/agent-browser/lib/results/presentation/input-contracts.js +0 -1
- package/dist/extensions/agent-browser/lib/results/presentation/large-output.js +0 -117
- package/dist/extensions/agent-browser/lib/results/presentation/navigation.js +0 -231
- package/dist/extensions/agent-browser/lib/results/presentation/notices.js +0 -75
- package/dist/extensions/agent-browser/lib/results/presentation/observation-contracts.js +0 -1
- package/dist/extensions/agent-browser/lib/results/presentation/observation-rendering.js +0 -127
- package/dist/extensions/agent-browser/lib/results/presentation/outcomes.js +0 -120
- package/dist/extensions/agent-browser/lib/results/presentation/output-completion.js +0 -77
- package/dist/extensions/agent-browser/lib/results/presentation/output-spill.js +0 -51
- package/dist/extensions/agent-browser/lib/results/presentation/registry.js +0 -145
- package/dist/extensions/agent-browser/lib/results/presentation/semantic-action.js +0 -104
- package/dist/extensions/agent-browser/lib/results/presentation/skills.js +0 -183
- package/dist/extensions/agent-browser/lib/results/presentation/source.js +0 -109
- package/dist/extensions/agent-browser/lib/results/presentation.js +0 -19
- package/dist/extensions/agent-browser/lib/results/recommendation-contracts.js +0 -1
- package/dist/extensions/agent-browser/lib/results/recording.js +0 -88
- package/dist/extensions/agent-browser/lib/results/recovery-actions.js +0 -118
- package/dist/extensions/agent-browser/lib/results/recovery-next-actions.js +0 -60
- package/dist/extensions/agent-browser/lib/results/selector-recovery-target.js +0 -83
- package/dist/extensions/agent-browser/lib/results/selector-recovery.js +0 -261
- package/dist/extensions/agent-browser/lib/results/snapshot-compact.js +0 -266
- package/dist/extensions/agent-browser/lib/results/snapshot-content.js +0 -32
- package/dist/extensions/agent-browser/lib/results/snapshot-high-value-controls.js +0 -240
- package/dist/extensions/agent-browser/lib/results/snapshot-refs.js +0 -103
- package/dist/extensions/agent-browser/lib/results/snapshot-segments.js +0 -383
- package/dist/extensions/agent-browser/lib/results/snapshot-spill.js +0 -53
- package/dist/extensions/agent-browser/lib/results/snapshot.js +0 -44
- package/dist/extensions/agent-browser/lib/results/text.js +0 -44
- package/dist/extensions/agent-browser/lib/runtime-args-validation.js +0 -133
- package/dist/extensions/agent-browser/lib/runtime-compatibility.js +0 -81
- package/dist/extensions/agent-browser/lib/runtime-contracts.js +0 -1
- package/dist/extensions/agent-browser/lib/runtime-redaction.js +0 -118
- package/dist/extensions/agent-browser/lib/runtime-replay-events.js +0 -144
- package/dist/extensions/agent-browser/lib/runtime-session-identity.js +0 -76
- package/dist/extensions/agent-browser/lib/runtime-session-plan.js +0 -114
- package/dist/extensions/agent-browser/lib/runtime-session-replay.js +0 -123
- package/dist/extensions/agent-browser/lib/runtime-tab-correction.js +0 -65
- package/dist/extensions/agent-browser/lib/runtime-timeouts.js +0 -28
- package/dist/extensions/agent-browser/lib/runtime.js +0 -163
- package/dist/extensions/agent-browser/lib/session-identity.js +0 -51
- package/dist/extensions/agent-browser/lib/session-page-observation.js +0 -357
- package/dist/extensions/agent-browser/lib/session-page-state.js +0 -353
- package/dist/extensions/agent-browser/lib/session-page-types.js +0 -1
- package/dist/extensions/agent-browser/lib/string-enum-schema.js +0 -8
- package/dist/extensions/agent-browser/lib/temp-artifact-budget.js +0 -81
- package/dist/extensions/agent-browser/lib/temp-mutation-queue.js +0 -7
- package/dist/extensions/agent-browser/lib/temp-root-ownership.js +0 -234
- package/dist/extensions/agent-browser/lib/temp-root.js +0 -211
- package/dist/extensions/agent-browser/lib/temp.js +0 -91
- package/dist/extensions/agent-browser/lib/tool-surface.js +0 -239
- package/dist/extensions/agent-browser/lib/upstream-version.js +0 -15
- package/dist/extensions/agent-browser/lib/web-search-providers.js +0 -193
- package/dist/extensions/agent-browser/lib/web-search-request.js +0 -102
- package/dist/extensions/agent-browser/lib/web-search-results.js +0 -281
- package/dist/extensions/agent-browser/lib/web-search-schema.js +0 -82
- package/dist/extensions/agent-browser/lib/web-search.js +0 -167
- package/dist/extensions/agent-browser/lib/webmcp-observation.js +0 -35
- package/dist/extensions/agent-browser/lib/windows-stock-launcher.js +0 -96
- package/dist/scripts/agent-browser-target.mjs +0 -23
|
@@ -0,0 +1,2810 @@
|
|
|
1
|
+
// dist/extensions/agent-browser/lib/browser-session-conversion.js
|
|
2
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
3
|
+
import { constants } from "node:fs";
|
|
4
|
+
import { link, lstat, mkdir, open, unlink } from "node:fs/promises";
|
|
5
|
+
import { dirname, resolve } from "node:path";
|
|
6
|
+
|
|
7
|
+
// dist/extensions/agent-browser/lib/parsing.js
|
|
8
|
+
function isRecord(value) {
|
|
9
|
+
return typeof value === "object" && value !== null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// dist/extensions/agent-browser/lib/browser-journal-projection.js
|
|
13
|
+
var ENVELOPE_MAX_BYTES = 16 * 1024 * 1024;
|
|
14
|
+
function matches(field, key) {
|
|
15
|
+
return field === key || field === "*" && typeof key === "number";
|
|
16
|
+
}
|
|
17
|
+
function selectedPath(path, fields) {
|
|
18
|
+
return fields.some((field) => field.every((key, index) => matches(key, path[index])) || path.every((key, index) => matches(field[index], key)));
|
|
19
|
+
}
|
|
20
|
+
var JsonProjection = class {
|
|
21
|
+
fields;
|
|
22
|
+
maxBytes;
|
|
23
|
+
stack = [];
|
|
24
|
+
root;
|
|
25
|
+
literal;
|
|
26
|
+
inKey = false;
|
|
27
|
+
keyText = "";
|
|
28
|
+
bytes = 0;
|
|
29
|
+
constructor(fields, maxBytes) {
|
|
30
|
+
this.fields = fields;
|
|
31
|
+
this.maxBytes = maxBytes;
|
|
32
|
+
}
|
|
33
|
+
result() {
|
|
34
|
+
return isRecord(this.root) ? this.root : void 0;
|
|
35
|
+
}
|
|
36
|
+
reserve(size) {
|
|
37
|
+
this.bytes += size;
|
|
38
|
+
if (this.bytes > this.maxBytes) {
|
|
39
|
+
throw new Error("Selected journal envelope exceeds its bounded read size.");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
path() {
|
|
43
|
+
const frame = this.stack.at(-1);
|
|
44
|
+
return frame ? [...frame.path, frame.key ?? frame.index] : [];
|
|
45
|
+
}
|
|
46
|
+
excluded() {
|
|
47
|
+
const frame = this.stack.at(-1);
|
|
48
|
+
return frame !== void 0 && frame.value === void 0;
|
|
49
|
+
}
|
|
50
|
+
frame() {
|
|
51
|
+
const frame = this.stack.at(-1);
|
|
52
|
+
if (!frame) {
|
|
53
|
+
throw new Error("Journal JSON container is missing.");
|
|
54
|
+
}
|
|
55
|
+
return frame;
|
|
56
|
+
}
|
|
57
|
+
put(value) {
|
|
58
|
+
const parent = this.stack.at(-1);
|
|
59
|
+
if (!parent) {
|
|
60
|
+
this.root = value;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (parent.value && value !== void 0) {
|
|
64
|
+
if (Array.isArray(parent.value)) {
|
|
65
|
+
parent.value[parent.index] = value;
|
|
66
|
+
} else {
|
|
67
|
+
if (parent.key === void 0) {
|
|
68
|
+
throw new Error("Journal object key is missing.");
|
|
69
|
+
}
|
|
70
|
+
Object.defineProperty(parent.value, parent.key, {
|
|
71
|
+
value,
|
|
72
|
+
writable: true,
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
parent.key = void 0;
|
|
79
|
+
parent.index += 1;
|
|
80
|
+
}
|
|
81
|
+
consume(token) {
|
|
82
|
+
if (token.name === "startKey") {
|
|
83
|
+
this.inKey = true;
|
|
84
|
+
this.keyText = "";
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (token.name === "endKey") {
|
|
88
|
+
this.inKey = false;
|
|
89
|
+
this.frame().key = this.keyText;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (this.inKey) {
|
|
93
|
+
this.consumeKey(token);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
switch (token.name) {
|
|
97
|
+
case "startObject":
|
|
98
|
+
case "startArray":
|
|
99
|
+
this.startContainer(token.name);
|
|
100
|
+
break;
|
|
101
|
+
case "endObject":
|
|
102
|
+
case "endArray": {
|
|
103
|
+
const frame = this.stack.pop();
|
|
104
|
+
if (!frame) {
|
|
105
|
+
throw new Error("Journal JSON container is missing.");
|
|
106
|
+
}
|
|
107
|
+
this.put(frame.value);
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
case "startString":
|
|
111
|
+
case "startNumber":
|
|
112
|
+
this.literal = {
|
|
113
|
+
value: "",
|
|
114
|
+
selected: !this.excluded() && selectedPath(this.path(), this.fields),
|
|
115
|
+
number: token.name === "startNumber"
|
|
116
|
+
};
|
|
117
|
+
break;
|
|
118
|
+
case "stringChunk":
|
|
119
|
+
case "numberChunk":
|
|
120
|
+
this.consumeLiteral(token.value);
|
|
121
|
+
break;
|
|
122
|
+
case "endString":
|
|
123
|
+
case "endNumber":
|
|
124
|
+
this.endLiteral();
|
|
125
|
+
break;
|
|
126
|
+
case "trueValue":
|
|
127
|
+
case "falseValue":
|
|
128
|
+
case "nullValue":
|
|
129
|
+
this.consumeConstant(token.name);
|
|
130
|
+
break;
|
|
131
|
+
case "keyValue":
|
|
132
|
+
case "numberValue":
|
|
133
|
+
case "stringValue":
|
|
134
|
+
case "whitespace":
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
consumeKey(token) {
|
|
139
|
+
if (token.name !== "stringChunk" || this.excluded()) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const path = this.frame().path;
|
|
143
|
+
const wholeContainer = this.fields.some((field) => field.every((key, index) => matches(key, path[index])));
|
|
144
|
+
if (wholeContainer || this.keyText.length <= 1024) {
|
|
145
|
+
if (wholeContainer) {
|
|
146
|
+
this.reserve(Buffer.byteLength(token.value));
|
|
147
|
+
}
|
|
148
|
+
this.keyText += token.value;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
startContainer(name) {
|
|
152
|
+
if (this.stack.length >= 1024) {
|
|
153
|
+
throw new Error("Journal JSON nesting exceeds 1024 levels.");
|
|
154
|
+
}
|
|
155
|
+
const currentPath = this.excluded() ? [] : this.path();
|
|
156
|
+
const selected = !this.excluded() && selectedPath(currentPath, this.fields);
|
|
157
|
+
if (selected) {
|
|
158
|
+
this.reserve(32);
|
|
159
|
+
}
|
|
160
|
+
let value;
|
|
161
|
+
if (selected) {
|
|
162
|
+
value = name === "startObject" ? {} : [];
|
|
163
|
+
}
|
|
164
|
+
this.stack.push({ path: currentPath, index: 0, value });
|
|
165
|
+
}
|
|
166
|
+
consumeLiteral(value) {
|
|
167
|
+
if (this.literal?.selected === true) {
|
|
168
|
+
this.reserve(Buffer.byteLength(value));
|
|
169
|
+
this.literal.value += value;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
endLiteral() {
|
|
173
|
+
const literal = this.literal;
|
|
174
|
+
let value;
|
|
175
|
+
if (literal?.selected === true) {
|
|
176
|
+
value = literal.number ? Number(literal.value) : literal.value;
|
|
177
|
+
}
|
|
178
|
+
this.put(value);
|
|
179
|
+
this.literal = void 0;
|
|
180
|
+
}
|
|
181
|
+
consumeConstant(name) {
|
|
182
|
+
const selected = !this.excluded() && selectedPath(this.path(), this.fields);
|
|
183
|
+
if (selected) {
|
|
184
|
+
this.reserve(8);
|
|
185
|
+
}
|
|
186
|
+
let value;
|
|
187
|
+
if (selected) {
|
|
188
|
+
value = name === "nullValue" ? null : name === "trueValue";
|
|
189
|
+
}
|
|
190
|
+
this.put(value);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
async function projectJson(input, fields, maxBytes = ENVELOPE_MAX_BYTES) {
|
|
194
|
+
const { jsonParser } = await import("stream-json/core/parser.js");
|
|
195
|
+
const chain = await import("stream-chain/defs.js");
|
|
196
|
+
const tokenize = jsonParser({ packValues: false, streamValues: true });
|
|
197
|
+
const projection = new JsonProjection(fields, maxBytes);
|
|
198
|
+
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
199
|
+
const consume = (text) => {
|
|
200
|
+
const tokens = tokenize(text);
|
|
201
|
+
if (tokens !== chain.none) {
|
|
202
|
+
for (const token of chain.getManyValues(tokens)) {
|
|
203
|
+
projection.consume(token);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
for await (const chunk of input) {
|
|
208
|
+
consume(decoder.decode(chunk, { stream: true }));
|
|
209
|
+
}
|
|
210
|
+
const tail = decoder.decode();
|
|
211
|
+
if (tail.length > 0) {
|
|
212
|
+
consume(tail);
|
|
213
|
+
}
|
|
214
|
+
consume(chain.none);
|
|
215
|
+
return projection.result();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// dist/extensions/agent-browser/lib/browser-journal-reader.js
|
|
219
|
+
var CHUNK_BYTES = 64 * 1024;
|
|
220
|
+
async function* readRange(file, range) {
|
|
221
|
+
let position = range.offset;
|
|
222
|
+
const end = range.offset + range.length;
|
|
223
|
+
while (position < end) {
|
|
224
|
+
const buffer = Buffer.allocUnsafe(Math.min(CHUNK_BYTES, end - position));
|
|
225
|
+
const { bytesRead } = await file.read(buffer, 0, buffer.length, position);
|
|
226
|
+
if (bytesRead === 0) {
|
|
227
|
+
throw new Error("Journal changed or truncated during read.");
|
|
228
|
+
}
|
|
229
|
+
position += bytesRead;
|
|
230
|
+
yield buffer.subarray(0, bytesRead);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
var JournalLineFramer = class {
|
|
234
|
+
start;
|
|
235
|
+
nonblank = false;
|
|
236
|
+
constructor(offset) {
|
|
237
|
+
this.start = offset;
|
|
238
|
+
}
|
|
239
|
+
*accept(buffer, position) {
|
|
240
|
+
for (let index = 0; index < buffer.length; index++) {
|
|
241
|
+
const byte = buffer[index];
|
|
242
|
+
if (byte === 10) {
|
|
243
|
+
if (this.nonblank) {
|
|
244
|
+
yield { offset: this.start, length: position + index + 1 - this.start };
|
|
245
|
+
}
|
|
246
|
+
this.start = position + index + 1;
|
|
247
|
+
this.nonblank = false;
|
|
248
|
+
} else if (![9, 13, 32].includes(byte)) {
|
|
249
|
+
this.nonblank = true;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
final(end, sealed) {
|
|
254
|
+
return this.nonblank && sealed ? { offset: this.start, length: end - this.start } : void 0;
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
async function* journalRanges(file, end, sealed = false, offset = 0) {
|
|
258
|
+
let position = offset;
|
|
259
|
+
const framer = new JournalLineFramer(offset);
|
|
260
|
+
while (position < end) {
|
|
261
|
+
const buffer = Buffer.allocUnsafe(Math.min(CHUNK_BYTES, end - position));
|
|
262
|
+
const { bytesRead } = await file.read(buffer, 0, buffer.length, position);
|
|
263
|
+
if (bytesRead === 0) {
|
|
264
|
+
throw new Error("Journal truncated during read.");
|
|
265
|
+
}
|
|
266
|
+
yield* framer.accept(buffer.subarray(0, bytesRead), position);
|
|
267
|
+
position += bytesRead;
|
|
268
|
+
}
|
|
269
|
+
const final = framer.final(end, sealed);
|
|
270
|
+
if (final) {
|
|
271
|
+
yield final;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
var STRUCTURAL_FIELDS = [
|
|
275
|
+
["type"],
|
|
276
|
+
["id"],
|
|
277
|
+
["parentId"],
|
|
278
|
+
["timestamp"],
|
|
279
|
+
["version"],
|
|
280
|
+
["customType"],
|
|
281
|
+
["data", "event", "version"],
|
|
282
|
+
["data", "snapshot", "id"],
|
|
283
|
+
["message", "toolName"],
|
|
284
|
+
["message", "details", "browserEventVersion"],
|
|
285
|
+
["message", "details", "sessionName"],
|
|
286
|
+
["message", "details", "artifactManifest", "version"],
|
|
287
|
+
["message", "details", "electron", "action"]
|
|
288
|
+
];
|
|
289
|
+
async function scanJournalMetadata(file, end, sealed = false) {
|
|
290
|
+
const entries = [];
|
|
291
|
+
for await (const range of journalRanges(file, end, sealed)) {
|
|
292
|
+
const value = await projectJson(readRange(file, range), STRUCTURAL_FIELDS);
|
|
293
|
+
if (!value) {
|
|
294
|
+
throw new Error(`Expected a journal object at byte ${range.offset}.`);
|
|
295
|
+
}
|
|
296
|
+
entries.push({ ...range, value });
|
|
297
|
+
}
|
|
298
|
+
return entries;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// dist/extensions/agent-browser/lib/process-errors.js
|
|
302
|
+
function getErrorCode(error) {
|
|
303
|
+
return isRecord(error) && typeof error.code === "string" ? error.code : void 0;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// dist/extensions/agent-browser/lib/browser-session-conversion-stream.js
|
|
307
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
308
|
+
import { Readable } from "node:stream";
|
|
309
|
+
import { pipeline } from "node:stream/promises";
|
|
310
|
+
import tokenizeJson from "stream-json/parser.js";
|
|
311
|
+
import ignoreJson from "stream-json/filters/ignore.js";
|
|
312
|
+
import stringifyJson from "stream-json/stringer.js";
|
|
313
|
+
import disassembleJson from "stream-json/disassembler.js";
|
|
314
|
+
|
|
315
|
+
// dist/extensions/agent-browser/lib/browser-transcript-contracts.js
|
|
316
|
+
var BROWSER_TRANSITION_ENTRY = "agent-browser-transition";
|
|
317
|
+
var BROWSER_RESULT_TOOLS = /* @__PURE__ */ new Set([
|
|
318
|
+
"agent_browser",
|
|
319
|
+
"agent_browser_code",
|
|
320
|
+
"agent_browser_action",
|
|
321
|
+
"agent_browser_qa",
|
|
322
|
+
"agent_browser_electron",
|
|
323
|
+
"agent_browser_source",
|
|
324
|
+
"agent_browser_network_source"
|
|
325
|
+
]);
|
|
326
|
+
var BROWSER_STATE_FIELDS = [
|
|
327
|
+
"args",
|
|
328
|
+
"command",
|
|
329
|
+
"subcommand",
|
|
330
|
+
"sessionName",
|
|
331
|
+
"namespace",
|
|
332
|
+
"sessionMode",
|
|
333
|
+
"usedImplicitSession",
|
|
334
|
+
"managedSessionSocketDir",
|
|
335
|
+
"managedSessionDaemon",
|
|
336
|
+
"ownerSessionId",
|
|
337
|
+
"agentBrowserStarted",
|
|
338
|
+
"resultCategory",
|
|
339
|
+
"exitCode",
|
|
340
|
+
"closeAllApplied",
|
|
341
|
+
"attachedBrowserSession",
|
|
342
|
+
"readConfirmation",
|
|
343
|
+
"compatibilityWorkaround",
|
|
344
|
+
"managedSessionHeadedAutosaveDisabled",
|
|
345
|
+
"managedSessionHeadedAutosaveInterval",
|
|
346
|
+
"managedSessionOutcome",
|
|
347
|
+
"managedSessionCwd",
|
|
348
|
+
"managedSessionRestoreDisabled",
|
|
349
|
+
"nativeSucceeded"
|
|
350
|
+
];
|
|
351
|
+
|
|
352
|
+
// dist/extensions/agent-browser/lib/browser-legacy-projection.js
|
|
353
|
+
import { randomUUID } from "node:crypto";
|
|
354
|
+
|
|
355
|
+
// dist/extensions/agent-browser/lib/command-capabilities.js
|
|
356
|
+
var ADDITIONAL_COMMAND_TOKENS = [
|
|
357
|
+
"a11y",
|
|
358
|
+
"auth",
|
|
359
|
+
"chat",
|
|
360
|
+
"clipboard",
|
|
361
|
+
"confirm",
|
|
362
|
+
"connect",
|
|
363
|
+
"dashboard",
|
|
364
|
+
"deny",
|
|
365
|
+
"device",
|
|
366
|
+
"dialog",
|
|
367
|
+
"diff",
|
|
368
|
+
"doctor",
|
|
369
|
+
"errors",
|
|
370
|
+
"eval",
|
|
371
|
+
"find",
|
|
372
|
+
"frame",
|
|
373
|
+
"get",
|
|
374
|
+
"highlight",
|
|
375
|
+
"inspect",
|
|
376
|
+
"install",
|
|
377
|
+
"is",
|
|
378
|
+
"mcp",
|
|
379
|
+
"plugin",
|
|
380
|
+
"plugins",
|
|
381
|
+
"profiles",
|
|
382
|
+
"profiler",
|
|
383
|
+
"react",
|
|
384
|
+
"record",
|
|
385
|
+
"removeinitscript",
|
|
386
|
+
"session",
|
|
387
|
+
"set",
|
|
388
|
+
"skills",
|
|
389
|
+
"snapshot",
|
|
390
|
+
"state",
|
|
391
|
+
"stream",
|
|
392
|
+
"trace",
|
|
393
|
+
"upgrade",
|
|
394
|
+
"vitals",
|
|
395
|
+
"wait",
|
|
396
|
+
"web-vitals",
|
|
397
|
+
"webmcp",
|
|
398
|
+
"window"
|
|
399
|
+
];
|
|
400
|
+
var COMMAND_CAPABILITIES = [
|
|
401
|
+
{
|
|
402
|
+
command: "back",
|
|
403
|
+
eligibleForElectronHealthProbe: true,
|
|
404
|
+
eligibleForPageChangeSummary: true,
|
|
405
|
+
invalidatesBatchRefs: true,
|
|
406
|
+
navigationObservable: true,
|
|
407
|
+
triggersPostMutationSnapshot: true
|
|
408
|
+
},
|
|
409
|
+
{
|
|
410
|
+
command: "batch",
|
|
411
|
+
excludedFromPostCommandCorrection: true
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
command: "check",
|
|
415
|
+
eligibleForElectronHealthProbe: true,
|
|
416
|
+
eligibleForPageChangeSummary: true,
|
|
417
|
+
guardsPageRefs: true,
|
|
418
|
+
invalidatesBatchRefs: true,
|
|
419
|
+
triggersPostMutationSnapshot: true
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
command: "click",
|
|
423
|
+
eligibleForElectronHealthProbe: true,
|
|
424
|
+
eligibleForPageChangeSummary: true,
|
|
425
|
+
guardsPageRefs: true,
|
|
426
|
+
invalidatesBatchRefs: true,
|
|
427
|
+
navigationObservable: true,
|
|
428
|
+
triggersPostMutationSnapshot: true
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
aliases: ["quit", "exit"],
|
|
432
|
+
closesSession: true,
|
|
433
|
+
command: "close",
|
|
434
|
+
excludedFromPinning: true,
|
|
435
|
+
excludedFromPostCommandCorrection: true
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
command: "console",
|
|
439
|
+
readOnlyDiagnosticSessionTarget: true
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
command: "cookies",
|
|
443
|
+
readOnlyDiagnosticSessionTarget: true
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
command: "dblclick",
|
|
447
|
+
eligibleForElectronHealthProbe: true,
|
|
448
|
+
eligibleForPageChangeSummary: true,
|
|
449
|
+
guardsPageRefs: true,
|
|
450
|
+
invalidatesBatchRefs: true,
|
|
451
|
+
navigationObservable: true,
|
|
452
|
+
triggersPostMutationSnapshot: true
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
command: "dialog",
|
|
456
|
+
eligibleForPageChangeSummary: true,
|
|
457
|
+
invalidatesBatchRefs: true,
|
|
458
|
+
triggersPostMutationSnapshot: true
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
command: "diff",
|
|
462
|
+
guardsPageRefs: true
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
command: "download",
|
|
466
|
+
eligibleForPageChangeSummary: true,
|
|
467
|
+
guardsPageRefs: true
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
command: "drag",
|
|
471
|
+
guardsPageRefs: true,
|
|
472
|
+
invalidatesBatchRefs: true
|
|
473
|
+
},
|
|
474
|
+
{
|
|
475
|
+
command: "errors",
|
|
476
|
+
readOnlyDiagnosticSessionTarget: true
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
command: "eval",
|
|
480
|
+
invalidatesBatchRefs: true,
|
|
481
|
+
navigationObservable: true,
|
|
482
|
+
triggersPostMutationSnapshot: true
|
|
483
|
+
},
|
|
484
|
+
{
|
|
485
|
+
command: "fill",
|
|
486
|
+
eligibleForElectronHealthProbe: true,
|
|
487
|
+
eligibleForPageChangeSummary: true,
|
|
488
|
+
guardsPageRefs: true,
|
|
489
|
+
triggersPostMutationSnapshot: true
|
|
490
|
+
},
|
|
491
|
+
{
|
|
492
|
+
command: "find",
|
|
493
|
+
eligibleForElectronHealthProbe: true
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
command: "frame",
|
|
497
|
+
guardsPageRefs: true
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
command: "focus",
|
|
501
|
+
guardsPageRefs: true
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
command: "forward",
|
|
505
|
+
eligibleForElectronHealthProbe: true,
|
|
506
|
+
eligibleForPageChangeSummary: true,
|
|
507
|
+
invalidatesBatchRefs: true,
|
|
508
|
+
navigationObservable: true,
|
|
509
|
+
triggersPostMutationSnapshot: true
|
|
510
|
+
},
|
|
511
|
+
{
|
|
512
|
+
command: "get",
|
|
513
|
+
guardsPageRefs: true
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
command: "highlight",
|
|
517
|
+
guardsPageRefs: true
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
command: "hover",
|
|
521
|
+
eligibleForPageChangeSummary: true,
|
|
522
|
+
guardsPageRefs: true,
|
|
523
|
+
invalidatesBatchRefs: true,
|
|
524
|
+
triggersPostMutationSnapshot: true
|
|
525
|
+
},
|
|
526
|
+
{
|
|
527
|
+
command: "is",
|
|
528
|
+
guardsPageRefs: true
|
|
529
|
+
},
|
|
530
|
+
{
|
|
531
|
+
command: "keydown",
|
|
532
|
+
eligibleForElectronHealthProbe: true,
|
|
533
|
+
eligibleForPageChangeSummary: true,
|
|
534
|
+
invalidatesBatchRefs: true,
|
|
535
|
+
triggersPostMutationSnapshot: true
|
|
536
|
+
},
|
|
537
|
+
{
|
|
538
|
+
command: "keyboard",
|
|
539
|
+
eligibleForElectronHealthProbe: true,
|
|
540
|
+
eligibleForPageChangeSummary: true,
|
|
541
|
+
invalidatesBatchRefs: true,
|
|
542
|
+
triggersPostMutationSnapshot: true
|
|
543
|
+
},
|
|
544
|
+
{
|
|
545
|
+
command: "keyup",
|
|
546
|
+
eligibleForElectronHealthProbe: true,
|
|
547
|
+
eligibleForPageChangeSummary: true,
|
|
548
|
+
invalidatesBatchRefs: true,
|
|
549
|
+
triggersPostMutationSnapshot: true
|
|
550
|
+
},
|
|
551
|
+
{
|
|
552
|
+
command: "mouse",
|
|
553
|
+
eligibleForElectronHealthProbe: true,
|
|
554
|
+
invalidatesBatchRefs: true
|
|
555
|
+
},
|
|
556
|
+
{
|
|
557
|
+
command: "network",
|
|
558
|
+
readOnlyDiagnosticSessionTarget: true
|
|
559
|
+
},
|
|
560
|
+
{
|
|
561
|
+
aliases: ["goto", "navigate"],
|
|
562
|
+
command: "open",
|
|
563
|
+
eligibleForPageChangeSummary: true,
|
|
564
|
+
excludedFromPinning: true,
|
|
565
|
+
invalidatesBatchRefs: true,
|
|
566
|
+
openNavigation: true
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
command: "pdf",
|
|
570
|
+
eligibleForPageChangeSummary: true
|
|
571
|
+
},
|
|
572
|
+
{
|
|
573
|
+
aliases: ["key"],
|
|
574
|
+
command: "press",
|
|
575
|
+
eligibleForElectronHealthProbe: true,
|
|
576
|
+
eligibleForPageChangeSummary: true,
|
|
577
|
+
invalidatesBatchRefs: true,
|
|
578
|
+
triggersPostMutationSnapshot: true
|
|
579
|
+
},
|
|
580
|
+
{
|
|
581
|
+
command: "pushstate",
|
|
582
|
+
eligibleForPageChangeSummary: true,
|
|
583
|
+
invalidatesBatchRefs: true,
|
|
584
|
+
triggersPostMutationSnapshot: true
|
|
585
|
+
},
|
|
586
|
+
{
|
|
587
|
+
command: "reload",
|
|
588
|
+
eligibleForElectronHealthProbe: true,
|
|
589
|
+
eligibleForPageChangeSummary: true,
|
|
590
|
+
invalidatesBatchRefs: true,
|
|
591
|
+
navigationObservable: true,
|
|
592
|
+
triggersPostMutationSnapshot: true
|
|
593
|
+
},
|
|
594
|
+
{
|
|
595
|
+
command: "read",
|
|
596
|
+
readOnlyDiagnosticSessionTarget: true
|
|
597
|
+
},
|
|
598
|
+
{
|
|
599
|
+
command: "screenshot",
|
|
600
|
+
eligibleForPageChangeSummary: true,
|
|
601
|
+
guardsPageRefs: true
|
|
602
|
+
},
|
|
603
|
+
{
|
|
604
|
+
command: "scroll",
|
|
605
|
+
eligibleForPageChangeSummary: true,
|
|
606
|
+
guardsPageRefs: true,
|
|
607
|
+
invalidatesBatchRefs: true,
|
|
608
|
+
triggersPostMutationSnapshot: true
|
|
609
|
+
},
|
|
610
|
+
{
|
|
611
|
+
aliases: ["scrollinto"],
|
|
612
|
+
command: "scrollintoview",
|
|
613
|
+
eligibleForPageChangeSummary: true,
|
|
614
|
+
guardsPageRefs: true,
|
|
615
|
+
invalidatesBatchRefs: true,
|
|
616
|
+
triggersPostMutationSnapshot: true
|
|
617
|
+
},
|
|
618
|
+
{
|
|
619
|
+
command: "select",
|
|
620
|
+
eligibleForElectronHealthProbe: true,
|
|
621
|
+
eligibleForPageChangeSummary: true,
|
|
622
|
+
guardsPageRefs: true,
|
|
623
|
+
invalidatesBatchRefs: true,
|
|
624
|
+
triggersPostMutationSnapshot: true
|
|
625
|
+
},
|
|
626
|
+
{
|
|
627
|
+
command: "session",
|
|
628
|
+
excludedFromPinning: true,
|
|
629
|
+
excludedFromPostCommandCorrection: true
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
command: "storage",
|
|
633
|
+
readOnlyDiagnosticSessionTarget: true
|
|
634
|
+
},
|
|
635
|
+
{
|
|
636
|
+
command: "swipe",
|
|
637
|
+
eligibleForPageChangeSummary: true,
|
|
638
|
+
invalidatesBatchRefs: true,
|
|
639
|
+
triggersPostMutationSnapshot: true
|
|
640
|
+
},
|
|
641
|
+
{
|
|
642
|
+
command: "tab",
|
|
643
|
+
excludedFromPinning: true,
|
|
644
|
+
excludedFromPostCommandCorrection: true
|
|
645
|
+
},
|
|
646
|
+
{
|
|
647
|
+
command: "tap",
|
|
648
|
+
eligibleForElectronHealthProbe: true,
|
|
649
|
+
eligibleForPageChangeSummary: true,
|
|
650
|
+
guardsPageRefs: true,
|
|
651
|
+
invalidatesBatchRefs: true,
|
|
652
|
+
triggersPostMutationSnapshot: true
|
|
653
|
+
},
|
|
654
|
+
{
|
|
655
|
+
command: "type",
|
|
656
|
+
eligibleForElectronHealthProbe: true,
|
|
657
|
+
eligibleForPageChangeSummary: true,
|
|
658
|
+
guardsPageRefs: true,
|
|
659
|
+
invalidatesBatchRefs: true,
|
|
660
|
+
triggersPostMutationSnapshot: true
|
|
661
|
+
},
|
|
662
|
+
{
|
|
663
|
+
command: "uncheck",
|
|
664
|
+
eligibleForElectronHealthProbe: true,
|
|
665
|
+
eligibleForPageChangeSummary: true,
|
|
666
|
+
guardsPageRefs: true,
|
|
667
|
+
invalidatesBatchRefs: true,
|
|
668
|
+
triggersPostMutationSnapshot: true
|
|
669
|
+
},
|
|
670
|
+
{
|
|
671
|
+
command: "upload",
|
|
672
|
+
guardsPageRefs: true,
|
|
673
|
+
invalidatesBatchRefs: true
|
|
674
|
+
}
|
|
675
|
+
];
|
|
676
|
+
var COMMAND_CAPABILITY_BY_NAME = /* @__PURE__ */ new Map();
|
|
677
|
+
for (const entry of COMMAND_CAPABILITIES) {
|
|
678
|
+
COMMAND_CAPABILITY_BY_NAME.set(entry.command, entry);
|
|
679
|
+
for (const alias of entry.aliases ?? []) {
|
|
680
|
+
COMMAND_CAPABILITY_BY_NAME.set(alias, entry);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
var KNOWN_COMMAND_TOKENS = /* @__PURE__ */ new Set([
|
|
684
|
+
...COMMAND_CAPABILITY_BY_NAME.keys(),
|
|
685
|
+
...ADDITIONAL_COMMAND_TOKENS
|
|
686
|
+
]);
|
|
687
|
+
function isKnownCommandToken(token) {
|
|
688
|
+
return KNOWN_COMMAND_TOKENS.has(token);
|
|
689
|
+
}
|
|
690
|
+
function getCommandCapability(command) {
|
|
691
|
+
return command === void 0 ? void 0 : COMMAND_CAPABILITY_BY_NAME.get(command);
|
|
692
|
+
}
|
|
693
|
+
function hasCommandCapability(command, capability) {
|
|
694
|
+
return getCommandCapability(command)?.[capability] === true;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
// dist/extensions/agent-browser/lib/command-taxonomy.js
|
|
698
|
+
var WEBMCP_PAGE_MUTATION_SUBCOMMANDS = /* @__PURE__ */ new Set(["invoke", "result", "cancel"]);
|
|
699
|
+
function isCloseCommand(command) {
|
|
700
|
+
return hasCommandCapability(command, "closesSession");
|
|
701
|
+
}
|
|
702
|
+
function isCloseAllCommand(commandTokens) {
|
|
703
|
+
return isCloseCommand(commandTokens[0]) && commandTokens.slice(1).includes("--all");
|
|
704
|
+
}
|
|
705
|
+
function isOpenNavigationCommand(command) {
|
|
706
|
+
return hasCommandCapability(command, "openNavigation");
|
|
707
|
+
}
|
|
708
|
+
function isReadOnlyDiagnosticSessionTargetCommand(command, subcommand) {
|
|
709
|
+
return hasCommandCapability(command, "readOnlyDiagnosticSessionTarget") || command === "webmcp" && subcommand === "list";
|
|
710
|
+
}
|
|
711
|
+
function isWindowOrDiffPageTransitionCommand(command, subcommand) {
|
|
712
|
+
return command === "window" && subcommand === "new" || command === "diff" && subcommand === "url";
|
|
713
|
+
}
|
|
714
|
+
function isWebMcpPageMutation(command, subcommand) {
|
|
715
|
+
return command === "webmcp" && WEBMCP_PAGE_MUTATION_SUBCOMMANDS.has(subcommand ?? "");
|
|
716
|
+
}
|
|
717
|
+
function isUnverifiedPageTransitionCommand(command, subcommand) {
|
|
718
|
+
return ["back", "connect", "eval", "forward", "reload"].includes(command ?? "") || command === "state" && subcommand === "load" || command === "tab" && subcommand !== void 0 && !["list", "new"].includes(subcommand) || isWindowOrDiffPageTransitionCommand(command, subcommand) || isWebMcpPageMutation(command, subcommand);
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
// dist/extensions/agent-browser/lib/session-identity.js
|
|
722
|
+
var SESSION_COMPONENT_ALPHANUMERIC = /^[\p{Alphabetic}\p{Number}]$/u;
|
|
723
|
+
function canonicalizeAgentBrowserNamespace(value) {
|
|
724
|
+
if (value === void 0) {
|
|
725
|
+
return void 0;
|
|
726
|
+
}
|
|
727
|
+
let normalized = "";
|
|
728
|
+
let lastWasSeparator = false;
|
|
729
|
+
for (const character of value) {
|
|
730
|
+
if (SESSION_COMPONENT_ALPHANUMERIC.test(character)) {
|
|
731
|
+
normalized += character.toLowerCase();
|
|
732
|
+
lastWasSeparator = false;
|
|
733
|
+
continue;
|
|
734
|
+
}
|
|
735
|
+
if (normalized.length > 0 && !lastWasSeparator) {
|
|
736
|
+
normalized += character === "_" ? "_" : "-";
|
|
737
|
+
lastWasSeparator = true;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
const result = normalized.replace(/[-_]+$/u, "");
|
|
741
|
+
return result.length > 0 ? result : void 0;
|
|
742
|
+
}
|
|
743
|
+
function foldAgentBrowserFilesystemIdentity(value, platform) {
|
|
744
|
+
if (platform !== "darwin" && platform !== "win32") {
|
|
745
|
+
return value;
|
|
746
|
+
}
|
|
747
|
+
return value.normalize("NFC").toLowerCase().toUpperCase().toLowerCase().normalize("NFC");
|
|
748
|
+
}
|
|
749
|
+
function getAgentBrowserSessionIdentityKey(sessionName, namespace, platform = process.platform) {
|
|
750
|
+
const canonicalNamespace = canonicalizeAgentBrowserNamespace(namespace);
|
|
751
|
+
const canonicalSessionName = foldAgentBrowserFilesystemIdentity(sessionName, platform);
|
|
752
|
+
return canonicalNamespace !== void 0 ? `${foldAgentBrowserFilesystemIdentity(canonicalNamespace, platform)}\0${canonicalSessionName}` : canonicalSessionName;
|
|
753
|
+
}
|
|
754
|
+
function isAgentBrowserSessionIdentityKeyInNamespace(identityKey, namespace) {
|
|
755
|
+
const prefix = getAgentBrowserSessionIdentityKey("", namespace);
|
|
756
|
+
return prefix.length > 0 ? identityKey.startsWith(prefix) : !identityKey.includes("\0");
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
// dist/extensions/agent-browser/lib/argv-grammar.js
|
|
760
|
+
var GLOBAL_VALUE_FLAGS = [
|
|
761
|
+
"--session",
|
|
762
|
+
"--namespace",
|
|
763
|
+
"--cdp",
|
|
764
|
+
"--config",
|
|
765
|
+
"--profile",
|
|
766
|
+
"--session-name",
|
|
767
|
+
"--restore-save",
|
|
768
|
+
"--restore-check-url",
|
|
769
|
+
"--restore-check-text",
|
|
770
|
+
"--restore-check-fn",
|
|
771
|
+
"--proxy",
|
|
772
|
+
"--proxy-bypass",
|
|
773
|
+
"--ca-cert",
|
|
774
|
+
"--headers",
|
|
775
|
+
"--executable-path",
|
|
776
|
+
"--extension",
|
|
777
|
+
"--init-script",
|
|
778
|
+
"--enable",
|
|
779
|
+
"--provider",
|
|
780
|
+
"-p",
|
|
781
|
+
"--engine",
|
|
782
|
+
"--state",
|
|
783
|
+
"--download-path",
|
|
784
|
+
"--screenshot-dir",
|
|
785
|
+
"--screenshot-format",
|
|
786
|
+
"--screenshot-quality",
|
|
787
|
+
"--color-scheme",
|
|
788
|
+
"--device",
|
|
789
|
+
"--args",
|
|
790
|
+
"--user-agent",
|
|
791
|
+
"--allowed-domains",
|
|
792
|
+
"--action-policy",
|
|
793
|
+
"--confirm-actions",
|
|
794
|
+
"--max-output",
|
|
795
|
+
"--model",
|
|
796
|
+
"--idle-timeout",
|
|
797
|
+
"--input-mode"
|
|
798
|
+
];
|
|
799
|
+
var COMMAND_VALUE_FLAGS = [
|
|
800
|
+
"--allowed-origins",
|
|
801
|
+
"--baseline",
|
|
802
|
+
"--body",
|
|
803
|
+
"--categories",
|
|
804
|
+
"--content",
|
|
805
|
+
"--curl",
|
|
806
|
+
"--depth",
|
|
807
|
+
"-d",
|
|
808
|
+
"--domain",
|
|
809
|
+
"--expires",
|
|
810
|
+
"--filter",
|
|
811
|
+
"--frame",
|
|
812
|
+
"--fn",
|
|
813
|
+
"--label",
|
|
814
|
+
"--load",
|
|
815
|
+
"--method",
|
|
816
|
+
"--name",
|
|
817
|
+
"--older-than",
|
|
818
|
+
"--output",
|
|
819
|
+
"--prefix",
|
|
820
|
+
"--path",
|
|
821
|
+
"--port",
|
|
822
|
+
"--params",
|
|
823
|
+
"--resource-type",
|
|
824
|
+
"--resource-types",
|
|
825
|
+
"--sameSite",
|
|
826
|
+
"--scope",
|
|
827
|
+
"--selector",
|
|
828
|
+
"-s",
|
|
829
|
+
"--status",
|
|
830
|
+
"--tags",
|
|
831
|
+
"--text",
|
|
832
|
+
"--threshold",
|
|
833
|
+
"--timeout",
|
|
834
|
+
"--type",
|
|
835
|
+
"--url",
|
|
836
|
+
"--username",
|
|
837
|
+
"--password",
|
|
838
|
+
"--wait-until"
|
|
839
|
+
];
|
|
840
|
+
var OPTIONAL_GLOBAL_VALUE_FLAGS = /* @__PURE__ */ new Set(["--restore"]);
|
|
841
|
+
var VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
842
|
+
...GLOBAL_VALUE_FLAGS,
|
|
843
|
+
...COMMAND_VALUE_FLAGS
|
|
844
|
+
]);
|
|
845
|
+
var PREVALIDATED_VALUE_FLAGS = new Set(GLOBAL_VALUE_FLAGS);
|
|
846
|
+
var GLOBAL_BOOLEAN_FLAGS_WITH_OPTIONAL_VALUES = /* @__PURE__ */ new Set([
|
|
847
|
+
"--allow-file-access",
|
|
848
|
+
"--annotate",
|
|
849
|
+
"--auto-connect",
|
|
850
|
+
"--confirm-interactive",
|
|
851
|
+
"--content-boundaries",
|
|
852
|
+
"--debug",
|
|
853
|
+
"--headed",
|
|
854
|
+
"--hide-scrollbars",
|
|
855
|
+
"--ignore-https-errors",
|
|
856
|
+
"--json",
|
|
857
|
+
"--no-auto-dialog",
|
|
858
|
+
"--no-ca-cert",
|
|
859
|
+
"--no-pin-tab",
|
|
860
|
+
"--no-webmcp",
|
|
861
|
+
"--offline",
|
|
862
|
+
"--pin-tab",
|
|
863
|
+
"--quick",
|
|
864
|
+
"--fix",
|
|
865
|
+
"--quiet",
|
|
866
|
+
"-q",
|
|
867
|
+
"--verbose",
|
|
868
|
+
"-v",
|
|
869
|
+
"--webgpu"
|
|
870
|
+
]);
|
|
871
|
+
function optionalGlobalValueFlagConsumesNext(flag, nextToken) {
|
|
872
|
+
if (!OPTIONAL_GLOBAL_VALUE_FLAGS.has(flag) || nextToken === void 0 || nextToken.startsWith("-")) {
|
|
873
|
+
return false;
|
|
874
|
+
}
|
|
875
|
+
return !isKnownCommandToken(nextToken);
|
|
876
|
+
}
|
|
877
|
+
function globalFlagWidth(token, next, seenCommand) {
|
|
878
|
+
if (token.startsWith("--restore=")) {
|
|
879
|
+
return 1;
|
|
880
|
+
}
|
|
881
|
+
if (token === "--restore") {
|
|
882
|
+
return !seenCommand && optionalGlobalValueFlagConsumesNext(token, next) ? 2 : 1;
|
|
883
|
+
}
|
|
884
|
+
if (PREVALIDATED_VALUE_FLAGS.has(token)) {
|
|
885
|
+
return 2;
|
|
886
|
+
}
|
|
887
|
+
if (GLOBAL_BOOLEAN_FLAGS_WITH_OPTIONAL_VALUES.has(token)) {
|
|
888
|
+
return ["true", "false"].includes(next ?? "") ? 2 : 1;
|
|
889
|
+
}
|
|
890
|
+
return 0;
|
|
891
|
+
}
|
|
892
|
+
function projectUpstreamGlobalFlags(args) {
|
|
893
|
+
const indices = [];
|
|
894
|
+
const tokens = [];
|
|
895
|
+
let seenCommand = false;
|
|
896
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
897
|
+
const token = args[index];
|
|
898
|
+
const width = globalFlagWidth(token, args[index + 1], seenCommand);
|
|
899
|
+
if (width > 0) {
|
|
900
|
+
index += width - 1;
|
|
901
|
+
continue;
|
|
902
|
+
}
|
|
903
|
+
tokens.push(token);
|
|
904
|
+
indices.push(index);
|
|
905
|
+
if (isKnownCommandToken(token)) {
|
|
906
|
+
seenCommand = true;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
return { indices, tokens };
|
|
910
|
+
}
|
|
911
|
+
function stripUpstreamGlobalFlags(args) {
|
|
912
|
+
return projectUpstreamGlobalFlags(args).tokens;
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
// dist/extensions/agent-browser/lib/argv-descriptor.js
|
|
916
|
+
function isBooleanLiteral(token) {
|
|
917
|
+
const normalized = token?.trim().toLowerCase();
|
|
918
|
+
return normalized === "true" || normalized === "false";
|
|
919
|
+
}
|
|
920
|
+
function flagConsumesFollowingToken(token, nextToken) {
|
|
921
|
+
const normalizedToken = token.split("=", 1).at(0) ?? token;
|
|
922
|
+
if (optionalGlobalValueFlagConsumesNext(normalizedToken, nextToken)) {
|
|
923
|
+
return true;
|
|
924
|
+
}
|
|
925
|
+
if (token.includes("=")) {
|
|
926
|
+
return false;
|
|
927
|
+
}
|
|
928
|
+
return VALUE_FLAGS.has(normalizedToken) || GLOBAL_BOOLEAN_FLAGS_WITH_OPTIONAL_VALUES.has(normalizedToken) && isBooleanLiteral(nextToken);
|
|
929
|
+
}
|
|
930
|
+
function findCommandStartIndex(args) {
|
|
931
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
932
|
+
const token = args[index];
|
|
933
|
+
if (token.startsWith("--session=") || token.startsWith("--namespace=") || token.startsWith("--restore=")) {
|
|
934
|
+
continue;
|
|
935
|
+
}
|
|
936
|
+
if (token.startsWith("-")) {
|
|
937
|
+
if (flagConsumesFollowingToken(token, args[index + 1])) {
|
|
938
|
+
index += 1;
|
|
939
|
+
}
|
|
940
|
+
continue;
|
|
941
|
+
}
|
|
942
|
+
return index;
|
|
943
|
+
}
|
|
944
|
+
return void 0;
|
|
945
|
+
}
|
|
946
|
+
function extractCommandTokens(args) {
|
|
947
|
+
const commandStartIndex = findCommandStartIndex(args);
|
|
948
|
+
return commandStartIndex === void 0 ? [] : args.slice(commandStartIndex);
|
|
949
|
+
}
|
|
950
|
+
function extractUpstreamCommandTokens(args) {
|
|
951
|
+
return stripUpstreamGlobalFlags(extractCommandTokens(args));
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
// dist/extensions/agent-browser/lib/page-target-navigation.js
|
|
955
|
+
var POSITIONAL_VALUE_FLAGS = /* @__PURE__ */ new Set([...VALUE_FLAGS, "--llms"]);
|
|
956
|
+
|
|
957
|
+
// dist/extensions/agent-browser/lib/native-confirmation.js
|
|
958
|
+
function isSuccessfulNativeConfirmedClose(commandTokens, data) {
|
|
959
|
+
if (commandTokens[0] !== "confirm" || commandTokens.length !== 2 || !isRecord(data) || data.confirmed !== true || data.action !== "close") {
|
|
960
|
+
return false;
|
|
961
|
+
}
|
|
962
|
+
return isRecord(data.result) && data.result.success === true && isRecord(data.result.data) && data.result.data.closed === true;
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
// dist/extensions/agent-browser/lib/results/confirmation.js
|
|
966
|
+
var CONFIRMATION_REQUIRED_FIELD_NAMES = [
|
|
967
|
+
"confirmation_required",
|
|
968
|
+
"confirmationRequired",
|
|
969
|
+
"requires_confirmation",
|
|
970
|
+
"requiresConfirmation"
|
|
971
|
+
];
|
|
972
|
+
var CONFIRMATION_REQUIRED_RECORD_FIELD_NAMES = [
|
|
973
|
+
"confirmation",
|
|
974
|
+
"pendingConfirmation",
|
|
975
|
+
"pending_confirmation"
|
|
976
|
+
];
|
|
977
|
+
var CONFIRMATION_ID_FIELD_NAMES = ["confirmation_id", "confirmationId", "id"];
|
|
978
|
+
var CONFIRMATION_ACTION_TEXT_FIELD_NAMES = [
|
|
979
|
+
"action",
|
|
980
|
+
"description",
|
|
981
|
+
"message",
|
|
982
|
+
"summary"
|
|
983
|
+
];
|
|
984
|
+
var CONFIRMATION_REQUIRED_MARKER = "confirmation_required";
|
|
985
|
+
function getTrimmedStringField(data, fieldNames) {
|
|
986
|
+
for (const fieldName of fieldNames) {
|
|
987
|
+
const value = data[fieldName];
|
|
988
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
989
|
+
return value.trim();
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
return void 0;
|
|
993
|
+
}
|
|
994
|
+
function hasConfirmationRequiredMarker(data) {
|
|
995
|
+
return CONFIRMATION_REQUIRED_FIELD_NAMES.some((fieldName) => data[fieldName] === true) || data.type === CONFIRMATION_REQUIRED_MARKER || data.status === CONFIRMATION_REQUIRED_MARKER || data.kind === CONFIRMATION_REQUIRED_MARKER;
|
|
996
|
+
}
|
|
997
|
+
function getNestedConfirmationRecord(data) {
|
|
998
|
+
for (const fieldName of CONFIRMATION_REQUIRED_RECORD_FIELD_NAMES) {
|
|
999
|
+
const value = data[fieldName];
|
|
1000
|
+
if (isRecord(value)) {
|
|
1001
|
+
return value;
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
return void 0;
|
|
1005
|
+
}
|
|
1006
|
+
function getConfirmationPayload(data) {
|
|
1007
|
+
return isRecord(data) && data.confirmed === true && isRecord(data.result) && data.result.success === true ? data.result.data : data;
|
|
1008
|
+
}
|
|
1009
|
+
function detectConfirmationRequired(data) {
|
|
1010
|
+
const payload = getConfirmationPayload(data);
|
|
1011
|
+
if (!isRecord(payload)) {
|
|
1012
|
+
return void 0;
|
|
1013
|
+
}
|
|
1014
|
+
const nestedRecord = getNestedConfirmationRecord(payload);
|
|
1015
|
+
const candidateRecords = nestedRecord ? [payload, nestedRecord] : [payload];
|
|
1016
|
+
if (!candidateRecords.some(hasConfirmationRequiredMarker)) {
|
|
1017
|
+
return void 0;
|
|
1018
|
+
}
|
|
1019
|
+
for (const record of candidateRecords) {
|
|
1020
|
+
const id = getTrimmedStringField(record, CONFIRMATION_ID_FIELD_NAMES);
|
|
1021
|
+
if (id === void 0 || id.length === 0) {
|
|
1022
|
+
continue;
|
|
1023
|
+
}
|
|
1024
|
+
return {
|
|
1025
|
+
actionText: getTrimmedStringField(record, CONFIRMATION_ACTION_TEXT_FIELD_NAMES),
|
|
1026
|
+
id
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
1029
|
+
return void 0;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
// dist/extensions/agent-browser/lib/batch-lifecycle.js
|
|
1033
|
+
function rowCommand(value, fallback) {
|
|
1034
|
+
return Array.isArray(value) && value.every((token) => typeof token === "string") ? value : fallback;
|
|
1035
|
+
}
|
|
1036
|
+
function rowResult(row) {
|
|
1037
|
+
if (isRecord(row.result)) {
|
|
1038
|
+
return row.result;
|
|
1039
|
+
}
|
|
1040
|
+
return isRecord(row.data) ? row.data : void 0;
|
|
1041
|
+
}
|
|
1042
|
+
function rowBrowserLaunched(row, result) {
|
|
1043
|
+
const lifecycle = isRecord(row.lifecycle) ? row.lifecycle : result?.lifecycle;
|
|
1044
|
+
if (!isRecord(lifecycle) || !isRecord(lifecycle.effectiveLaunch)) {
|
|
1045
|
+
return void 0;
|
|
1046
|
+
}
|
|
1047
|
+
const launched = lifecycle.effectiveLaunch.browserLaunched;
|
|
1048
|
+
return typeof launched === "boolean" ? launched : void 0;
|
|
1049
|
+
}
|
|
1050
|
+
function lifecycleStep(value, fallback) {
|
|
1051
|
+
if (!isRecord(value)) {
|
|
1052
|
+
return void 0;
|
|
1053
|
+
}
|
|
1054
|
+
const result = rowResult(value);
|
|
1055
|
+
const command = rowCommand(value.command, fallback);
|
|
1056
|
+
return {
|
|
1057
|
+
result,
|
|
1058
|
+
succeeded: value.success === true,
|
|
1059
|
+
browserLaunched: rowBrowserLaunched(value, result),
|
|
1060
|
+
tokens: command === void 0 ? void 0 : extractUpstreamCommandTokens(command)
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
1063
|
+
function batchHasSuccessfulCloseAll(data, fallbackCommands = []) {
|
|
1064
|
+
if (!Array.isArray(data)) {
|
|
1065
|
+
return false;
|
|
1066
|
+
}
|
|
1067
|
+
return data.some((row, index) => {
|
|
1068
|
+
if (!isRecord(row) || row.success !== true) {
|
|
1069
|
+
return false;
|
|
1070
|
+
}
|
|
1071
|
+
const command = rowCommand(row.command, fallbackCommands.at(index));
|
|
1072
|
+
return command !== void 0 && !detectConfirmationRequired(row.result) && isCloseAllCommand(extractUpstreamCommandTokens(command));
|
|
1073
|
+
});
|
|
1074
|
+
}
|
|
1075
|
+
function successfulClose(step) {
|
|
1076
|
+
return step.succeeded && step.tokens !== void 0 && !detectConfirmationRequired(step.result) && (isCloseCommand(step.tokens[0]) || isSuccessfulNativeConfirmedClose(step.tokens, step.result));
|
|
1077
|
+
}
|
|
1078
|
+
function closedState(step) {
|
|
1079
|
+
const result = step.result;
|
|
1080
|
+
const closeData = step.tokens?.[0] === "confirm" && isRecord(result) && isRecord(result.result) ? result.result.data : result;
|
|
1081
|
+
return {
|
|
1082
|
+
endsClosed: true,
|
|
1083
|
+
browserActiveAfterClose: false,
|
|
1084
|
+
recordingClosedAfterBatch: true,
|
|
1085
|
+
statePath: isRecord(closeData) && typeof closeData.statePath === "string" ? closeData.statePath : void 0
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
function recordingState(state, step) {
|
|
1089
|
+
const relaunched = step.browserLaunched !== false;
|
|
1090
|
+
const browserActiveAfterClose = state.browserActiveAfterClose || relaunched;
|
|
1091
|
+
let recordingClosedAfterBatch = state.recordingClosedAfterBatch;
|
|
1092
|
+
const subcommand = step.tokens?.[1];
|
|
1093
|
+
if (step.succeeded && subcommand === "stop") {
|
|
1094
|
+
recordingClosedAfterBatch = true;
|
|
1095
|
+
} else if (step.succeeded && browserActiveAfterClose && (subcommand === "start" || subcommand === "restart")) {
|
|
1096
|
+
recordingClosedAfterBatch = false;
|
|
1097
|
+
}
|
|
1098
|
+
return {
|
|
1099
|
+
...state,
|
|
1100
|
+
endsClosed: state.endsClosed && !relaunched,
|
|
1101
|
+
browserActiveAfterClose,
|
|
1102
|
+
recordingClosedAfterBatch
|
|
1103
|
+
};
|
|
1104
|
+
}
|
|
1105
|
+
function advanceClosedState(state, step) {
|
|
1106
|
+
if (step.tokens?.[0] === "record") {
|
|
1107
|
+
return recordingState(state, step);
|
|
1108
|
+
}
|
|
1109
|
+
if (step.browserLaunched === false) {
|
|
1110
|
+
return state;
|
|
1111
|
+
}
|
|
1112
|
+
return {
|
|
1113
|
+
...state,
|
|
1114
|
+
endsClosed: false,
|
|
1115
|
+
browserActiveAfterClose: true,
|
|
1116
|
+
recordingClosedAfterBatch: step.tokens === void 0 ? false : state.recordingClosedAfterBatch
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1119
|
+
function getSuccessfulBatchCloseLifecycle(rows, fallbackCommands = []) {
|
|
1120
|
+
if (!Array.isArray(rows)) {
|
|
1121
|
+
return void 0;
|
|
1122
|
+
}
|
|
1123
|
+
let state;
|
|
1124
|
+
for (const [index, row] of rows.entries()) {
|
|
1125
|
+
const step = lifecycleStep(row, fallbackCommands.at(index));
|
|
1126
|
+
if (step === void 0) {
|
|
1127
|
+
continue;
|
|
1128
|
+
}
|
|
1129
|
+
if (successfulClose(step)) {
|
|
1130
|
+
state = closedState(step);
|
|
1131
|
+
} else if (state !== void 0) {
|
|
1132
|
+
state = advanceClosedState(state, step);
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
return state === void 0 ? void 0 : {
|
|
1136
|
+
endsClosed: state.endsClosed,
|
|
1137
|
+
recordingClosedAfterBatch: state.recordingClosedAfterBatch,
|
|
1138
|
+
statePath: state.statePath
|
|
1139
|
+
};
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
// dist/extensions/agent-browser/lib/redaction-fields.js
|
|
1143
|
+
var SENSITIVE_FIELD_NAME_PATTERN = /^(?:[A-Za-z0-9_-]*(?:api[_-]?key|access[_-]?key|private[_-]?key|secret(?:[_-]?(?:key|access[_-]?key))?|token|password|passwd|credentials?|database[_-]?url|db[_-]?url|connection[_-]?string|mongo(?:db)?[_-]?uri|redis[_-]?url)|[A-Za-z0-9]*(?:apiKey|ApiKey|apikey|privateKey|PrivateKey|databaseUrl|DatabaseUrl|dbUrl|DbUrl|connectionString|ConnectionString|mongoUri|MongoUri|mongodbUri|MongodbUri|mongoDbUri|MongoDbUri|redisUrl|RedisUrl|Token|Secret|Password|Credential|Credentials)|auth(?:orization)?|bearer|client(?:_|-)?secret|cookie|id(?:_|-)?token|pass(?:word)?|proxy(?:_|-)?authorization|refresh(?:_|-)?token|sentry(?:_|-)?key|session(?:_|-)?id|set(?:_|-)?cookie|sig(?:nature)?|write(?:_|-)?key|x(?:_|-)?api(?:_|-)?key)$/i;
|
|
1144
|
+
var ENV_SECRET_ASSIGNMENT_PATTERN = /\b((?:export\s+)?([A-Za-z_][A-Za-z0-9_-]*)(\s*[:=]\s*))(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[^\s,;]+)/g;
|
|
1145
|
+
function isSensitiveFieldName(key) {
|
|
1146
|
+
SENSITIVE_FIELD_NAME_PATTERN.lastIndex = 0;
|
|
1147
|
+
return SENSITIVE_FIELD_NAME_PATTERN.test(key);
|
|
1148
|
+
}
|
|
1149
|
+
function isEnvSecretAssignmentKey(key) {
|
|
1150
|
+
if (!isSensitiveFieldName(key)) {
|
|
1151
|
+
return false;
|
|
1152
|
+
}
|
|
1153
|
+
if (key === "password" || key.includes("_") || key.includes("-") || key === key.toUpperCase()) {
|
|
1154
|
+
return true;
|
|
1155
|
+
}
|
|
1156
|
+
return /(?:apiKey|ApiKey|privateKey|PrivateKey|databaseUrl|DatabaseUrl|dbUrl|DbUrl|connectionString|ConnectionString|mongoUri|MongoUri|mongodbUri|MongodbUri|mongoDbUri|MongoDbUri|redisUrl|RedisUrl|Token|Secret|Password|Credential|Credentials)$/.test(key);
|
|
1157
|
+
}
|
|
1158
|
+
function isLineBoundary(text, index) {
|
|
1159
|
+
return index < 0 || index >= text.length || text[index] === "\n" || text[index] === "\r";
|
|
1160
|
+
}
|
|
1161
|
+
function redactPasswordAssignment(text, match, prefix, offset) {
|
|
1162
|
+
const end = offset + match.length;
|
|
1163
|
+
if (!isLineBoundary(text, offset - 1) || !isLineBoundary(text, end) || /^(?:\[REDACTED\]|%5Bredacted%5D)/i.test(match.slice(prefix.length))) {
|
|
1164
|
+
return match;
|
|
1165
|
+
}
|
|
1166
|
+
const value = match.slice(prefix.length);
|
|
1167
|
+
const boundary = value[0] === '"' || value[0] === "'" ? -1 : value.search(/[&#](?=[A-Za-z_][A-Za-z0-9_-]*\s*=)/);
|
|
1168
|
+
return `${prefix}[REDACTED]${boundary < 0 ? "" : value.slice(boundary)}`;
|
|
1169
|
+
}
|
|
1170
|
+
function redactEnvSecretAssignments(text) {
|
|
1171
|
+
return text.replace(
|
|
1172
|
+
ENV_SECRET_ASSIGNMENT_PATTERN,
|
|
1173
|
+
// String.replace supplies match, three captures, then the source offset.
|
|
1174
|
+
(match, prefix, key, _separator, offset) => {
|
|
1175
|
+
if (!isEnvSecretAssignmentKey(key)) {
|
|
1176
|
+
return match;
|
|
1177
|
+
}
|
|
1178
|
+
return key === "password" ? redactPasswordAssignment(text, match, prefix, offset) : `${prefix}[REDACTED]`;
|
|
1179
|
+
}
|
|
1180
|
+
);
|
|
1181
|
+
}
|
|
1182
|
+
function credentialTrailingPunctuation(credential) {
|
|
1183
|
+
return credential.match(/[,.:;!?]+$/)?.[0] ?? "";
|
|
1184
|
+
}
|
|
1185
|
+
function formatRedactedCredential(label, credential, trailing = "") {
|
|
1186
|
+
return `${label} [REDACTED]${credentialTrailingPunctuation(credential)}${trailing}`;
|
|
1187
|
+
}
|
|
1188
|
+
function redactBearerCredentials(text) {
|
|
1189
|
+
return text.replace(
|
|
1190
|
+
/((?:\b([A-Za-z][A-Za-z0-9_-]*)\s*[:=]\s*|(?:^|\s)(?:-H\s*|--header(?:\s+|=)))["']?Bearer)\s+([^\s"',)[\]]+)([),.]?)/gi,
|
|
1191
|
+
// String.replace supplies the match followed by this expression's four captures.
|
|
1192
|
+
(match, label, field, credential, trailing) => {
|
|
1193
|
+
if (field !== void 0 && field.length > 0 && !isSensitiveFieldName(field)) {
|
|
1194
|
+
return match;
|
|
1195
|
+
}
|
|
1196
|
+
return formatRedactedCredential(label, credential, trailing);
|
|
1197
|
+
}
|
|
1198
|
+
).replace(/\b(Bearer)\s+([^\s\\"',)[\]]+)([),.]?)/gi, (match, label, credential, trailing) => {
|
|
1199
|
+
const token = credential.slice(0, credential.length - credentialTrailingPunctuation(credential).length);
|
|
1200
|
+
if (!/^[A-Za-z0-9._~+/-]+=*$/.test(token) || !/[0-9._~+/=-]/.test(token)) {
|
|
1201
|
+
return match;
|
|
1202
|
+
}
|
|
1203
|
+
return formatRedactedCredential(label, credential, trailing);
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
function redactStandaloneBasicCredential(text) {
|
|
1207
|
+
return text.replace(/\b(Basic)\s+([A-Za-z0-9+/=]{12,})/gi, (match, label, credential) => {
|
|
1208
|
+
if (!/[0-9+/=]/.test(credential)) {
|
|
1209
|
+
return match;
|
|
1210
|
+
}
|
|
1211
|
+
return `${label} [REDACTED]`;
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
// dist/extensions/agent-browser/lib/redaction-json.js
|
|
1216
|
+
function nextQuotePosition(options) {
|
|
1217
|
+
if (options.char === '"') {
|
|
1218
|
+
return options.index;
|
|
1219
|
+
}
|
|
1220
|
+
return options.char === "\\" ? options.quoteAfterNext : options.quoteAtNext;
|
|
1221
|
+
}
|
|
1222
|
+
function buildJsonBoundaries(text) {
|
|
1223
|
+
const boundaries = new Int32Array(text.length + 1).fill(-1);
|
|
1224
|
+
let quoteAtNext = -1;
|
|
1225
|
+
let quoteAfterNext = -1;
|
|
1226
|
+
for (let index = text.length - 1; index >= 0; index -= 1) {
|
|
1227
|
+
const char = text[index];
|
|
1228
|
+
switch (char) {
|
|
1229
|
+
case "}":
|
|
1230
|
+
case "]":
|
|
1231
|
+
boundaries[index] = index;
|
|
1232
|
+
break;
|
|
1233
|
+
case '"':
|
|
1234
|
+
boundaries[index] = quoteAtNext < 0 ? -1 : boundaries[quoteAtNext + 1];
|
|
1235
|
+
break;
|
|
1236
|
+
case "{":
|
|
1237
|
+
case "[": {
|
|
1238
|
+
const end = boundaries[index + 1];
|
|
1239
|
+
boundaries[index] = end >= 0 && text[end] === (char === "{" ? "}" : "]") ? boundaries[end + 1] : -1;
|
|
1240
|
+
break;
|
|
1241
|
+
}
|
|
1242
|
+
default:
|
|
1243
|
+
boundaries[index] = boundaries[index + 1];
|
|
1244
|
+
}
|
|
1245
|
+
const quote = nextQuotePosition({ char, index, quoteAtNext, quoteAfterNext });
|
|
1246
|
+
quoteAfterNext = quoteAtNext;
|
|
1247
|
+
quoteAtNext = quote;
|
|
1248
|
+
}
|
|
1249
|
+
return boundaries;
|
|
1250
|
+
}
|
|
1251
|
+
function createBalancedJsonEndFinder(text) {
|
|
1252
|
+
let boundaries;
|
|
1253
|
+
return (startIndex) => {
|
|
1254
|
+
const opener = text[startIndex];
|
|
1255
|
+
if (opener !== "{" && opener !== "[") {
|
|
1256
|
+
return;
|
|
1257
|
+
}
|
|
1258
|
+
boundaries ??= buildJsonBoundaries(text);
|
|
1259
|
+
const end = boundaries[startIndex + 1];
|
|
1260
|
+
return end >= 0 && text[end] === (opener === "{" ? "}" : "]") ? end : void 0;
|
|
1261
|
+
};
|
|
1262
|
+
}
|
|
1263
|
+
function parseJsonString(token) {
|
|
1264
|
+
const value = JSON.parse(token);
|
|
1265
|
+
if (typeof value !== "string") {
|
|
1266
|
+
throw new Error("Expected a JSON string token");
|
|
1267
|
+
}
|
|
1268
|
+
return value;
|
|
1269
|
+
}
|
|
1270
|
+
function isSerializedJson(text) {
|
|
1271
|
+
if (text === "[REDACTED]" || !/^\s*[[{"\d\-tfn]/.test(text)) {
|
|
1272
|
+
return false;
|
|
1273
|
+
}
|
|
1274
|
+
try {
|
|
1275
|
+
JSON.parse(text);
|
|
1276
|
+
return true;
|
|
1277
|
+
} catch {
|
|
1278
|
+
return false;
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
function findJsonValueEnd(text, start, findEnd) {
|
|
1282
|
+
const balancedEnd = findEnd(start);
|
|
1283
|
+
if (balancedEnd !== void 0) {
|
|
1284
|
+
return balancedEnd + 1;
|
|
1285
|
+
}
|
|
1286
|
+
if (text[start] === '"') {
|
|
1287
|
+
const strings = /"(?:\\.|[^"\\])*"/g;
|
|
1288
|
+
strings.lastIndex = start;
|
|
1289
|
+
const fieldValue = strings.exec(text);
|
|
1290
|
+
if (fieldValue === null) {
|
|
1291
|
+
throw new Error("Expected a validated JSON string field value");
|
|
1292
|
+
}
|
|
1293
|
+
return parseJsonString(fieldValue[0]) === "[REDACTED]" ? void 0 : strings.lastIndex;
|
|
1294
|
+
}
|
|
1295
|
+
let end = start;
|
|
1296
|
+
while (end < text.length && !/[\s,\]}]/.test(text[end])) {
|
|
1297
|
+
end += 1;
|
|
1298
|
+
}
|
|
1299
|
+
return end;
|
|
1300
|
+
}
|
|
1301
|
+
function redactSerializedJson(text, redact) {
|
|
1302
|
+
if (!isSerializedJson(text)) {
|
|
1303
|
+
return;
|
|
1304
|
+
}
|
|
1305
|
+
let output = "";
|
|
1306
|
+
let cursor = 0;
|
|
1307
|
+
const findEnd = createBalancedJsonEndFinder(text);
|
|
1308
|
+
const strings = /"(?:\\.|[^"\\])*"/g;
|
|
1309
|
+
let match;
|
|
1310
|
+
while ((match = strings.exec(text)) !== null) {
|
|
1311
|
+
const end = strings.lastIndex;
|
|
1312
|
+
const value = parseJsonString(match[0]);
|
|
1313
|
+
const redacted = redact(value);
|
|
1314
|
+
if (redacted !== value) {
|
|
1315
|
+
output += text.slice(cursor, match.index) + JSON.stringify(redacted);
|
|
1316
|
+
cursor = end;
|
|
1317
|
+
}
|
|
1318
|
+
const separator = /^\s*:\s*/.exec(text.slice(end));
|
|
1319
|
+
if (separator === null || !isSensitiveFieldName(value)) {
|
|
1320
|
+
continue;
|
|
1321
|
+
}
|
|
1322
|
+
const valueStart = end + separator[0].length;
|
|
1323
|
+
const valueEnd = findJsonValueEnd(text, valueStart, findEnd);
|
|
1324
|
+
if (valueEnd === void 0) {
|
|
1325
|
+
strings.lastIndex = valueStart;
|
|
1326
|
+
strings.exec(text);
|
|
1327
|
+
continue;
|
|
1328
|
+
}
|
|
1329
|
+
output += text.slice(cursor, valueStart) + '"[REDACTED]"';
|
|
1330
|
+
cursor = valueEnd;
|
|
1331
|
+
strings.lastIndex = valueEnd;
|
|
1332
|
+
}
|
|
1333
|
+
return output + text.slice(cursor);
|
|
1334
|
+
}
|
|
1335
|
+
function redactEmbeddedStructuredText(text, redact) {
|
|
1336
|
+
let output = "";
|
|
1337
|
+
let cursor = 0;
|
|
1338
|
+
const findEnd = createBalancedJsonEndFinder(text);
|
|
1339
|
+
const openers = /[[{]/g;
|
|
1340
|
+
let match;
|
|
1341
|
+
while ((match = openers.exec(text)) !== null) {
|
|
1342
|
+
const endIndex = findEnd(match.index);
|
|
1343
|
+
if (endIndex === void 0) {
|
|
1344
|
+
continue;
|
|
1345
|
+
}
|
|
1346
|
+
const candidate = text.slice(match.index, endIndex + 1);
|
|
1347
|
+
const redacted = redactSerializedJson(candidate, redact) ?? candidate;
|
|
1348
|
+
if (redacted !== candidate) {
|
|
1349
|
+
output += text.slice(cursor, match.index) + redacted;
|
|
1350
|
+
cursor = endIndex + 1;
|
|
1351
|
+
}
|
|
1352
|
+
openers.lastIndex = endIndex + 1;
|
|
1353
|
+
}
|
|
1354
|
+
return cursor === 0 ? text : output + text.slice(cursor);
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
// dist/extensions/agent-browser/lib/redaction-url.js
|
|
1358
|
+
var SENSITIVE_QUERY_PARAM_PATTERN = /^(?:access(?:_|-)?token|api(?:_|-)?key|auth|authorization|authorization(?:_|-)?session(?:_|-)?id|bearer|client(?:_|-)?secret|code|cookie|id(?:_|-)?token|key|pass(?:word)?|refresh(?:_|-)?token|relay(?:_|-)?state|saml(?:_|-)?request|saml(?:_|-)?response|secret|sentry(?:_|-)?key|session(?:_|-)?id|sig(?:nature)?|token|write(?:_|-)?key)$/i;
|
|
1359
|
+
var AUTH_STATE_QUERY_PARAM_PATTERN = /^(?:nonce|state)$/i;
|
|
1360
|
+
var AUTH_URL_CONTEXT_PATTERN = /(?:^|[./_-])(?:auth|authorize|callback|login|oauth2?|oidc|saml|sso)(?:[./?#_-]|$)/i;
|
|
1361
|
+
function shouldRedactQueryParam(name) {
|
|
1362
|
+
return SENSITIVE_QUERY_PARAM_PATTERN.test(name) || isSensitiveFieldName(name);
|
|
1363
|
+
}
|
|
1364
|
+
function isSensitiveParameter(name, authContext) {
|
|
1365
|
+
return shouldRedactQueryParam(name) || authContext && AUTH_STATE_QUERY_PARAM_PATTERN.test(name);
|
|
1366
|
+
}
|
|
1367
|
+
function redactParameters(params, authContext) {
|
|
1368
|
+
let mutated = false;
|
|
1369
|
+
for (const [name] of params) {
|
|
1370
|
+
if (isSensitiveParameter(name, authContext)) {
|
|
1371
|
+
params.set(name, "[REDACTED]");
|
|
1372
|
+
mutated = true;
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
return mutated;
|
|
1376
|
+
}
|
|
1377
|
+
function getHashParameters(hash) {
|
|
1378
|
+
const text = hash.startsWith("#") ? hash.slice(1) : hash;
|
|
1379
|
+
return text.includes("=") ? new URLSearchParams(text) : void 0;
|
|
1380
|
+
}
|
|
1381
|
+
function redactUrlToken(token) {
|
|
1382
|
+
let parsed;
|
|
1383
|
+
try {
|
|
1384
|
+
parsed = new URL(token);
|
|
1385
|
+
} catch {
|
|
1386
|
+
return token;
|
|
1387
|
+
}
|
|
1388
|
+
const originalHref = parsed.href;
|
|
1389
|
+
if (parsed.username.length > 0) {
|
|
1390
|
+
parsed.username = "[REDACTED]";
|
|
1391
|
+
}
|
|
1392
|
+
if (parsed.password.length > 0) {
|
|
1393
|
+
parsed.password = "[REDACTED]";
|
|
1394
|
+
}
|
|
1395
|
+
const hashParams = getHashParameters(parsed.hash);
|
|
1396
|
+
const authContext = AUTH_URL_CONTEXT_PATTERN.test(`${parsed.hostname}${parsed.pathname}`) || [...parsed.searchParams.keys(), ...hashParams?.keys() ?? []].some(shouldRedactQueryParam);
|
|
1397
|
+
redactParameters(parsed.searchParams, authContext);
|
|
1398
|
+
if (hashParams && redactParameters(hashParams, authContext)) {
|
|
1399
|
+
parsed.hash = `#${hashParams.toString()}`;
|
|
1400
|
+
}
|
|
1401
|
+
return parsed.href === originalHref ? token : parsed.href;
|
|
1402
|
+
}
|
|
1403
|
+
function decodeParameterName(raw) {
|
|
1404
|
+
try {
|
|
1405
|
+
return decodeURIComponent(raw.replace(/\+/g, " "));
|
|
1406
|
+
} catch {
|
|
1407
|
+
return raw;
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
function redactLooseUrlParameterText(text) {
|
|
1411
|
+
return text.replace(/(?<![^\s"'`<>\])}])[^\s"'`<>\])}]*[?#&][^\s"'`<>\])}]*/g, (token) => {
|
|
1412
|
+
const queryNames = [...token.matchAll(/[?#&]([^=&#\s"'`<>\])}]+)=/g)].map((match) => decodeParameterName(match[1]));
|
|
1413
|
+
const authContext = AUTH_URL_CONTEXT_PATTERN.test(token) || queryNames.some(shouldRedactQueryParam);
|
|
1414
|
+
return token.replace(/([?#&])([^=&#\s"'`<>\])}]+)=([^&#\s"'`<>\])}]*)/g, (match, separator, rawName, rawValue) => {
|
|
1415
|
+
if (rawValue === "[REDACTED" || rawValue === "[REDACTED]" || /%5Bredacted%5D/i.test(rawValue)) {
|
|
1416
|
+
return match;
|
|
1417
|
+
}
|
|
1418
|
+
if (!isSensitiveParameter(decodeParameterName(rawName), authContext)) {
|
|
1419
|
+
return match;
|
|
1420
|
+
}
|
|
1421
|
+
return `${separator}${rawName}=[REDACTED]`;
|
|
1422
|
+
});
|
|
1423
|
+
});
|
|
1424
|
+
}
|
|
1425
|
+
function redactLooseUrlUserinfo(text) {
|
|
1426
|
+
return text.replace(/\b([A-Za-z][A-Za-z0-9+.-]*:\/\/)([^\s"'`/@]+)@([^\s"'`]+)/g, (match, prefix, userinfo, suffix) => {
|
|
1427
|
+
if (/%5Bredacted%5D/i.test(userinfo)) {
|
|
1428
|
+
return match;
|
|
1429
|
+
}
|
|
1430
|
+
if (userinfo.includes("[REDACTED]")) {
|
|
1431
|
+
return redactLooseUrlParameterText(match);
|
|
1432
|
+
}
|
|
1433
|
+
return redactLooseUrlParameterText(`${prefix}${userinfo.includes(":") ? "[REDACTED]:[REDACTED]" : "[REDACTED]"}@${suffix}`);
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
function redactLooseUrls(text) {
|
|
1437
|
+
const urls = text.replace(/\b[A-Za-z][A-Za-z0-9+.-]*:\/\/[^\s"'`<>\])]+/g, (match) => redactUrlToken(match));
|
|
1438
|
+
return redactLooseUrlParameterText(redactLooseUrlUserinfo(urls));
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
// dist/extensions/agent-browser/lib/runtime-redaction.js
|
|
1442
|
+
function redactSensitiveText(text) {
|
|
1443
|
+
const serialized = redactSerializedJson(text, redactSensitiveText);
|
|
1444
|
+
if (serialized !== void 0) {
|
|
1445
|
+
return serialized;
|
|
1446
|
+
}
|
|
1447
|
+
const embedded = redactEmbeddedStructuredText(text, redactSensitiveText);
|
|
1448
|
+
const credentials = redactStandaloneBasicCredential(redactBearerCredentials(redactLooseUrls(embedded))).replace(/\b(Authorization\s*:\s*Basic)\s+[^\s",]+/gi, "$1 [REDACTED]").replace(/\b(Cookie|Set-Cookie)\s*:\s*[^\n\r"]+/gi, "$1: [REDACTED]");
|
|
1449
|
+
return redactEmbeddedStructuredText(redactEnvSecretAssignments(credentials), redactSensitiveText);
|
|
1450
|
+
}
|
|
1451
|
+
function redactSensitiveValue(value) {
|
|
1452
|
+
if (typeof value === "string") {
|
|
1453
|
+
return redactSensitiveText(value);
|
|
1454
|
+
}
|
|
1455
|
+
if (Array.isArray(value)) {
|
|
1456
|
+
return value.map((item) => redactSensitiveValue(item));
|
|
1457
|
+
}
|
|
1458
|
+
if (!isRecord(value)) {
|
|
1459
|
+
return value;
|
|
1460
|
+
}
|
|
1461
|
+
return Object.fromEntries(Object.entries(value).map(([key, entryValue]) => [
|
|
1462
|
+
key,
|
|
1463
|
+
isSensitiveFieldName(key) ? "[REDACTED]" : redactSensitiveValue(entryValue)
|
|
1464
|
+
]));
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
// dist/extensions/agent-browser/lib/browser-value-parsing.js
|
|
1468
|
+
function isBrowserStringArray(value) {
|
|
1469
|
+
if (!Array.isArray(value)) {
|
|
1470
|
+
return false;
|
|
1471
|
+
}
|
|
1472
|
+
const rows = value;
|
|
1473
|
+
return rows.every((row) => typeof row === "string");
|
|
1474
|
+
}
|
|
1475
|
+
function browserStringArray(value) {
|
|
1476
|
+
if (!Array.isArray(value)) {
|
|
1477
|
+
return [];
|
|
1478
|
+
}
|
|
1479
|
+
const rows = value;
|
|
1480
|
+
return rows.filter((row) => typeof row === "string");
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
// dist/extensions/agent-browser/lib/session-page-observation.js
|
|
1484
|
+
function normalizeComparableUrl(url) {
|
|
1485
|
+
const normalizedUrl = url?.trim();
|
|
1486
|
+
if (normalizedUrl === void 0 || normalizedUrl.length === 0) {
|
|
1487
|
+
return void 0;
|
|
1488
|
+
}
|
|
1489
|
+
try {
|
|
1490
|
+
const parsedUrl = new URL(normalizedUrl);
|
|
1491
|
+
parsedUrl.hash = "";
|
|
1492
|
+
return parsedUrl.toString();
|
|
1493
|
+
} catch {
|
|
1494
|
+
return void 0;
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
function trimmedOptionalValue(value) {
|
|
1498
|
+
const trimmed = value?.trim();
|
|
1499
|
+
return trimmed !== void 0 && trimmed.length > 0 ? trimmed : void 0;
|
|
1500
|
+
}
|
|
1501
|
+
function normalizeSessionTabTarget(target) {
|
|
1502
|
+
if (!target) {
|
|
1503
|
+
return void 0;
|
|
1504
|
+
}
|
|
1505
|
+
const url = trimmedOptionalValue(target.url);
|
|
1506
|
+
if (url === void 0 || normalizeComparableUrl(url) === void 0) {
|
|
1507
|
+
return void 0;
|
|
1508
|
+
}
|
|
1509
|
+
const targetId = trimmedOptionalValue(target.targetId);
|
|
1510
|
+
return {
|
|
1511
|
+
...targetId !== void 0 ? { targetId } : {},
|
|
1512
|
+
title: trimmedOptionalValue(target.title),
|
|
1513
|
+
url
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
function extractStringResultField(data, fieldName) {
|
|
1517
|
+
if (typeof data === "string") {
|
|
1518
|
+
if (fieldName === "value") {
|
|
1519
|
+
return data;
|
|
1520
|
+
}
|
|
1521
|
+
const text2 = data.trim();
|
|
1522
|
+
return text2.length > 0 ? text2 : void 0;
|
|
1523
|
+
}
|
|
1524
|
+
if (!isRecord(data) || typeof data[fieldName] !== "string") {
|
|
1525
|
+
return void 0;
|
|
1526
|
+
}
|
|
1527
|
+
if (fieldName === "value") {
|
|
1528
|
+
return data[fieldName];
|
|
1529
|
+
}
|
|
1530
|
+
const text = data[fieldName].trim();
|
|
1531
|
+
return text.length > 0 ? text : void 0;
|
|
1532
|
+
}
|
|
1533
|
+
function extractSessionTabTargetFromData(data) {
|
|
1534
|
+
const directTarget = normalizeSessionTabTarget({
|
|
1535
|
+
targetId: isRecord(data) && typeof data.targetId === "string" ? data.targetId : void 0,
|
|
1536
|
+
title: extractStringResultField(data, "title"),
|
|
1537
|
+
url: extractStringResultField(data, "url")
|
|
1538
|
+
});
|
|
1539
|
+
if (directTarget) {
|
|
1540
|
+
return directTarget;
|
|
1541
|
+
}
|
|
1542
|
+
if (isRecord(data) && typeof data.origin === "string") {
|
|
1543
|
+
return normalizeSessionTabTarget({ url: data.origin });
|
|
1544
|
+
}
|
|
1545
|
+
return void 0;
|
|
1546
|
+
}
|
|
1547
|
+
function extractBatchResultCommand(item) {
|
|
1548
|
+
return browserStringArray(item.command);
|
|
1549
|
+
}
|
|
1550
|
+
function confirmedNavigationResult(command, data) {
|
|
1551
|
+
if (command === "confirm" && isRecord(data) && data.confirmed === true && (data.action === "navigate" || data.action === "url") && isRecord(data.result) && data.result.success === true && !detectConfirmationRequired(data)) {
|
|
1552
|
+
return data.result;
|
|
1553
|
+
}
|
|
1554
|
+
return void 0;
|
|
1555
|
+
}
|
|
1556
|
+
function extractSessionTabTargetFromCommandData(commandTokens, data) {
|
|
1557
|
+
const [command, subcommand] = commandTokens;
|
|
1558
|
+
const confirmed = confirmedNavigationResult(command, data);
|
|
1559
|
+
if (confirmed) {
|
|
1560
|
+
return extractSessionTabTargetFromData(confirmed.data);
|
|
1561
|
+
}
|
|
1562
|
+
if (command === "get" && subcommand === "url") {
|
|
1563
|
+
return normalizeSessionTabTarget({
|
|
1564
|
+
url: extractStringResultField(data, "url") ?? extractStringResultField(data, "result")
|
|
1565
|
+
});
|
|
1566
|
+
}
|
|
1567
|
+
return isReadOnlyDiagnosticSessionTargetCommand(command, subcommand) ? void 0 : extractSessionTabTargetFromData(data);
|
|
1568
|
+
}
|
|
1569
|
+
var BatchTargetObservation = class {
|
|
1570
|
+
target;
|
|
1571
|
+
pendingTitle;
|
|
1572
|
+
observe(item) {
|
|
1573
|
+
if (detectConfirmationRequired(item.result)) {
|
|
1574
|
+
return;
|
|
1575
|
+
}
|
|
1576
|
+
if (this.target?.targetId !== void 0 && this.target.targetId.length > 0) {
|
|
1577
|
+
this.target = normalizeSessionTabTarget({ title: this.target.title, url: this.target.url });
|
|
1578
|
+
}
|
|
1579
|
+
const tokens = extractUpstreamCommandTokens(extractBatchResultCommand(item));
|
|
1580
|
+
this.invalidateTransition(tokens);
|
|
1581
|
+
if (item.success === false) {
|
|
1582
|
+
return;
|
|
1583
|
+
}
|
|
1584
|
+
this.observeResult(tokens, item.result);
|
|
1585
|
+
}
|
|
1586
|
+
invalidateTransition(tokens) {
|
|
1587
|
+
const [name, subcommand] = tokens;
|
|
1588
|
+
if (isOpenNavigationCommand(name) || isUnverifiedPageTransitionCommand(name, subcommand) || name === "click" && tokens.includes("--new-tab")) {
|
|
1589
|
+
this.target = void 0;
|
|
1590
|
+
this.pendingTitle = void 0;
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
observeResult(tokens, result) {
|
|
1594
|
+
const [name, subcommand] = tokens;
|
|
1595
|
+
if (isCloseCommand(name) || isSuccessfulNativeConfirmedClose(tokens, result)) {
|
|
1596
|
+
this.target = void 0;
|
|
1597
|
+
this.pendingTitle = void 0;
|
|
1598
|
+
return;
|
|
1599
|
+
}
|
|
1600
|
+
if (name === "get" && subcommand === "title") {
|
|
1601
|
+
this.pendingTitle = extractStringResultField(result, "title");
|
|
1602
|
+
return;
|
|
1603
|
+
}
|
|
1604
|
+
if (name === "get" && subcommand === "url") {
|
|
1605
|
+
const target = normalizeSessionTabTarget({
|
|
1606
|
+
title: this.pendingTitle,
|
|
1607
|
+
url: extractStringResultField(result, "url")
|
|
1608
|
+
});
|
|
1609
|
+
if (target) {
|
|
1610
|
+
this.target = target;
|
|
1611
|
+
}
|
|
1612
|
+
} else {
|
|
1613
|
+
const target = extractSessionTabTargetFromCommandData(tokens.slice(0, 2), result);
|
|
1614
|
+
if (target) {
|
|
1615
|
+
this.target = target;
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
this.pendingTitle = void 0;
|
|
1619
|
+
}
|
|
1620
|
+
};
|
|
1621
|
+
function extractSessionTabTargetFromBatchResults(data) {
|
|
1622
|
+
if (!Array.isArray(data)) {
|
|
1623
|
+
return void 0;
|
|
1624
|
+
}
|
|
1625
|
+
const observation = new BatchTargetObservation();
|
|
1626
|
+
for (const item of data) {
|
|
1627
|
+
if (isRecord(item)) {
|
|
1628
|
+
observation.observe(item);
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
return observation.target;
|
|
1632
|
+
}
|
|
1633
|
+
function buildNoActivePageRefSnapshotInvalidation() {
|
|
1634
|
+
return {
|
|
1635
|
+
reason: "no-active-page",
|
|
1636
|
+
summary: "The latest snapshot for this session reported No active page. Old page-scoped refs are invalid until snapshot -i succeeds."
|
|
1637
|
+
};
|
|
1638
|
+
}
|
|
1639
|
+
function isNoActivePageSnapshotFailure(command, text) {
|
|
1640
|
+
return command === "snapshot" && /\bno active page\b/i.test(text ?? "");
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
// dist/extensions/agent-browser/lib/results/artifact-manifest-validation.js
|
|
1644
|
+
function finiteNonnegative(value) {
|
|
1645
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
1646
|
+
}
|
|
1647
|
+
function safeCount(value) {
|
|
1648
|
+
return finiteNonnegative(value) && Number.isSafeInteger(value);
|
|
1649
|
+
}
|
|
1650
|
+
function optionalStrings(value, keys) {
|
|
1651
|
+
return keys.every((key) => value[key] === void 0 || typeof value[key] === "string");
|
|
1652
|
+
}
|
|
1653
|
+
function nullableStrings(value, keys) {
|
|
1654
|
+
return keys.every((key) => value[key] === null || typeof value[key] === "string");
|
|
1655
|
+
}
|
|
1656
|
+
function nullableNumbers(value, keys) {
|
|
1657
|
+
return keys.every((key) => value[key] === null || finiteNonnegative(value[key]));
|
|
1658
|
+
}
|
|
1659
|
+
function nullableBoolean(value) {
|
|
1660
|
+
return value === null || typeof value === "boolean";
|
|
1661
|
+
}
|
|
1662
|
+
function captureIsValid(value) {
|
|
1663
|
+
return nullableStrings(value, [
|
|
1664
|
+
"startedAt",
|
|
1665
|
+
"endedAt",
|
|
1666
|
+
"firstFrameAt",
|
|
1667
|
+
"lastFrameAt",
|
|
1668
|
+
"timestampSource"
|
|
1669
|
+
]) && nullableNumbers(value, [
|
|
1670
|
+
"durationMs",
|
|
1671
|
+
"firstFrameAfterMs",
|
|
1672
|
+
"lastFrameAfterMs",
|
|
1673
|
+
"averageFps",
|
|
1674
|
+
"maxFrameGapMs"
|
|
1675
|
+
]);
|
|
1676
|
+
}
|
|
1677
|
+
function outputIsValid(value) {
|
|
1678
|
+
return nullableStrings(value, ["durationSource"]) && nullableNumbers(value, [
|
|
1679
|
+
"frames",
|
|
1680
|
+
"fps",
|
|
1681
|
+
"encodedFrames",
|
|
1682
|
+
"durationMs",
|
|
1683
|
+
"heldFrames",
|
|
1684
|
+
"droppedFrames",
|
|
1685
|
+
"skippedFrames"
|
|
1686
|
+
]) && nullableBoolean(value.encoderSucceeded);
|
|
1687
|
+
}
|
|
1688
|
+
function recordingIsValid(value) {
|
|
1689
|
+
if (!isRecord(value) || !isRecord(value.capture) || !isRecord(value.output) || !isRecord(value.file)) {
|
|
1690
|
+
return false;
|
|
1691
|
+
}
|
|
1692
|
+
return recordingScalarsAreValid(value) && captureIsValid(value.capture) && outputIsValid(value.output) && nullableBoolean(value.file.exists) && nullableNumbers(value.file, ["sizeBytes"]);
|
|
1693
|
+
}
|
|
1694
|
+
function recordingScalarsAreValid(value) {
|
|
1695
|
+
return typeof value.warning === "string" && typeof value.path === "string" && nullableStrings(value, ["recordingId", "error"]) && nullableBoolean(value.success) && nullableNumbers(value, ["frames", "capturedFrames", "fps"]);
|
|
1696
|
+
}
|
|
1697
|
+
function optionalNumbersAreValid(value) {
|
|
1698
|
+
return ["evictedAtMs", "recordingStartedAtMs"].every((key) => value[key] === void 0 || typeof value[key] === "number" && Number.isFinite(value[key])) && (value.sizeBytes === void 0 || finiteNonnegative(value.sizeBytes));
|
|
1699
|
+
}
|
|
1700
|
+
function optionalRecordingIsValid(value) {
|
|
1701
|
+
return (value.recordingState === void 0 || value.recordingState === "openRecording") && (value.recording === void 0 || recordingIsValid(value.recording)) && (value.status === void 0 || [
|
|
1702
|
+
"failed",
|
|
1703
|
+
"missing",
|
|
1704
|
+
"pending",
|
|
1705
|
+
"repaired-from-temp",
|
|
1706
|
+
"saved",
|
|
1707
|
+
"stale",
|
|
1708
|
+
"unverified",
|
|
1709
|
+
"upstream-temp-only"
|
|
1710
|
+
].some((status) => status === value.status));
|
|
1711
|
+
}
|
|
1712
|
+
function optionalEvidenceIsValid(value) {
|
|
1713
|
+
return optionalStrings(value, [
|
|
1714
|
+
"absolutePath",
|
|
1715
|
+
"command",
|
|
1716
|
+
"cwd",
|
|
1717
|
+
"extension",
|
|
1718
|
+
"mediaType",
|
|
1719
|
+
"namespace",
|
|
1720
|
+
"requestedPath",
|
|
1721
|
+
"session",
|
|
1722
|
+
"subcommand"
|
|
1723
|
+
]) && (value.exists === void 0 || typeof value.exists === "boolean") && optionalNumbersAreValid(value) && optionalRecordingIsValid(value);
|
|
1724
|
+
}
|
|
1725
|
+
function isManifestEntry(value) {
|
|
1726
|
+
if (!isRecord(value)) {
|
|
1727
|
+
return false;
|
|
1728
|
+
}
|
|
1729
|
+
return typeof value.path === "string" && value.path.trim().length > 0 && typeof value.createdAtMs === "number" && Number.isFinite(value.createdAtMs) && ["evicted", "ephemeral", "live", "missing"].some((state) => state === value.retentionState) && ["explicit-path", "persistent-session", "process-temp"].some((scope) => scope === value.storageScope) && ["download", "file", "har", "image", "pdf", "profile", "trace", "video", "spill"].some((kind) => kind === value.kind) && optionalEvidenceIsValid(value);
|
|
1730
|
+
}
|
|
1731
|
+
function manifestCountsAreValid(value) {
|
|
1732
|
+
return safeCount(value.maxEntries) && value.maxEntries !== 0 && safeCount(value.liveCount) && safeCount(value.evictedCount);
|
|
1733
|
+
}
|
|
1734
|
+
function isSessionArtifactManifest(value) {
|
|
1735
|
+
if (!isRecord(value)) {
|
|
1736
|
+
return false;
|
|
1737
|
+
}
|
|
1738
|
+
return value.version === 1 && Array.isArray(value.entries) && value.entries.every(isManifestEntry) && typeof value.updatedAtMs === "number" && Number.isFinite(value.updatedAtMs) && manifestCountsAreValid(value);
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
// dist/extensions/agent-browser/lib/results/artifact-manifest.js
|
|
1742
|
+
function isPendingRecordingCommand(command, subcommand, kind) {
|
|
1743
|
+
return command === "record" && (subcommand === "start" || subcommand === "restart") && kind === "video";
|
|
1744
|
+
}
|
|
1745
|
+
function isPendingRecordingArtifact(artifact) {
|
|
1746
|
+
return artifact.recordingState === "openRecording" || artifact.status === "pending" || artifact.status === void 0 && isPendingRecordingCommand(artifact.command, artifact.subcommand, artifact.kind);
|
|
1747
|
+
}
|
|
1748
|
+
function getSessionArtifactManifestEntryKey(entry) {
|
|
1749
|
+
const pathKey = entry.storageScope === "explicit-path" && entry.absolutePath !== void 0 && entry.absolutePath.length > 0 ? `${entry.storageScope}:${entry.absolutePath}` : `${entry.storageScope}:${entry.path}`;
|
|
1750
|
+
const recordingSessionKey = entry.command === "record" && entry.kind === "video" && entry.session !== void 0 && entry.session.length > 0 ? getAgentBrowserSessionIdentityKey(entry.session, entry.namespace) : void 0;
|
|
1751
|
+
return recordingSessionKey !== void 0 && recordingSessionKey.length > 0 ? `${pathKey}\0${recordingSessionKey}` : pathKey;
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
// dist/extensions/agent-browser/lib/results/presentation/common.js
|
|
1755
|
+
function getNestedLifecycleRow(row) {
|
|
1756
|
+
return isRecord(row) ? row.result ?? row.data ?? row : row;
|
|
1757
|
+
}
|
|
1758
|
+
function extractAgentBrowserLifecycle(result) {
|
|
1759
|
+
if (Array.isArray(result)) {
|
|
1760
|
+
let latest;
|
|
1761
|
+
for (const row of result) {
|
|
1762
|
+
const nested = getNestedLifecycleRow(row);
|
|
1763
|
+
latest = extractAgentBrowserLifecycle(nested) ?? latest;
|
|
1764
|
+
}
|
|
1765
|
+
return latest;
|
|
1766
|
+
}
|
|
1767
|
+
if (!isRecord(result)) {
|
|
1768
|
+
return void 0;
|
|
1769
|
+
}
|
|
1770
|
+
if (isRecord(result.lifecycle) && isRecord(result.lifecycle.effectiveLaunch)) {
|
|
1771
|
+
const browserLaunched = result.lifecycle.effectiveLaunch.browserLaunched;
|
|
1772
|
+
if (typeof browserLaunched === "boolean") {
|
|
1773
|
+
return { effectiveLaunch: { browserLaunched } };
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
return extractAgentBrowserLifecycle(result.result ?? result.data);
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1779
|
+
// dist/extensions/agent-browser/lib/browser-transcript-validation.js
|
|
1780
|
+
function invalidEvent() {
|
|
1781
|
+
throw new Error("Invalid browser event; inspect or convert the retained session before browser work.");
|
|
1782
|
+
}
|
|
1783
|
+
function invalidPage() {
|
|
1784
|
+
throw new Error("Invalid browser page disposition; refs cannot be restored.");
|
|
1785
|
+
}
|
|
1786
|
+
function parseInvalidation(value) {
|
|
1787
|
+
if (value === void 0) {
|
|
1788
|
+
return void 0;
|
|
1789
|
+
}
|
|
1790
|
+
if (!isRecord(value) || value.reason !== "page-transition" && value.reason !== "no-active-page" || typeof value.summary !== "string") {
|
|
1791
|
+
return invalidPage();
|
|
1792
|
+
}
|
|
1793
|
+
return { ...value, reason: value.reason, summary: value.summary };
|
|
1794
|
+
}
|
|
1795
|
+
function parseRefs(value) {
|
|
1796
|
+
if (!isRecord(value)) {
|
|
1797
|
+
return invalidPage();
|
|
1798
|
+
}
|
|
1799
|
+
if (value.kind === "reuse" || value.kind === "replace") {
|
|
1800
|
+
if (typeof value.snapshotId !== "string" || value.snapshotId.length === 0) {
|
|
1801
|
+
return invalidPage();
|
|
1802
|
+
}
|
|
1803
|
+
return { ...value, kind: value.kind, snapshotId: value.snapshotId };
|
|
1804
|
+
}
|
|
1805
|
+
if (value.kind !== "unknown" && value.kind !== "invalidate") {
|
|
1806
|
+
return invalidPage();
|
|
1807
|
+
}
|
|
1808
|
+
const invalidation = parseInvalidation(value.invalidation);
|
|
1809
|
+
return { ...value, kind: value.kind, ...invalidation ? { invalidation } : {} };
|
|
1810
|
+
}
|
|
1811
|
+
function decodeBrowserTarget(value) {
|
|
1812
|
+
if (!isRecord(value) || typeof value.url !== "string") {
|
|
1813
|
+
return void 0;
|
|
1814
|
+
}
|
|
1815
|
+
if (value.title !== void 0 && typeof value.title !== "string" || value.targetId !== void 0 && typeof value.targetId !== "string") {
|
|
1816
|
+
return void 0;
|
|
1817
|
+
}
|
|
1818
|
+
const target = { ...value, url: value.url };
|
|
1819
|
+
return normalizeSessionTabTarget(target) === void 0 ? void 0 : target;
|
|
1820
|
+
}
|
|
1821
|
+
function parseBrowserTarget(value) {
|
|
1822
|
+
if (value === void 0) {
|
|
1823
|
+
return void 0;
|
|
1824
|
+
}
|
|
1825
|
+
return decodeBrowserTarget(value) ?? invalidPage();
|
|
1826
|
+
}
|
|
1827
|
+
function pageScalarsValid(value) {
|
|
1828
|
+
return (value.confirmActions === void 0 || value.confirmActions === null || typeof value.confirmActions === "string") && (value.unknown === void 0 || value.unknown === true) && (value.clear === void 0 || value.clear === true);
|
|
1829
|
+
}
|
|
1830
|
+
function pagePolicyValid(value) {
|
|
1831
|
+
return (value.reopenPending === void 0 || typeof value.reopenPending === "boolean") && (value.pinningReason === void 0 || value.pinningReason === "restore" || value.pinningReason === "drift");
|
|
1832
|
+
}
|
|
1833
|
+
function parsePage(value) {
|
|
1834
|
+
if (!isRecord(value) || typeof value.key !== "string" || !pageScalarsValid(value) || !pagePolicyValid(value)) {
|
|
1835
|
+
return invalidPage();
|
|
1836
|
+
}
|
|
1837
|
+
const target = parseBrowserTarget(value.target);
|
|
1838
|
+
return { ...value, key: value.key, refs: parseRefs(value.refs), ...target ? { target } : {} };
|
|
1839
|
+
}
|
|
1840
|
+
function parsePages(value) {
|
|
1841
|
+
if (value === void 0) {
|
|
1842
|
+
return void 0;
|
|
1843
|
+
}
|
|
1844
|
+
if (!Array.isArray(value)) {
|
|
1845
|
+
return invalidPage();
|
|
1846
|
+
}
|
|
1847
|
+
const pages = value;
|
|
1848
|
+
return pages.map(parsePage);
|
|
1849
|
+
}
|
|
1850
|
+
function parseArtifacts(value) {
|
|
1851
|
+
if (value === void 0) {
|
|
1852
|
+
return void 0;
|
|
1853
|
+
}
|
|
1854
|
+
if (!isRecord(value) || !isBrowserStringArray(value.removals)) {
|
|
1855
|
+
throw new Error("Invalid browser artifact changes; inspect the retained journal.");
|
|
1856
|
+
}
|
|
1857
|
+
const manifest = {
|
|
1858
|
+
version: 1,
|
|
1859
|
+
entries: value.upserts,
|
|
1860
|
+
maxEntries: value.maxEntries,
|
|
1861
|
+
updatedAtMs: value.updatedAtMs,
|
|
1862
|
+
liveCount: 0,
|
|
1863
|
+
evictedCount: 0
|
|
1864
|
+
};
|
|
1865
|
+
if (!isSessionArtifactManifest(manifest)) {
|
|
1866
|
+
throw new Error("Invalid browser artifact changes; inspect the retained journal.");
|
|
1867
|
+
}
|
|
1868
|
+
return {
|
|
1869
|
+
...value,
|
|
1870
|
+
upserts: manifest.entries,
|
|
1871
|
+
removals: value.removals,
|
|
1872
|
+
maxEntries: manifest.maxEntries,
|
|
1873
|
+
updatedAtMs: manifest.updatedAtMs
|
|
1874
|
+
};
|
|
1875
|
+
}
|
|
1876
|
+
function eventIdentity(value) {
|
|
1877
|
+
if (typeof value.operationId !== "string" || typeof value.toolCallId !== "string" || typeof value.commandIndex !== "number" || !Number.isSafeInteger(value.commandIndex) || value.commandIndex < 0 || typeof value.isError !== "boolean") {
|
|
1878
|
+
return invalidEvent();
|
|
1879
|
+
}
|
|
1880
|
+
return {
|
|
1881
|
+
operationId: value.operationId,
|
|
1882
|
+
toolCallId: value.toolCallId,
|
|
1883
|
+
commandIndex: value.commandIndex,
|
|
1884
|
+
isError: value.isError
|
|
1885
|
+
};
|
|
1886
|
+
}
|
|
1887
|
+
function parseBrowserEvent(value) {
|
|
1888
|
+
const phase = value.phase;
|
|
1889
|
+
if (phase !== "begin" && phase !== "finish" && phase !== "state") {
|
|
1890
|
+
return invalidEvent();
|
|
1891
|
+
}
|
|
1892
|
+
if (!isRecord(value.state)) {
|
|
1893
|
+
return invalidEvent();
|
|
1894
|
+
}
|
|
1895
|
+
const identity = eventIdentity(value);
|
|
1896
|
+
const pages = parsePages(value.pages);
|
|
1897
|
+
const artifacts = parseArtifacts(value.artifacts);
|
|
1898
|
+
return {
|
|
1899
|
+
...value,
|
|
1900
|
+
...identity,
|
|
1901
|
+
version: 1,
|
|
1902
|
+
phase,
|
|
1903
|
+
state: value.state,
|
|
1904
|
+
...pages ? { pages } : {},
|
|
1905
|
+
...artifacts ? { artifacts } : {}
|
|
1906
|
+
};
|
|
1907
|
+
}
|
|
1908
|
+
|
|
1909
|
+
// dist/extensions/agent-browser/lib/browser-transcript.js
|
|
1910
|
+
var BROWSER_EVENT_VERSION = 1;
|
|
1911
|
+
function browserStateEffects(details) {
|
|
1912
|
+
const state = Object.fromEntries(BROWSER_STATE_FIELDS.filter((key) => details[key] !== void 0).map((key) => [
|
|
1913
|
+
key,
|
|
1914
|
+
details[key]
|
|
1915
|
+
]));
|
|
1916
|
+
if (Array.isArray(details.batchSteps)) {
|
|
1917
|
+
state.batchSteps = details.batchSteps.filter(isRecord).map((step) => ({
|
|
1918
|
+
command: step.command,
|
|
1919
|
+
success: step.success,
|
|
1920
|
+
lifecycle: extractAgentBrowserLifecycle(step)
|
|
1921
|
+
}));
|
|
1922
|
+
}
|
|
1923
|
+
if (isRecord(details.electron) && (details.electron.launch !== void 0 || details.electron.cleanup !== void 0)) {
|
|
1924
|
+
state.electron = { launch: details.electron.launch, cleanup: details.electron.cleanup };
|
|
1925
|
+
}
|
|
1926
|
+
return state;
|
|
1927
|
+
}
|
|
1928
|
+
function getBrowserRecord(entry) {
|
|
1929
|
+
if (!isRecord(entry) || !isRecord(entry.data)) {
|
|
1930
|
+
return void 0;
|
|
1931
|
+
}
|
|
1932
|
+
if (entry.type !== "message" && !(entry.type === "custom" && entry.customType === BROWSER_TRANSITION_ENTRY)) {
|
|
1933
|
+
return void 0;
|
|
1934
|
+
}
|
|
1935
|
+
const event = entry.data.event;
|
|
1936
|
+
if (!isRecord(event) || event.version !== BROWSER_EVENT_VERSION) {
|
|
1937
|
+
return void 0;
|
|
1938
|
+
}
|
|
1939
|
+
return { ...entry.data, event: parseBrowserEvent(event) };
|
|
1940
|
+
}
|
|
1941
|
+
function snapshotDefinition(snapshot) {
|
|
1942
|
+
if (snapshot.snapshotId === void 0 || snapshot.snapshotId.length === 0) {
|
|
1943
|
+
throw new Error("A snapshot capture must have an identity before publication.");
|
|
1944
|
+
}
|
|
1945
|
+
return {
|
|
1946
|
+
id: snapshot.snapshotId,
|
|
1947
|
+
refs: Object.fromEntries(snapshot.refIds.map((id) => [id, snapshot.refs?.[id] ?? {}])),
|
|
1948
|
+
target: snapshot.target,
|
|
1949
|
+
generation: snapshot.generation
|
|
1950
|
+
};
|
|
1951
|
+
}
|
|
1952
|
+
function indexedArtifacts(manifest) {
|
|
1953
|
+
return new Map((manifest?.entries ?? []).map((row) => [getSessionArtifactManifestEntryKey(row), row]));
|
|
1954
|
+
}
|
|
1955
|
+
function redactedArtifact(row) {
|
|
1956
|
+
const manifest = {
|
|
1957
|
+
version: 1,
|
|
1958
|
+
entries: [redactSensitiveValue(row)],
|
|
1959
|
+
maxEntries: 1,
|
|
1960
|
+
updatedAtMs: row.createdAtMs,
|
|
1961
|
+
liveCount: 0,
|
|
1962
|
+
evictedCount: 0
|
|
1963
|
+
};
|
|
1964
|
+
if (!isSessionArtifactManifest(manifest)) {
|
|
1965
|
+
throw new Error("Redacted browser artifact has no valid manifest receipt.");
|
|
1966
|
+
}
|
|
1967
|
+
return manifest.entries[0];
|
|
1968
|
+
}
|
|
1969
|
+
function artifactChanges(previous, next) {
|
|
1970
|
+
if (previous === next) {
|
|
1971
|
+
return void 0;
|
|
1972
|
+
}
|
|
1973
|
+
const before = indexedArtifacts(previous);
|
|
1974
|
+
const after = indexedArtifacts(next);
|
|
1975
|
+
const upserts = [...after].filter(([key, row]) => JSON.stringify(before.get(key)) !== JSON.stringify(row)).map(([, row]) => redactedArtifact(row));
|
|
1976
|
+
const removals = [...before.keys()].filter((key) => !after.has(key));
|
|
1977
|
+
return upserts.length > 0 || removals.length > 0 ? {
|
|
1978
|
+
upserts,
|
|
1979
|
+
removals,
|
|
1980
|
+
maxEntries: (next ?? previous)?.maxEntries ?? 100,
|
|
1981
|
+
updatedAtMs: next?.updatedAtMs ?? Date.now()
|
|
1982
|
+
} : void 0;
|
|
1983
|
+
}
|
|
1984
|
+
function applyArtifactChanges(previous, changes) {
|
|
1985
|
+
if (!changes) {
|
|
1986
|
+
return previous;
|
|
1987
|
+
}
|
|
1988
|
+
const rows = new Map((previous?.entries ?? []).map((row) => [getSessionArtifactManifestEntryKey(row), row]));
|
|
1989
|
+
for (const key of changes.removals) {
|
|
1990
|
+
rows.delete(key);
|
|
1991
|
+
}
|
|
1992
|
+
for (const row of changes.upserts) {
|
|
1993
|
+
rows.set(getSessionArtifactManifestEntryKey(row), row);
|
|
1994
|
+
}
|
|
1995
|
+
const entries = [...rows.values()].sort((a, b) => {
|
|
1996
|
+
const age = (b.evictedAtMs ?? b.createdAtMs) - (a.evictedAtMs ?? a.createdAtMs);
|
|
1997
|
+
if (age !== 0) {
|
|
1998
|
+
return age;
|
|
1999
|
+
}
|
|
2000
|
+
const pending = Number(isPendingRecordingArtifact(b)) - Number(isPendingRecordingArtifact(a));
|
|
2001
|
+
return pending !== 0 ? pending : a.path.localeCompare(b.path);
|
|
2002
|
+
}).slice(0, changes.maxEntries);
|
|
2003
|
+
const manifest = {
|
|
2004
|
+
version: 1,
|
|
2005
|
+
entries,
|
|
2006
|
+
maxEntries: changes.maxEntries,
|
|
2007
|
+
updatedAtMs: changes.updatedAtMs,
|
|
2008
|
+
liveCount: entries.filter((row) => row.retentionState === "live").length,
|
|
2009
|
+
evictedCount: entries.filter((row) => row.retentionState === "evicted").length
|
|
2010
|
+
};
|
|
2011
|
+
if (!isSessionArtifactManifest(manifest)) {
|
|
2012
|
+
throw new Error("Invalid browser artifact changes; inspect the retained journal.");
|
|
2013
|
+
}
|
|
2014
|
+
return entries.length > 0 ? manifest : void 0;
|
|
2015
|
+
}
|
|
2016
|
+
|
|
2017
|
+
// dist/extensions/agent-browser/lib/browser-legacy-pages.js
|
|
2018
|
+
import { createHash } from "node:crypto";
|
|
2019
|
+
function legacyTarget(value) {
|
|
2020
|
+
return normalizeSessionTabTarget({
|
|
2021
|
+
url: typeof value.url === "string" ? value.url : void 0,
|
|
2022
|
+
title: typeof value.title === "string" ? value.title : void 0,
|
|
2023
|
+
targetId: typeof value.targetId === "string" ? value.targetId : void 0
|
|
2024
|
+
});
|
|
2025
|
+
}
|
|
2026
|
+
function legacySnapshot(value, id) {
|
|
2027
|
+
if (!isRecord(value) || !Array.isArray(value.refIds)) {
|
|
2028
|
+
return void 0;
|
|
2029
|
+
}
|
|
2030
|
+
const refIds = browserStringArray(value.refIds).filter((ref) => /^e\d+$/.test(ref));
|
|
2031
|
+
const sourceRefs = isRecord(value.refs) ? value.refs : {};
|
|
2032
|
+
return snapshotDefinition({
|
|
2033
|
+
snapshotId: typeof value.snapshotId === "string" ? value.snapshotId : id,
|
|
2034
|
+
refIds,
|
|
2035
|
+
generation: typeof value.generation === "string" ? value.generation : void 0,
|
|
2036
|
+
refs: Object.fromEntries(refIds.flatMap((refId) => {
|
|
2037
|
+
const ref = sourceRefs[refId];
|
|
2038
|
+
if (!isRecord(ref) || typeof ref.name !== "string" || typeof ref.role !== "string") {
|
|
2039
|
+
return [];
|
|
2040
|
+
}
|
|
2041
|
+
return [
|
|
2042
|
+
[
|
|
2043
|
+
refId,
|
|
2044
|
+
{
|
|
2045
|
+
name: ref.name,
|
|
2046
|
+
role: ref.role,
|
|
2047
|
+
...typeof ref.isEditable === "boolean" ? { isEditable: ref.isEditable } : {},
|
|
2048
|
+
...typeof ref.isContentEditable === "boolean" ? { isContentEditable: ref.isContentEditable } : {}
|
|
2049
|
+
}
|
|
2050
|
+
]
|
|
2051
|
+
];
|
|
2052
|
+
})),
|
|
2053
|
+
target: isRecord(value.target) ? legacyTarget(value.target) : void 0
|
|
2054
|
+
});
|
|
2055
|
+
}
|
|
2056
|
+
function snapshotDigest(definition) {
|
|
2057
|
+
return createHash("sha256").update(JSON.stringify({
|
|
2058
|
+
refs: definition.refs,
|
|
2059
|
+
target: definition.target,
|
|
2060
|
+
generation: definition.generation
|
|
2061
|
+
})).digest("hex");
|
|
2062
|
+
}
|
|
2063
|
+
function canonicalPage(prior, canonical, page) {
|
|
2064
|
+
const definition = isRecord(canonical.snapshot) ? canonical.snapshot : void 0;
|
|
2065
|
+
const digest = definition !== void 0 && Boolean(definition.refs) ? snapshotDigest(definition) : prior.snapshot?.digest ?? "";
|
|
2066
|
+
let snapshot;
|
|
2067
|
+
if (page.refs.kind === "replace" || page.refs.kind === "reuse") {
|
|
2068
|
+
snapshot = { id: page.refs.snapshotId, digest, usable: true, candidate: false };
|
|
2069
|
+
} else if (prior.snapshot) {
|
|
2070
|
+
snapshot = { ...prior.snapshot, usable: false, candidate: canonical.event.phase === "begin" };
|
|
2071
|
+
}
|
|
2072
|
+
return {
|
|
2073
|
+
target: page.target,
|
|
2074
|
+
unknown: page.unknown,
|
|
2075
|
+
reopenPending: page.reopenPending,
|
|
2076
|
+
snapshot,
|
|
2077
|
+
pending: canonical.event.phase === "begin" ? {
|
|
2078
|
+
operationId: canonical.event.operationId,
|
|
2079
|
+
toolCallId: canonical.event.toolCallId,
|
|
2080
|
+
index: canonical.event.commandIndex
|
|
2081
|
+
} : void 0
|
|
2082
|
+
};
|
|
2083
|
+
}
|
|
2084
|
+
function parseInvalidation2(value, fallbackSummary) {
|
|
2085
|
+
if (!isRecord(value)) {
|
|
2086
|
+
return void 0;
|
|
2087
|
+
}
|
|
2088
|
+
if (value.reason !== "no-active-page" && value.reason !== "page-transition") {
|
|
2089
|
+
throw new Error("Invalid legacy browser ref invalidation.");
|
|
2090
|
+
}
|
|
2091
|
+
if (typeof value.summary === "string") {
|
|
2092
|
+
return { reason: value.reason, summary: value.summary };
|
|
2093
|
+
}
|
|
2094
|
+
if (fallbackSummary) {
|
|
2095
|
+
return {
|
|
2096
|
+
reason: value.reason,
|
|
2097
|
+
summary: "The prior refs were invalidated; take a fresh snapshot."
|
|
2098
|
+
};
|
|
2099
|
+
}
|
|
2100
|
+
throw new Error("Invalid legacy browser ref invalidation summary.");
|
|
2101
|
+
}
|
|
2102
|
+
function observedInvalidation(ctx) {
|
|
2103
|
+
const value = ctx.details.refSnapshotInvalidation;
|
|
2104
|
+
if (isRecord(value) && (value.reason === "no-active-page" || value.reason === "page-transition")) {
|
|
2105
|
+
return parseInvalidation2(value, true);
|
|
2106
|
+
}
|
|
2107
|
+
let error;
|
|
2108
|
+
if (typeof ctx.details.error === "string") {
|
|
2109
|
+
error = ctx.details.error;
|
|
2110
|
+
} else if (typeof ctx.details.summary === "string") {
|
|
2111
|
+
error = ctx.details.summary;
|
|
2112
|
+
}
|
|
2113
|
+
return isNoActivePageSnapshotFailure(ctx.command, error) ? buildNoActivePageRefSnapshotInvalidation() : void 0;
|
|
2114
|
+
}
|
|
2115
|
+
function snapshotReusable(page, details, digest) {
|
|
2116
|
+
return page.snapshot?.digest === digest && (page.snapshot.usable || page.snapshot.candidate) && (!isRecord(details.refSnapshot) || typeof details.refSnapshot.snapshotId !== "string" || details.refSnapshot.snapshotId === page.snapshot.id);
|
|
2117
|
+
}
|
|
2118
|
+
var LegacyPageConversion = class {
|
|
2119
|
+
ctx;
|
|
2120
|
+
page;
|
|
2121
|
+
definition;
|
|
2122
|
+
constructor(ctx, prior) {
|
|
2123
|
+
this.ctx = ctx;
|
|
2124
|
+
this.page = { ...prior };
|
|
2125
|
+
}
|
|
2126
|
+
knownTarget() {
|
|
2127
|
+
const { details, command, subcommand } = this.ctx;
|
|
2128
|
+
if (!isRecord(details.compiledNetworkSourceLookup) && !isReadOnlyDiagnosticSessionTargetCommand(command, subcommand) && isRecord(details.sessionTabTarget)) {
|
|
2129
|
+
this.page.target = legacyTarget(details.sessionTabTarget) ?? this.page.target;
|
|
2130
|
+
} else if (command === "batch" && !isRecord(details.compiledNetworkSourceLookup)) {
|
|
2131
|
+
this.page.target = extractSessionTabTargetFromBatchResults(details.data) ?? this.page.target;
|
|
2132
|
+
}
|
|
2133
|
+
if (this.page.target) {
|
|
2134
|
+
this.page.unknown = void 0;
|
|
2135
|
+
}
|
|
2136
|
+
if (typeof details.sessionTabReopenPending === "boolean") {
|
|
2137
|
+
this.page.reopenPending = details.sessionTabReopenPending;
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
knownRefs() {
|
|
2141
|
+
const invalidation = observedInvalidation(this.ctx);
|
|
2142
|
+
const candidate = invalidation ? void 0 : legacySnapshot(this.ctx.details.refSnapshot, `snapshot-${this.ctx.nativeId}`);
|
|
2143
|
+
if (candidate) {
|
|
2144
|
+
const digest = snapshotDigest(candidate);
|
|
2145
|
+
let refs;
|
|
2146
|
+
if (snapshotReusable(this.page, this.ctx.details, digest) && this.page.snapshot) {
|
|
2147
|
+
refs = { kind: "reuse", snapshotId: this.page.snapshot.id };
|
|
2148
|
+
} else {
|
|
2149
|
+
this.definition = candidate;
|
|
2150
|
+
refs = { kind: "replace", snapshotId: candidate.id };
|
|
2151
|
+
}
|
|
2152
|
+
this.page.snapshot = { id: refs.snapshotId, digest, usable: true, candidate: false };
|
|
2153
|
+
return refs;
|
|
2154
|
+
}
|
|
2155
|
+
if (invalidation) {
|
|
2156
|
+
this.disableSnapshot(false);
|
|
2157
|
+
return { kind: "invalidate", invalidation };
|
|
2158
|
+
}
|
|
2159
|
+
return this.page.snapshot?.usable === true ? { kind: "reuse", snapshotId: this.page.snapshot.id } : { kind: "invalidate" };
|
|
2160
|
+
}
|
|
2161
|
+
disableSnapshot(candidate) {
|
|
2162
|
+
if (this.page.snapshot) {
|
|
2163
|
+
this.page.snapshot = { ...this.page.snapshot, usable: false, candidate };
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
change(key) {
|
|
2167
|
+
return {
|
|
2168
|
+
...this.pageChange(key),
|
|
2169
|
+
...typeof this.ctx.details.sessionConfirmActions === "string" || this.ctx.details.sessionConfirmActions === null ? { confirmActions: this.ctx.details.sessionConfirmActions } : {}
|
|
2170
|
+
};
|
|
2171
|
+
}
|
|
2172
|
+
pageChange(key) {
|
|
2173
|
+
const ctx = this.ctx;
|
|
2174
|
+
if (ctx.begin) {
|
|
2175
|
+
this.page.target = void 0;
|
|
2176
|
+
this.page.unknown = true;
|
|
2177
|
+
this.page.snapshot = ctx.prior.snapshot ? { ...ctx.prior.snapshot, usable: false, candidate: true } : void 0;
|
|
2178
|
+
this.page.pending = {
|
|
2179
|
+
toolCallId: ctx.toolCallId,
|
|
2180
|
+
operationId: ctx.operationId,
|
|
2181
|
+
index: ctx.commandIndex
|
|
2182
|
+
};
|
|
2183
|
+
return { key, refs: { kind: "unknown" }, unknown: true };
|
|
2184
|
+
}
|
|
2185
|
+
if (ctx.details.sessionTabTargetUnknown === true) {
|
|
2186
|
+
this.page.target = void 0;
|
|
2187
|
+
this.page.unknown = true;
|
|
2188
|
+
this.page.pending = void 0;
|
|
2189
|
+
this.disableSnapshot(false);
|
|
2190
|
+
return {
|
|
2191
|
+
key,
|
|
2192
|
+
refs: {
|
|
2193
|
+
kind: "unknown",
|
|
2194
|
+
invalidation: parseInvalidation2(ctx.details.refSnapshotInvalidation, false)
|
|
2195
|
+
},
|
|
2196
|
+
unknown: true
|
|
2197
|
+
};
|
|
2198
|
+
}
|
|
2199
|
+
this.knownTarget();
|
|
2200
|
+
const refs = this.knownRefs();
|
|
2201
|
+
this.page.pending = void 0;
|
|
2202
|
+
return {
|
|
2203
|
+
key,
|
|
2204
|
+
target: this.page.target,
|
|
2205
|
+
unknown: this.page.unknown,
|
|
2206
|
+
reopenPending: this.page.reopenPending,
|
|
2207
|
+
refs
|
|
2208
|
+
};
|
|
2209
|
+
}
|
|
2210
|
+
};
|
|
2211
|
+
|
|
2212
|
+
// dist/extensions/agent-browser/lib/browser-conversion-branches.js
|
|
2213
|
+
var BrowserConversionBranches = class {
|
|
2214
|
+
states = /* @__PURE__ */ new Map();
|
|
2215
|
+
children = /* @__PURE__ */ new Map();
|
|
2216
|
+
constructor(parentIds) {
|
|
2217
|
+
for (const id of parentIds) {
|
|
2218
|
+
if (typeof id === "string") {
|
|
2219
|
+
this.children.set(id, (this.children.get(id) ?? 0) + 1);
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
get(id) {
|
|
2224
|
+
return this.states.get(id);
|
|
2225
|
+
}
|
|
2226
|
+
advance(id, parentId, projection) {
|
|
2227
|
+
if (typeof parentId === "string") {
|
|
2228
|
+
const remaining = (this.children.get(parentId) ?? 0) - 1;
|
|
2229
|
+
if (remaining > 0) {
|
|
2230
|
+
this.children.set(parentId, remaining);
|
|
2231
|
+
} else {
|
|
2232
|
+
this.children.delete(parentId);
|
|
2233
|
+
this.states.delete(parentId);
|
|
2234
|
+
}
|
|
2235
|
+
}
|
|
2236
|
+
if (this.children.has(id)) {
|
|
2237
|
+
this.states.set(id, projection);
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
};
|
|
2241
|
+
|
|
2242
|
+
// dist/extensions/agent-browser/lib/browser-legacy-projection.js
|
|
2243
|
+
var emptyProjection = () => ({ pages: /* @__PURE__ */ new Map(), nextIndex: 0 });
|
|
2244
|
+
function legacyMessage(entry) {
|
|
2245
|
+
if (entry.type === "custom" && entry.customType === BROWSER_TRANSITION_ENTRY && isRecord(entry.data) && isRecord(entry.data.details)) {
|
|
2246
|
+
return entry.data;
|
|
2247
|
+
}
|
|
2248
|
+
const message = entry.type === "message" && isRecord(entry.message) ? entry.message : void 0;
|
|
2249
|
+
return isLegacyToolMessage(message) ? message : void 0;
|
|
2250
|
+
}
|
|
2251
|
+
function isLegacyToolMessage(message) {
|
|
2252
|
+
return message !== void 0 && typeof message.toolName === "string" && BROWSER_RESULT_TOOLS.has(message.toolName) && isRecord(message.details) && message.details.browserEventVersion !== 1;
|
|
2253
|
+
}
|
|
2254
|
+
function applyCanonical(current, parent, canonical) {
|
|
2255
|
+
current.manifest = applyArtifactChanges(parent.manifest, canonical.event.artifacts);
|
|
2256
|
+
for (const page of canonical.event.pages ?? []) {
|
|
2257
|
+
if (page.clear === true) {
|
|
2258
|
+
current.pages.delete(page.key);
|
|
2259
|
+
continue;
|
|
2260
|
+
}
|
|
2261
|
+
current.pages.set(page.key, canonicalPage(current.pages.get(page.key) ?? {}, canonical, page));
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
function scriptRecord(entry, nativeId, ownerSessionId) {
|
|
2265
|
+
if (entry.type !== "custom" || entry.customType !== "agent-browser-script-session" || !isRecord(entry.data)) {
|
|
2266
|
+
return void 0;
|
|
2267
|
+
}
|
|
2268
|
+
return {
|
|
2269
|
+
event: {
|
|
2270
|
+
version: 1,
|
|
2271
|
+
phase: "state",
|
|
2272
|
+
operationId: `legacy-${nativeId}`,
|
|
2273
|
+
toolCallId: `legacy-${nativeId}`,
|
|
2274
|
+
commandIndex: 0,
|
|
2275
|
+
isError: entry.data.cleanup !== "closed",
|
|
2276
|
+
state: {
|
|
2277
|
+
scriptLease: { ...entry.data, ownerSessionId: entry.data.ownerSessionId ?? ownerSessionId }
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
};
|
|
2281
|
+
}
|
|
2282
|
+
function isLegacyBegin(entry, details) {
|
|
2283
|
+
return entry.type === "custom" && details.sessionTabTargetUnknown === true && details.command === void 0 && details.exitCode === void 0 && details.agentBrowserStarted === void 0;
|
|
2284
|
+
}
|
|
2285
|
+
function legacyIdentity(details) {
|
|
2286
|
+
const sessionName = typeof details.sessionName === "string" ? details.sessionName : void 0;
|
|
2287
|
+
const namespace = typeof details.namespace === "string" ? details.namespace : void 0;
|
|
2288
|
+
const key = sessionName !== void 0 && sessionName.length > 0 ? getAgentBrowserSessionIdentityKey(sessionName, namespace) : void 0;
|
|
2289
|
+
const tokens = extractUpstreamCommandTokens(browserStringArray(details.args));
|
|
2290
|
+
return {
|
|
2291
|
+
key,
|
|
2292
|
+
namespace,
|
|
2293
|
+
tokens,
|
|
2294
|
+
command: typeof details.command === "string" ? details.command : tokens[0],
|
|
2295
|
+
subcommand: typeof details.subcommand === "string" ? details.subcommand : tokens[1]
|
|
2296
|
+
};
|
|
2297
|
+
}
|
|
2298
|
+
function legacyPrior(key, current) {
|
|
2299
|
+
return key === void 0 ? {} : current.pages.get(key) ?? {};
|
|
2300
|
+
}
|
|
2301
|
+
function operationIdentity(options, current) {
|
|
2302
|
+
const prior = legacyPrior(options.key, current);
|
|
2303
|
+
const begin = isLegacyBegin(options.entry, options.details);
|
|
2304
|
+
const pending = prior.pending?.toolCallId === options.toolCallId ? prior.pending : void 0;
|
|
2305
|
+
let phase = "state";
|
|
2306
|
+
if (begin) {
|
|
2307
|
+
phase = "begin";
|
|
2308
|
+
} else if (pending) {
|
|
2309
|
+
phase = "finish";
|
|
2310
|
+
}
|
|
2311
|
+
let commandIndex = pending?.index ?? 0;
|
|
2312
|
+
if (begin) {
|
|
2313
|
+
commandIndex = current.nextIndex;
|
|
2314
|
+
current.nextIndex++;
|
|
2315
|
+
}
|
|
2316
|
+
return {
|
|
2317
|
+
prior,
|
|
2318
|
+
begin,
|
|
2319
|
+
phase,
|
|
2320
|
+
commandIndex,
|
|
2321
|
+
operationId: pending?.operationId ?? `legacy-${options.nativeId}`
|
|
2322
|
+
};
|
|
2323
|
+
}
|
|
2324
|
+
function normalizeLegacyBatchStep(step) {
|
|
2325
|
+
return step.success === true && isSuccessfulNativeConfirmedClose(browserStringArray(step.command), step.data) ? { ...step, command: ["close"] } : step;
|
|
2326
|
+
}
|
|
2327
|
+
function normalizeLegacyDetails(details, isError) {
|
|
2328
|
+
const closed = !isError && isSuccessfulNativeConfirmedClose(extractUpstreamCommandTokens(browserStringArray(details.args)), details.data);
|
|
2329
|
+
const batchSteps = Array.isArray(details.batchSteps) ? details.batchSteps.filter(isRecord).map(normalizeLegacyBatchStep) : void 0;
|
|
2330
|
+
return {
|
|
2331
|
+
...details,
|
|
2332
|
+
...closed ? { command: "close", subcommand: void 0 } : {},
|
|
2333
|
+
...batchSteps !== void 0 ? { batchSteps } : {}
|
|
2334
|
+
};
|
|
2335
|
+
}
|
|
2336
|
+
function context(entry, message, details, current) {
|
|
2337
|
+
const nativeId = typeof entry.id === "string" ? entry.id : randomUUID();
|
|
2338
|
+
const toolCallId = typeof message.toolCallId === "string" ? message.toolCallId : `legacy-${nativeId}`;
|
|
2339
|
+
const replayDetails = normalizeLegacyDetails(details, message.isError === true);
|
|
2340
|
+
const identity = legacyIdentity(replayDetails);
|
|
2341
|
+
const operation = operationIdentity({ entry, details: replayDetails, key: identity.key, toolCallId, nativeId }, current);
|
|
2342
|
+
return {
|
|
2343
|
+
...identity,
|
|
2344
|
+
...operation,
|
|
2345
|
+
nativeId,
|
|
2346
|
+
details: replayDetails,
|
|
2347
|
+
isError: message.isError === true,
|
|
2348
|
+
toolCallId
|
|
2349
|
+
};
|
|
2350
|
+
}
|
|
2351
|
+
function closingLifecycle(ctx) {
|
|
2352
|
+
const close = getSuccessfulBatchCloseLifecycle(ctx.details.batchSteps);
|
|
2353
|
+
const closeAll = ctx.details.closeAllApplied === true || !ctx.isError && isCloseAllCommand(ctx.tokens) || batchHasSuccessfulCloseAll(ctx.details.batchSteps);
|
|
2354
|
+
return {
|
|
2355
|
+
closeAll,
|
|
2356
|
+
lifecycleReset: !ctx.isError && isCloseCommand(ctx.command) || close !== void 0,
|
|
2357
|
+
endsClosed: close?.endsClosed === true
|
|
2358
|
+
};
|
|
2359
|
+
}
|
|
2360
|
+
function closePages(current, ctx) {
|
|
2361
|
+
const closing = closingLifecycle(ctx);
|
|
2362
|
+
const pages = [];
|
|
2363
|
+
if (closing.closeAll) {
|
|
2364
|
+
for (const key of current.pages.keys()) {
|
|
2365
|
+
if (isAgentBrowserSessionIdentityKeyInNamespace(key, ctx.namespace)) {
|
|
2366
|
+
current.pages.delete(key);
|
|
2367
|
+
pages.push({ key, clear: true, refs: { kind: "invalidate" } });
|
|
2368
|
+
}
|
|
2369
|
+
}
|
|
2370
|
+
} else if (ctx.key !== void 0 && closing.lifecycleReset) {
|
|
2371
|
+
current.pages.delete(ctx.key);
|
|
2372
|
+
pages.push({ key: ctx.key, clear: true, refs: { kind: "invalidate" } });
|
|
2373
|
+
}
|
|
2374
|
+
return { ...closing, pages };
|
|
2375
|
+
}
|
|
2376
|
+
function hasPageEffects(ctx) {
|
|
2377
|
+
return ctx.begin || [
|
|
2378
|
+
"sessionTabTargetUnknown",
|
|
2379
|
+
"sessionTabTarget",
|
|
2380
|
+
"sessionTabReopenPending",
|
|
2381
|
+
"sessionConfirmActions",
|
|
2382
|
+
"refSnapshot",
|
|
2383
|
+
"refSnapshotInvalidation"
|
|
2384
|
+
].some((field) => ctx.details[field] !== void 0) || ctx.command === "batch" && Array.isArray(ctx.details.data);
|
|
2385
|
+
}
|
|
2386
|
+
function stampElectronState(state, ownerSessionId) {
|
|
2387
|
+
if (!isRecord(state.electron)) {
|
|
2388
|
+
return state;
|
|
2389
|
+
}
|
|
2390
|
+
const stamp = (value) => isRecord(value) ? { ...value, ownerSessionId: value.ownerSessionId ?? ownerSessionId } : value;
|
|
2391
|
+
const cleanup = isRecord(state.electron.cleanup) ? state.electron.cleanup : void 0;
|
|
2392
|
+
return {
|
|
2393
|
+
...state,
|
|
2394
|
+
electron: {
|
|
2395
|
+
...state.electron,
|
|
2396
|
+
launch: stamp(state.electron.launch),
|
|
2397
|
+
...cleanup ? {
|
|
2398
|
+
cleanup: {
|
|
2399
|
+
...cleanup,
|
|
2400
|
+
records: Array.isArray(cleanup.records) ? cleanup.records.map(stamp) : cleanup.records,
|
|
2401
|
+
results: Array.isArray(cleanup.results) ? cleanup.results.map((row) => isRecord(row) ? { ...row, record: stamp(row.record) } : row) : cleanup.results
|
|
2402
|
+
}
|
|
2403
|
+
} : {}
|
|
2404
|
+
}
|
|
2405
|
+
};
|
|
2406
|
+
}
|
|
2407
|
+
function updateManifest(current, parent, details) {
|
|
2408
|
+
if (isSessionArtifactManifest(details.artifactManifest) && (!parent.manifest || details.artifactManifest.updatedAtMs >= parent.manifest.updatedAtMs)) {
|
|
2409
|
+
current.manifest = details.artifactManifest;
|
|
2410
|
+
}
|
|
2411
|
+
const changes = artifactChanges(parent.manifest, current.manifest);
|
|
2412
|
+
if (!changes) {
|
|
2413
|
+
current.manifest = parent.manifest;
|
|
2414
|
+
}
|
|
2415
|
+
return changes;
|
|
2416
|
+
}
|
|
2417
|
+
function convertMessage(ctx, parent, current, ownerSessionId) {
|
|
2418
|
+
const closing = closePages(current, ctx);
|
|
2419
|
+
const pages = closing.pages;
|
|
2420
|
+
let definition;
|
|
2421
|
+
const suppressPage = (closing.closeAll || closing.lifecycleReset) && (isCloseCommand(ctx.command) || closing.endsClosed);
|
|
2422
|
+
if (ctx.key !== void 0 && hasPageEffects(ctx) && !suppressPage) {
|
|
2423
|
+
const conversion = new LegacyPageConversion(ctx, current.pages.get(ctx.key) ?? {});
|
|
2424
|
+
pages.push(conversion.change(ctx.key));
|
|
2425
|
+
current.pages.set(ctx.key, conversion.page);
|
|
2426
|
+
definition = conversion.definition;
|
|
2427
|
+
}
|
|
2428
|
+
const artifacts = updateManifest(current, parent, ctx.details);
|
|
2429
|
+
return {
|
|
2430
|
+
event: {
|
|
2431
|
+
version: 1,
|
|
2432
|
+
phase: ctx.phase,
|
|
2433
|
+
operationId: ctx.operationId,
|
|
2434
|
+
toolCallId: ctx.toolCallId,
|
|
2435
|
+
commandIndex: ctx.commandIndex,
|
|
2436
|
+
isError: ctx.isError,
|
|
2437
|
+
state: stampElectronState(browserStateEffects(ctx.details), ownerSessionId),
|
|
2438
|
+
pages,
|
|
2439
|
+
artifacts
|
|
2440
|
+
},
|
|
2441
|
+
...definition ? { snapshot: definition } : {}
|
|
2442
|
+
};
|
|
2443
|
+
}
|
|
2444
|
+
function hasCanonicalBrowserEvent(entry) {
|
|
2445
|
+
return isRecord(entry.data) && Object.hasOwn(entry.data, "event") && (entry.type === "message" || entry.customType === BROWSER_TRANSITION_ENTRY);
|
|
2446
|
+
}
|
|
2447
|
+
function convertLegacyBrowserEntry(entry, parent = emptyProjection(), ownerSessionId) {
|
|
2448
|
+
const current = {
|
|
2449
|
+
pages: new Map(parent.pages),
|
|
2450
|
+
manifest: parent.manifest,
|
|
2451
|
+
nextIndex: parent.nextIndex
|
|
2452
|
+
};
|
|
2453
|
+
const canonical = getBrowserRecord(entry);
|
|
2454
|
+
if (canonical) {
|
|
2455
|
+
applyCanonical(current, parent, canonical);
|
|
2456
|
+
return { projection: current };
|
|
2457
|
+
}
|
|
2458
|
+
if (hasCanonicalBrowserEvent(entry)) {
|
|
2459
|
+
throw new Error("Invalid browser event; legacy replay cannot bypass canonical validation.");
|
|
2460
|
+
}
|
|
2461
|
+
const script = scriptRecord(entry, typeof entry.id === "string" ? entry.id : randomUUID(), ownerSessionId);
|
|
2462
|
+
if (script) {
|
|
2463
|
+
return { record: script, projection: current };
|
|
2464
|
+
}
|
|
2465
|
+
const message = legacyMessage(entry);
|
|
2466
|
+
if (!message || !isRecord(message.details)) {
|
|
2467
|
+
return { projection: parent };
|
|
2468
|
+
}
|
|
2469
|
+
return {
|
|
2470
|
+
record: convertMessage(context(entry, message, message.details, current), parent, current, ownerSessionId),
|
|
2471
|
+
projection: current
|
|
2472
|
+
};
|
|
2473
|
+
}
|
|
2474
|
+
function archiveParent(value, branches, linear) {
|
|
2475
|
+
if (typeof value.parentId === "string") {
|
|
2476
|
+
return branches.get(value.parentId) ?? emptyProjection();
|
|
2477
|
+
}
|
|
2478
|
+
return Object.hasOwn(value, "parentId") ? emptyProjection() : linear;
|
|
2479
|
+
}
|
|
2480
|
+
function convertBrowserEntries(entries, ownerSessionId) {
|
|
2481
|
+
const branches = new BrowserConversionBranches(entries.map((value) => isRecord(value) ? value.parentId : void 0));
|
|
2482
|
+
let linear = emptyProjection();
|
|
2483
|
+
return entries.map((value, index) => {
|
|
2484
|
+
if (!isRecord(value)) {
|
|
2485
|
+
return value;
|
|
2486
|
+
}
|
|
2487
|
+
const entry = {
|
|
2488
|
+
...value,
|
|
2489
|
+
id: typeof value.id === "string" ? value.id : `archive-${index}`,
|
|
2490
|
+
parentId: value.parentId ?? null
|
|
2491
|
+
};
|
|
2492
|
+
const converted = convertLegacyBrowserEntry(entry, archiveParent(value, branches, linear), ownerSessionId);
|
|
2493
|
+
branches.advance(entry.id, value.parentId, converted.projection);
|
|
2494
|
+
linear = converted.projection;
|
|
2495
|
+
return converted.record ? {
|
|
2496
|
+
...entry,
|
|
2497
|
+
...entry.type === "custom" ? { customType: BROWSER_TRANSITION_ENTRY } : {},
|
|
2498
|
+
data: converted.record
|
|
2499
|
+
} : entry;
|
|
2500
|
+
});
|
|
2501
|
+
}
|
|
2502
|
+
|
|
2503
|
+
// dist/extensions/agent-browser/lib/browser-legacy-fields.js
|
|
2504
|
+
var DETAILS_FIELDS = [
|
|
2505
|
+
...BROWSER_STATE_FIELDS,
|
|
2506
|
+
"browserEventVersion",
|
|
2507
|
+
"electron",
|
|
2508
|
+
"compiledNetworkSourceLookup",
|
|
2509
|
+
"sessionTabTarget",
|
|
2510
|
+
"sessionTabTargetUnknown",
|
|
2511
|
+
"sessionTabReopenPending",
|
|
2512
|
+
"sessionConfirmActions",
|
|
2513
|
+
"refSnapshot",
|
|
2514
|
+
"refSnapshotInvalidation",
|
|
2515
|
+
"artifactManifest",
|
|
2516
|
+
"error",
|
|
2517
|
+
"summary"
|
|
2518
|
+
];
|
|
2519
|
+
var CONFIRMED_CLOSE_FIELDS = [
|
|
2520
|
+
["confirmed"],
|
|
2521
|
+
["action"],
|
|
2522
|
+
["result", "success"],
|
|
2523
|
+
["result", "data", "closed"]
|
|
2524
|
+
];
|
|
2525
|
+
var LEGACY_BROWSER_FIELDS = [
|
|
2526
|
+
["data", "event"],
|
|
2527
|
+
["data", "snapshot"],
|
|
2528
|
+
["data", "cleanup"],
|
|
2529
|
+
["data", "sessionName"],
|
|
2530
|
+
["data", "ownerSessionId"],
|
|
2531
|
+
["data", "closeCommandArgs"],
|
|
2532
|
+
["data", "launchAttempted"],
|
|
2533
|
+
["data", "toolCallId"],
|
|
2534
|
+
["data", "isError"],
|
|
2535
|
+
["message", "toolName"],
|
|
2536
|
+
["message", "toolCallId"],
|
|
2537
|
+
["message", "isError"],
|
|
2538
|
+
...["data", "message"].flatMap((root) => DETAILS_FIELDS.map((field) => [root, "details", field])),
|
|
2539
|
+
...["data", "message"].flatMap((root) => CONFIRMED_CLOSE_FIELDS.flatMap((field) => [
|
|
2540
|
+
[root, "details", "data", ...field],
|
|
2541
|
+
[root, "details", "batchSteps", "*", "data", ...field]
|
|
2542
|
+
])),
|
|
2543
|
+
...["data", "message"].flatMap((root) => ["command", "success", "lifecycle"].map((field) => [root, "details", "batchSteps", "*", field]).concat([
|
|
2544
|
+
["data", "lifecycle"],
|
|
2545
|
+
["result", "lifecycle"]
|
|
2546
|
+
].map((field) => [root, "details", "batchSteps", "*"].concat(field)))),
|
|
2547
|
+
...["data", "message"].flatMap((root) => ["command", "success", "error"].map((field) => [root, "details", "data", "*", field]).concat(["url", "title", "origin", "targetId"].map((field) => [
|
|
2548
|
+
root,
|
|
2549
|
+
"details",
|
|
2550
|
+
"data",
|
|
2551
|
+
"*",
|
|
2552
|
+
"result",
|
|
2553
|
+
field
|
|
2554
|
+
])))
|
|
2555
|
+
];
|
|
2556
|
+
|
|
2557
|
+
// dist/extensions/agent-browser/lib/browser-session-conversion-stream.js
|
|
2558
|
+
async function sourceChecksum(file, size) {
|
|
2559
|
+
const hash = createHash2("sha256");
|
|
2560
|
+
for await (const chunk of readRange(file, { offset: 0, length: size })) {
|
|
2561
|
+
hash.update(chunk);
|
|
2562
|
+
}
|
|
2563
|
+
return hash.digest("hex");
|
|
2564
|
+
}
|
|
2565
|
+
async function writeBytes(file, chunks) {
|
|
2566
|
+
for await (const chunk of chunks) {
|
|
2567
|
+
const buffer = typeof chunk === "string" ? Buffer.from(chunk) : chunk;
|
|
2568
|
+
let offset = 0;
|
|
2569
|
+
while (offset < buffer.length) {
|
|
2570
|
+
const { bytesWritten } = await file.write(buffer, offset, buffer.length - offset);
|
|
2571
|
+
if (bytesWritten === 0) {
|
|
2572
|
+
throw new Error("Could not write converted journal.");
|
|
2573
|
+
}
|
|
2574
|
+
offset += bytesWritten;
|
|
2575
|
+
}
|
|
2576
|
+
}
|
|
2577
|
+
}
|
|
2578
|
+
async function* decodeRange(file, range) {
|
|
2579
|
+
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
2580
|
+
for await (const bytes of readRange(file, range)) {
|
|
2581
|
+
yield decoder.decode(bytes, { stream: true });
|
|
2582
|
+
}
|
|
2583
|
+
const tail = decoder.decode();
|
|
2584
|
+
if (tail.length > 0) {
|
|
2585
|
+
yield tail;
|
|
2586
|
+
}
|
|
2587
|
+
}
|
|
2588
|
+
async function rewriteMessage(file, range, destination, record) {
|
|
2589
|
+
const tokenizer = tokenizeJson.asStream({ packValues: false, packKeys: true, streamKeys: false });
|
|
2590
|
+
const filter = ignoreJson.asStream({
|
|
2591
|
+
filter: /^(?:data|message\.details\.(?:refSnapshot|artifactManifest|browserEventVersion))$/
|
|
2592
|
+
});
|
|
2593
|
+
async function* inject(tokens) {
|
|
2594
|
+
let depth = 0;
|
|
2595
|
+
for await (const token of tokens) {
|
|
2596
|
+
if (token.name === "startObject" || token.name === "startArray") {
|
|
2597
|
+
depth++;
|
|
2598
|
+
}
|
|
2599
|
+
if (token.name === "endObject" || token.name === "endArray") {
|
|
2600
|
+
depth--;
|
|
2601
|
+
if (depth === 0) {
|
|
2602
|
+
const key = { name: "keyValue", value: "data" };
|
|
2603
|
+
yield key;
|
|
2604
|
+
yield* disassembleJson({ packValues: false, packKeys: true, streamKeys: false })(record);
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2607
|
+
yield token;
|
|
2608
|
+
}
|
|
2609
|
+
}
|
|
2610
|
+
const output = stringifyJson.asStream({ useKeyValues: true });
|
|
2611
|
+
const processing = pipeline(Readable.from(decodeRange(file, range)), tokenizer, filter, inject, output);
|
|
2612
|
+
try {
|
|
2613
|
+
await Promise.all([writeBytes(destination, output), processing]);
|
|
2614
|
+
} finally {
|
|
2615
|
+
tokenizer.destroy();
|
|
2616
|
+
filter.destroy();
|
|
2617
|
+
output.destroy();
|
|
2618
|
+
}
|
|
2619
|
+
await destination.write("\n");
|
|
2620
|
+
}
|
|
2621
|
+
function isLegacyBrowserEntry(value) {
|
|
2622
|
+
if (value.type === "custom" && typeof value.customType === "string" && [BROWSER_TRANSITION_ENTRY, "agent-browser-script-session"].includes(value.customType)) {
|
|
2623
|
+
return true;
|
|
2624
|
+
}
|
|
2625
|
+
return isRecord(value.message) && typeof value.message.toolName === "string" && BROWSER_RESULT_TOOLS.has(value.message.toolName);
|
|
2626
|
+
}
|
|
2627
|
+
var BrowserConversionWriter = class {
|
|
2628
|
+
file;
|
|
2629
|
+
stage;
|
|
2630
|
+
source;
|
|
2631
|
+
ids = /* @__PURE__ */ new Set();
|
|
2632
|
+
branches;
|
|
2633
|
+
convertedRecords = 0;
|
|
2634
|
+
snapshotDefinitions = 0;
|
|
2635
|
+
constructor(file, stage, source, metadata) {
|
|
2636
|
+
this.file = file;
|
|
2637
|
+
this.stage = stage;
|
|
2638
|
+
this.source = source;
|
|
2639
|
+
this.branches = new BrowserConversionBranches(metadata.map((entry) => entry.value.type === "session" ? void 0 : entry.value.parentId));
|
|
2640
|
+
}
|
|
2641
|
+
get counts() {
|
|
2642
|
+
return {
|
|
2643
|
+
entryCount: this.ids.size,
|
|
2644
|
+
convertedRecords: this.convertedRecords,
|
|
2645
|
+
snapshotDefinitions: this.snapshotDefinitions
|
|
2646
|
+
};
|
|
2647
|
+
}
|
|
2648
|
+
async conversion(entry) {
|
|
2649
|
+
if (entry.value.type === "session") {
|
|
2650
|
+
return void 0;
|
|
2651
|
+
}
|
|
2652
|
+
const id = entry.value.id;
|
|
2653
|
+
if (typeof id !== "string" || this.ids.has(id)) {
|
|
2654
|
+
throw new Error("Conversion source contains a missing or duplicate native entry ID.");
|
|
2655
|
+
}
|
|
2656
|
+
const parentId = entry.value.parentId;
|
|
2657
|
+
if (parentId !== null && (typeof parentId !== "string" || !this.ids.has(parentId))) {
|
|
2658
|
+
throw new Error("Conversion source contains a missing or forward parent.");
|
|
2659
|
+
}
|
|
2660
|
+
this.ids.add(id);
|
|
2661
|
+
const parent = typeof parentId === "string" ? this.branches.get(parentId) ?? emptyProjection() : emptyProjection();
|
|
2662
|
+
if (!isLegacyBrowserEntry(entry.value)) {
|
|
2663
|
+
this.branches.advance(id, parentId, parent);
|
|
2664
|
+
return void 0;
|
|
2665
|
+
}
|
|
2666
|
+
const details = await projectJson(readRange(this.file, entry), LEGACY_BROWSER_FIELDS, Infinity);
|
|
2667
|
+
const conversion = convertLegacyBrowserEntry({ ...entry.value, ...details }, parent, this.source.sessionId);
|
|
2668
|
+
this.branches.advance(id, parentId, conversion.projection);
|
|
2669
|
+
return conversion.record;
|
|
2670
|
+
}
|
|
2671
|
+
async write(entry, sourceSize) {
|
|
2672
|
+
const record = await this.conversion(entry);
|
|
2673
|
+
if (!record) {
|
|
2674
|
+
await writeBytes(this.stage, readRange(this.file, entry));
|
|
2675
|
+
if (entry.offset + entry.length === sourceSize) {
|
|
2676
|
+
await this.completeLastLine(sourceSize);
|
|
2677
|
+
}
|
|
2678
|
+
return;
|
|
2679
|
+
}
|
|
2680
|
+
const data = {
|
|
2681
|
+
...record,
|
|
2682
|
+
archive: { sourceSha256: this.source.checksum, offset: entry.offset, length: entry.length }
|
|
2683
|
+
};
|
|
2684
|
+
if (entry.value.type === "message") {
|
|
2685
|
+
await rewriteMessage(this.file, entry, this.stage, data);
|
|
2686
|
+
} else {
|
|
2687
|
+
await this.stage.write(`${JSON.stringify({ ...entry.value, customType: BROWSER_TRANSITION_ENTRY, data })}
|
|
2688
|
+
`);
|
|
2689
|
+
}
|
|
2690
|
+
this.convertedRecords++;
|
|
2691
|
+
if (record.snapshot !== void 0) {
|
|
2692
|
+
this.snapshotDefinitions++;
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2695
|
+
async completeLastLine(size) {
|
|
2696
|
+
const lastByte = Buffer.alloc(1);
|
|
2697
|
+
await this.file.read(lastByte, 0, 1, size - 1);
|
|
2698
|
+
if (lastByte[0] !== 10) {
|
|
2699
|
+
await this.stage.write("\n");
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
};
|
|
2703
|
+
|
|
2704
|
+
// dist/extensions/agent-browser/lib/browser-session-conversion.js
|
|
2705
|
+
async function validateConversionPaths(options) {
|
|
2706
|
+
if (!options.confirmedStopped) {
|
|
2707
|
+
throw new Error("Stop/quiesce the exact session writer first, then pass --confirm-stopped. Conversion never stops a session.");
|
|
2708
|
+
}
|
|
2709
|
+
const source = resolve(options.source);
|
|
2710
|
+
const destination = resolve(options.destination);
|
|
2711
|
+
if (source === destination) {
|
|
2712
|
+
throw new Error("Conversion requires a separate destination; originals are never rewritten.");
|
|
2713
|
+
}
|
|
2714
|
+
const sourceStat = await lstat(source);
|
|
2715
|
+
if (!sourceStat.isFile() || sourceStat.isSymbolicLink()) {
|
|
2716
|
+
throw new Error("Conversion source must be a regular file, not a symlink.");
|
|
2717
|
+
}
|
|
2718
|
+
const directory = dirname(destination);
|
|
2719
|
+
await mkdir(directory, { mode: 448, recursive: true });
|
|
2720
|
+
await validateDestination(directory, destination);
|
|
2721
|
+
return { source, destination, directory, sourceStat };
|
|
2722
|
+
}
|
|
2723
|
+
async function validateDestination(directory, destination) {
|
|
2724
|
+
const entry = await lstat(directory);
|
|
2725
|
+
if (!entry.isDirectory() || entry.isSymbolicLink() || process.platform !== "win32" && (entry.uid !== process.getuid?.() || (entry.mode & 63) !== 0)) {
|
|
2726
|
+
throw new Error("Conversion destination must be a private current-user directory (0700 on POSIX), without symlinks.");
|
|
2727
|
+
}
|
|
2728
|
+
try {
|
|
2729
|
+
await lstat(destination);
|
|
2730
|
+
throw new Error("Conversion destination is occupied.");
|
|
2731
|
+
} catch (error) {
|
|
2732
|
+
if (getErrorCode(error) !== "ENOENT") {
|
|
2733
|
+
throw error;
|
|
2734
|
+
}
|
|
2735
|
+
}
|
|
2736
|
+
}
|
|
2737
|
+
async function verifySourceUnchanged(file, source, initial, checksum) {
|
|
2738
|
+
const final = await file.stat();
|
|
2739
|
+
const finalPath = await lstat(source);
|
|
2740
|
+
if (final.dev !== initial.dev || final.ino !== initial.ino || final.size !== initial.size || final.mtimeMs !== initial.mtimeMs || finalPath.dev !== initial.dev || finalPath.ino !== initial.ino || await sourceChecksum(file, initial.size) !== checksum) {
|
|
2741
|
+
throw new Error("Conversion source changed; no destination was published.");
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
2744
|
+
async function syncPublishedDirectory(directory) {
|
|
2745
|
+
const parent = await open(directory, constants.O_RDONLY);
|
|
2746
|
+
try {
|
|
2747
|
+
await parent.sync();
|
|
2748
|
+
} finally {
|
|
2749
|
+
await parent.close();
|
|
2750
|
+
}
|
|
2751
|
+
}
|
|
2752
|
+
async function convertBrowserSession(options) {
|
|
2753
|
+
const { source, destination, directory, sourceStat } = await validateConversionPaths(options);
|
|
2754
|
+
const file = await open(source, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
2755
|
+
const stagePath = `${destination}.${randomUUID2()}.tmp`;
|
|
2756
|
+
let stage;
|
|
2757
|
+
let published = false;
|
|
2758
|
+
try {
|
|
2759
|
+
const initial = await file.stat();
|
|
2760
|
+
if (initial.dev !== sourceStat.dev || initial.ino !== sourceStat.ino) {
|
|
2761
|
+
throw new Error("Conversion source changed before capture.");
|
|
2762
|
+
}
|
|
2763
|
+
const checksum = await sourceChecksum(file, initial.size);
|
|
2764
|
+
const metadata = await scanJournalMetadata(file, initial.size, true);
|
|
2765
|
+
const header = metadata.at(0);
|
|
2766
|
+
if (header === void 0 || header.value.type !== "session" || typeof header.value.id !== "string") {
|
|
2767
|
+
throw new Error("Conversion source has no native session header.");
|
|
2768
|
+
}
|
|
2769
|
+
stage = await open(stagePath, "wx+", 384);
|
|
2770
|
+
const writer = new BrowserConversionWriter(file, stage, { sessionId: header.value.id, checksum }, metadata);
|
|
2771
|
+
for (const entry of metadata) {
|
|
2772
|
+
await writer.write(entry, initial.size);
|
|
2773
|
+
}
|
|
2774
|
+
await stage.sync();
|
|
2775
|
+
const output = await stage.stat();
|
|
2776
|
+
const destinationSha256 = await sourceChecksum(stage, output.size);
|
|
2777
|
+
await verifySourceUnchanged(file, source, initial, checksum);
|
|
2778
|
+
await stage.close();
|
|
2779
|
+
stage = void 0;
|
|
2780
|
+
await link(stagePath, destination);
|
|
2781
|
+
published = true;
|
|
2782
|
+
return {
|
|
2783
|
+
version: 1,
|
|
2784
|
+
source,
|
|
2785
|
+
destination,
|
|
2786
|
+
sessionId: header.value.id,
|
|
2787
|
+
sourceSha256: checksum,
|
|
2788
|
+
destinationSha256,
|
|
2789
|
+
...writer.counts,
|
|
2790
|
+
sourceBytes: initial.size,
|
|
2791
|
+
destinationBytes: output.size
|
|
2792
|
+
};
|
|
2793
|
+
} finally {
|
|
2794
|
+
await stage?.close();
|
|
2795
|
+
await file.close();
|
|
2796
|
+
await unlink(stagePath).catch((error) => {
|
|
2797
|
+
if (getErrorCode(error) !== "ENOENT") {
|
|
2798
|
+
throw error;
|
|
2799
|
+
}
|
|
2800
|
+
});
|
|
2801
|
+
if (published && process.platform !== "win32") {
|
|
2802
|
+
await syncPublishedDirectory(directory);
|
|
2803
|
+
}
|
|
2804
|
+
}
|
|
2805
|
+
}
|
|
2806
|
+
export {
|
|
2807
|
+
convertBrowserEntries,
|
|
2808
|
+
convertBrowserSession,
|
|
2809
|
+
convertLegacyBrowserEntry
|
|
2810
|
+
};
|