@fluidgrids/fe-sdk 0.0.0-stage → 2026.1203.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +564 -2
- package/dist/ActivityOptionsFields-C2u-hY2U.js +142 -0
- package/dist/AiStudioPage-B_hNTj-_.js +1137 -0
- package/dist/ApprovalInboxPage-ClITra3n.js +1312 -0
- package/dist/ChoiceSelect-LkK-uS9J.js +65 -0
- package/dist/ConfirmActionDialog-DHWTDRbp.js +31 -0
- package/dist/ConnectionFormDialog-C0kDgcrZ.js +153 -0
- package/dist/CreateFluidgridsTagDocument-Dtp9KPLJ.js +1055 -0
- package/dist/DataSinkDashboardPage-b4ezeqa6.js +278 -0
- package/dist/DataTablesPage-C1d9YGHz.js +5575 -0
- package/dist/DateTimeField-B1qR4ruo.js +51 -0
- package/dist/Disclosure-BNKij7-v.js +45 -0
- package/dist/ElementLibraryPage-8jNO6YmE.js +2256 -0
- package/dist/ElementLibrarySequenceDocument-B-W8SPzn.js +3979 -0
- package/dist/EnsureThemeProvider-BvlNjAd0.js +24 -0
- package/dist/EntityTagBadge-1OlP6p0c.js +25 -0
- package/dist/EntityTagPicker-BBrU5cE0.js +137 -0
- package/dist/ExecuteStepDocument-B4j1mdRT.js +189 -0
- package/dist/ExecutionDetailDocument-D6QuM-kp.js +875 -0
- package/dist/ExecutionDetailPage-D4CBtFdo.js +12217 -0
- package/dist/ExecutionDetailPage-DvQ667OE.d.ts +10 -0
- package/dist/ExecutionStatusBadge-BsDVor9t.js +221 -0
- package/dist/ExecutionsListDocument-Dan7ZiqB.js +459 -0
- package/dist/ExecutionsListPage-B3XT8ITL.js +4307 -0
- package/dist/FailureTriagePanel-DOJMaJ0n.js +1285 -0
- package/dist/FileDownloadUrlDocument-CVOYKcL5.js +92 -0
- package/dist/FluidGridsDocsLink-bX0Hnhxr.js +66 -0
- package/dist/FluidGridsMark-CE2blT7K.js +74 -0
- package/dist/HeldLoadRegion-BtTxbvOW.js +34 -0
- package/dist/HistoryPage-BLoRpJ1R.d.ts +6 -0
- package/dist/HistoryPage-BSBISXoj.js +2835 -0
- package/dist/Icon-BtQ0HXLh.js +160 -0
- package/dist/InsightsPage-D7ybj8N9.js +11245 -0
- package/dist/IsolationSetting-vy911E8b.js +1153 -0
- package/dist/LibraryParts-DOeNgR8A.js +413 -0
- package/dist/ManagedAiPolicyAuthority-BxwJ3ptd.js +40 -0
- package/dist/ManagedAiPolicyAuthority-DM3t3wNr.d.ts +18 -0
- package/dist/ManagedAiPolicyAuthorityContext-CNkxIOZ1.js +10 -0
- package/dist/McpTriggerServers-BCPCAOWB.js +459 -0
- package/dist/MissingNodesInstallModal-rO_SEDrC.js +224 -0
- package/dist/NavigationV2Provider-DCDt35eG.js +17 -0
- package/dist/NodeSchemaIntrospectionDocument-C1vAIcHd.js +95 -0
- package/dist/NodesPage-DEbnz9iU.d.ts +6 -0
- package/dist/NodesPage-O7KeeKtd.js +653 -0
- package/dist/OfflineIcon-TwMKYWjA.js +207 -0
- package/dist/OpenTemplateAsCodeButton-BhWJWIF3.js +94 -0
- package/dist/PaidTemplateConfirm-_G3ag6S4.js +28 -0
- package/dist/PublishCustomNodeAction-CIySbK4c.js +134 -0
- package/dist/RecordTaskDialog-BkpCDvhR.js +2078 -0
- package/dist/RunActionsMenu-DodOgIQm.js +59 -0
- package/dist/RunnerStatusPill-C1v967iq.js +24 -0
- package/dist/RunnersPage-dB0RSdY_.js +1929 -0
- package/dist/SandboxRuntimeExhaustedNotice-BFOIF93C.js +120 -0
- package/dist/SchedulesPage-DPWr1yvf.js +1607 -0
- package/dist/SearchBox-BGtYjvfs.js +49 -0
- package/dist/SequenceEditor-CFiHeHkR.js +497 -0
- package/dist/SettingsPage-0CQBNPZV.js +8695 -0
- package/dist/StewardPages-DAJhepen.js +47 -0
- package/dist/StewardRunImportPanel-Kva2DO0u.js +2844 -0
- package/dist/StoreTemplateCardCompact-CHn5kP7A.js +2166 -0
- package/dist/TagFilterSelect-CyA8QrS7.js +42 -0
- package/dist/TaskQueuesPage-DdnDCyat.js +3571 -0
- package/dist/TechnicalDetails-B0Oi4aZw.js +19 -0
- package/dist/TemplateConfigurationModal-CdvCYJLM.js +332 -0
- package/dist/TemplateDetailPanel-CbiKciuB.js +222 -0
- package/dist/TemplatePreview-cx7-NOeG.js +868 -0
- package/dist/TemplatesPage-BG3H-6v6.d.ts +10 -0
- package/dist/TemplatesPage-BVQpGYIV.js +3251 -0
- package/dist/TerminateExecutionDocument-B_HKNVrN.js +581 -0
- package/dist/TranslationBridge-Bd4aJKMs.d.ts +11 -0
- package/dist/TranslationBridge-Da-TPgQm.js +68 -0
- package/dist/TriggerWorkflowDocument-D9Km2Vv2.js +460 -0
- package/dist/UiSequencePickerSequenceDocument-BSYnSDV7.js +607 -0
- package/dist/UiStepScreenshot-Qh4QMyUp.js +146 -0
- package/dist/UsageTimeSeriesDocument-DcInx9-z.js +177 -0
- package/dist/VariablesPage-ChfGuW22.js +2243 -0
- package/dist/VersionDiffDialog-Bd2AeUwf.js +1702 -0
- package/dist/VersionLifecycleBar-BBeWVtz-.js +143 -0
- package/dist/WebhookDeliveriesPage-D66bua0j.js +1563 -0
- package/dist/WorkflowBuilder-B6wQD1TK.js +539 -0
- package/dist/WorkflowBuilder-DR4ku8Tr.js +1611 -0
- package/dist/WorkflowDefinitionDocument-DZLbTPUZ.js +321 -0
- package/dist/WorkflowEmbed-BXfFGy0i.js +708 -0
- package/dist/WorkflowEmbed-Cbqe1s1z.d.ts +6 -0
- package/dist/WorkflowPinnedDataDocument-BODT5omd.js +782 -0
- package/dist/WorkflowProposalCard-BruukdeF.js +96 -0
- package/dist/WorkflowProposalDocument-BdUbsrd0.js +620 -0
- package/dist/WorkflowSearchRedirect-C7zJ2MKH.js +40 -0
- package/dist/WorkflowSettingsDrawer-MVU1BKfY.d.ts +18 -0
- package/dist/WorkflowSettingsDrawer-gazs97WR.js +196 -0
- package/dist/WorkflowShareDialog-e8jJtLjU.js +469 -0
- package/dist/WorkflowVersionsDocument-DRVOp8Uj.js +3213 -0
- package/dist/WorkflowsList--hR2_8gf.js +4593 -0
- package/dist/WorkflowsList-CcNDQge5.d.ts +6 -0
- package/dist/WorkflowsListPageDocument-CnzcQm_o.js +934 -0
- package/dist/addonCatalog-CbZS4deh.js +58 -0
- package/dist/addonCatalog-sjlonAmR.d.ts +15 -0
- package/dist/addons.d.ts +3 -0
- package/dist/addons.js +4 -0
- package/dist/agent-form-Bfvm32j1.js +83 -0
- package/dist/agent-tools.d.ts +3 -0
- package/dist/agent-tools.js +5 -0
- package/dist/agentTools-CyL7DLOF.js +320 -0
- package/dist/ai-usage-BrxDgvdR.js +240 -0
- package/dist/aiCreditsBridge-BuE92tKo.js +49 -0
- package/dist/api-BKq-nIOZ.js +2286 -0
- package/dist/api-Ol7I8NxE.js +8289 -0
- package/dist/apollo-type-policies.d.ts +11 -0
- package/dist/apollo-type-policies.js +64 -0
- package/dist/askAboutBridge-ByYsQams.js +106 -0
- package/dist/askQuestions-Cmx7VnMm.js +742 -0
- package/dist/assert-rules-lfYEMc99.js +318 -0
- package/dist/assistant.d.ts +94 -0
- package/dist/assistant.js +99 -0
- package/dist/attach-node-helpers-HDKQOtrD.js +32 -0
- package/dist/badge-CXfPhoMH.js +26 -0
- package/dist/basil.generated-BK-EHbwN.js +10 -0
- package/dist/browser-steps-DMpS5TyB.js +533 -0
- package/dist/builderTimings-pvGnK1m-.js +510 -0
- package/dist/button-DG7y_FVJ.js +48 -0
- package/dist/canvasNoteTools-BxuP_AYO.js +137 -0
- package/dist/card-Bomy_1UG.js +44 -0
- package/dist/catalogGrid-BOrfMgi-.js +41 -0
- package/dist/channel-CPyQ1NR1.js +212 -0
- package/dist/chips-CvNrYJZa.js +27 -0
- package/dist/client-holder-C0M5Cfwl.js +68 -0
- package/dist/cn-QqidFIgr.js +10 -0
- package/dist/code-editor-diagnostics-Zr0cIcx1.js +46 -0
- package/dist/code-editor-field-x_JrY8KR.js +113 -0
- package/dist/codec-client-DPuD6mw7.js +515 -0
- package/dist/conditionBuilder-DwfEF0Q-.js +1144 -0
- package/dist/config-DO68jw5k.js +322 -0
- package/dist/constants-DgbVc24O.d.ts +296 -0
- package/dist/constants-DlRnHBfQ.js +217 -0
- package/dist/convert-browser-action-pfecelF7.js +347 -0
- package/dist/convert-dialog-B_o22NiJ.js +382 -0
- package/dist/create-workflow-first-Azg3JUdX.js +120 -0
- package/dist/definition-canvas-Bsda-rDT.js +31 -0
- package/dist/dialog-BVd152GS.js +94 -0
- package/dist/durable-nodes-BXyYCLxT.js +91 -0
- package/dist/duration-CDb7-mT_.js +33 -0
- package/dist/edge-mapper-wEAdGVU2.js +4477 -0
- package/dist/element-library-DkSlg_VE.js +727 -0
- package/dist/entities-I_0kio3q.js +38 -0
- package/dist/error-advice-QLr5NCm7.js +65 -0
- package/dist/errors-ClKb5sEt.js +188 -0
- package/dist/executions.d.ts +3 -0
- package/dist/executions.js +5 -0
- package/dist/feature-flags-B2qetXKd.js +385 -0
- package/dist/field-label-DPZRmE_B.js +153 -0
- package/dist/firstWorkflow-C_h0KMB2.js +133 -0
- package/dist/flags.d.ts +3 -0
- package/dist/flags.js +4 -0
- package/dist/flow-builder-DIvLOhz0.js +28038 -0
- package/dist/flow-store-holder-CUN7Terz.js +52 -0
- package/dist/fluent.generated-CA_e6-4l.js +14 -0
- package/dist/fluidgridsEvents-bbEQbwU6.js +175 -0
- package/dist/fluidgridsTheme-DUhvOgoy.js +297 -0
- package/dist/global-client-BQPuFrFa.js +433 -0
- package/dist/global-operations-BG6YgxrM.js +136 -0
- package/dist/graphql-types-UTYtujY9.js +21358 -0
- package/dist/history.d.ts +3 -0
- package/dist/history.js +4 -0
- package/dist/index-AoJAa5vU.d.ts +164958 -0
- package/dist/index-DEMT3iAM.d.ts +120 -0
- package/dist/index-ROZzNGyY.d.ts +76 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +8123 -0
- package/dist/ion.generated-mbajjcAg.js +10 -0
- package/dist/label-Lzb8ZXf_.js +29 -0
- package/dist/labels-rXd9gYQz.js +1236 -0
- package/dist/liveCanvas-D5ytXDp8.js +103 -0
- package/dist/logos.generated-X6_0kjVR.js +21 -0
- package/dist/logs-panel-Cw0DkG0l.js +468 -0
- package/dist/lucide.generated-B6NVd3GT.js +29 -0
- package/dist/marksStore-a9oIMMot.js +175 -0
- package/dist/mcp-trigger-D0nRdvq5.js +307 -0
- package/dist/mdi.generated-D1BV74d6.js +292 -0
- package/dist/menus-CU3hDGYl.js +160 -0
- package/dist/mynaui.generated-DMWr5cXz.js +66 -0
- package/dist/navigation-v2.d.ts +3 -0
- package/dist/navigation-v2.js +5 -0
- package/dist/node-detail-view-Cgm5H1P-.js +1372 -0
- package/dist/node-editor-tab-body-CZ0fVuVP.js +187 -0
- package/dist/node-operation-selection-CdV3KI_V.js +3534 -0
- package/dist/node-registry-refresh-s3okf83X.js +27 -0
- package/dist/node-role-TMbnkmeP.js +132 -0
- package/dist/node-type-icon-BZa8n4iG.js +33 -0
- package/dist/nodes.d.ts +3 -0
- package/dist/nodes.js +4 -0
- package/dist/notesKey-5EaREBGA.js +12 -0
- package/dist/observability.d.ts +3 -0
- package/dist/observability.js +5 -0
- package/dist/offset-pages-zghoClB3.js +55 -0
- package/dist/operations-BBmT9ToP.js +663 -0
- package/dist/operations-WxRJWeqO.js +3133 -0
- package/dist/output-files-Ba8bu5lv.js +196 -0
- package/dist/page-operation-DrWuhd6Y.js +129 -0
- package/dist/page-twins.d.ts +13 -0
- package/dist/page-twins.js +186 -0
- package/dist/pageControlSpecs-DZJ9K37m.js +134 -0
- package/dist/pageControlsBridge-0pX9s-3k.js +54 -0
- package/dist/pageControlsBridge-DAuT3w7L.d.ts +36 -0
- package/dist/panels-PfBBAToE.js +346 -0
- package/dist/parts-B7fBcw-B.js +346 -0
- package/dist/popover-Dms9Vz3j.js +3389 -0
- package/dist/preloadable-lazy-Pp47mqQ9.js +65 -0
- package/dist/proactive.d.ts +66 -0
- package/dist/proactive.js +237 -0
- package/dist/quick-config-panel-DFd77xho.js +451 -0
- package/dist/quota-DeA_CJ2e.js +175 -0
- package/dist/quota.d.ts +3 -0
- package/dist/quota.js +4 -0
- package/dist/read-only-context-Dt9N9SIG.js +18 -0
- package/dist/relative-time-Dxt8ZIIu.js +55 -0
- package/dist/results-CwK_yDxK.js +325 -0
- package/dist/rolldown-runtime-hDbaFkMy.js +18 -0
- package/dist/route-data.d.ts +12 -0
- package/dist/route-data.js +69 -0
- package/dist/route-match-C-0_EnAt.d.ts +5 -0
- package/dist/route-match-DMkUICYV.js +41 -0
- package/dist/route-preload-C4DlGoCd.js +120 -0
- package/dist/run-display-UjLAoYqQ.js +81 -0
- package/dist/run-history-arGiHzGU.js +285 -0
- package/dist/run-list-links-DJn4Mf1T.js +98 -0
- package/dist/run-mode-USmM0-Uo.js +82 -0
- package/dist/run-parity-CWXqEJqM.js +144 -0
- package/dist/runsQuota-B6SyTbne.js +100 -0
- package/dist/runsQuota-DsniKiSg.d.ts +20 -0
- package/dist/safe-expression-Cw7-SCsm.js +1251 -0
- package/dist/save-status-store-C7nEYpfb.js +631 -0
- package/dist/schedule-panel-B4GYXzXQ.js +13774 -0
- package/dist/schedule-rules-ggVKRkBH.js +358 -0
- package/dist/secrets-Re_wSiE3.js +153 -0
- package/dist/settings.d.ts +4 -0
- package/dist/settings.js +6 -0
- package/dist/shared-DAWGGMSM.js +177 -0
- package/dist/sidebar-node-editor-6eSSgCzc.js +178 -0
- package/dist/solar.generated-CGYuUQAC.js +10 -0
- package/dist/stableTabbedDialog-BBhrfXGe.js +20 -0
- package/dist/start-url-CT6Yz96K.js +24 -0
- package/dist/status-CessxGpm.js +55 -0
- package/dist/store-icon-OctYp5zP.js +155 -0
- package/dist/styles-WGmTnZ2n.js +26 -0
- package/dist/styles.css +139 -0
- package/dist/svg-spinners.generated-CIPT7IhM.js +10 -0
- package/dist/template-code-CzN6JWNV.js +191 -0
- package/dist/template-graph-DLF9dygU.js +20 -0
- package/dist/template-preview-DcIIKOOL.js +32 -0
- package/dist/template-price-CdUHZRMF.js +40 -0
- package/dist/templates.d.ts +3 -0
- package/dist/templates.js +5 -0
- package/dist/theme-provider-CntfC4_i.js +23 -0
- package/dist/transient-DgZfhDfN.js +57 -0
- package/dist/typed-calls-C5tO03wq.js +26 -0
- package/dist/ui-script-By74Guk3.js +1094 -0
- package/dist/ui-script-editor-CqPu2bCN.js +2447 -0
- package/dist/ui-step-fix-8uM2_Hft.js +67 -0
- package/dist/ui-step-fix-store-CcO1FdRx.js +19 -0
- package/dist/ui-step-run-context-o7bLE6KP.js +46 -0
- package/dist/ui-target-editor-D2JhB_lD.js +673 -0
- package/dist/uiMarkTools-CSznnO1i.js +1054 -0
- package/dist/upgradePrompt-BAFBKKW5.js +72 -0
- package/dist/use-bare-node-registry-O6mKJO_n.js +11498 -0
- package/dist/use-browser-available-hj8wc3Kb.js +241 -0
- package/dist/use-edge-mapper-schemas-Bonofxow.js +496 -0
- package/dist/use-extension-bridge-B9ZreOkQ.js +608 -0
- package/dist/use-mobile-BTqCUjzS.js +27 -0
- package/dist/use-sdk-query-C697xZVv.js +116 -0
- package/dist/use-workflow-code-editor-CFoRFrZ5.js +753 -0
- package/dist/useActionParam-B2tU2BlY.js +85 -0
- package/dist/useAgentTokenStream-Bko_J0d0.js +4217 -0
- package/dist/useBrowserClients-3v95-gSh.js +103 -0
- package/dist/useCodeWorkflowInsights-w0tz9Ap_.js +600 -0
- package/dist/useConnections-DsgEJs05.js +439 -0
- package/dist/useDebouncedValue-BFekcv6n.js +18 -0
- package/dist/useDurableParity-8fnMZmBc.js +1787 -0
- package/dist/useEntityTags-D0spL6Ut.js +460 -0
- package/dist/useExecutions-2u5nGJJk.js +681 -0
- package/dist/useFluidGridsAnalytics-VM8lAi2x.js +238 -0
- package/dist/useGlobalStoreClient-BTdhkA2I.js +24 -0
- package/dist/useHumanRequests-zlYDp3l1.js +221 -0
- package/dist/useNavigationV2-C2WeqN7d.js +29 -0
- package/dist/useNavigationV2-DANUmg12.d.ts +9 -0
- package/dist/useObservability-BRlQ0tOA.js +285 -0
- package/dist/useRequestedProposal-B7uPXfZB.js +51 -0
- package/dist/useRunHistory-CXCMUPyf.js +2759 -0
- package/dist/useRunLive-D0JvVZT2.js +1060 -0
- package/dist/useRunnerList-Dbi59i1K.js +446 -0
- package/dist/useRunners-URUc5quU.js +173 -0
- package/dist/useRunsPage-DG656UCK.js +2709 -0
- package/dist/useVariables-BIelxcWr.js +463 -0
- package/dist/useVersionHistoryData-CTjqVw7l.js +292 -0
- package/dist/useWorkflowCodeExport-pqxyLHD1.js +522 -0
- package/dist/useWorkflowListExport-hcZNvTaB.js +232 -0
- package/dist/useWorkflowOrganization-CpBbOrs7.js +1772 -0
- package/dist/useWorkflowProposal-BH0VdNMA.js +3280 -0
- package/dist/useWorkflows-Cvg-Z_IE.js +1606 -0
- package/dist/utils-fvBb5qOD.js +89 -0
- package/dist/webhook-deliveries-AvQujaZy.js +99 -0
- package/dist/workflow-builder-CJygVkVv.d.ts +2 -0
- package/dist/workflow-builder.d.ts +3 -0
- package/dist/workflow-builder.js +8 -0
- package/dist/workflow-code-transfer-Bsy0JKAZ.js +323 -0
- package/dist/workflow-embed.d.ts +3 -0
- package/dist/workflow-embed.js +4 -0
- package/dist/workflow-git-sync--K9ZsPDC.js +263 -0
- package/dist/workflow-host.d.ts +6 -0
- package/dist/workflow-host.js +11 -0
- package/dist/workflow-pages-D-7ByLTB.d.ts +68 -0
- package/dist/workflow-pages.d.ts +3 -0
- package/dist/workflow-pages.js +115 -0
- package/dist/workflow-preview-canvas-CO8yzdE3.js +848 -0
- package/dist/workflow-preview.d.ts +65 -0
- package/dist/workflow-preview.js +4 -0
- package/dist/workflow-route.d.ts +33 -0
- package/dist/workflow-route.js +4 -0
- package/dist/workflow-save-state-D0l-DkLf.js +767 -0
- package/dist/workflow-transfer-CQnQC-ke.js +104 -0
- package/dist/workflowRouteData-BkfVOc-O.js +169 -0
- package/dist/workflows-list.d.ts +10 -0
- package/dist/workflows-list.js +5 -0
- package/package.json +320 -4
|
@@ -0,0 +1,608 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { t as fetchMyBrowserClients } from "./useBrowserClients-3v95-gSh.js";
|
|
3
|
+
import { useCallback, useEffect, useLayoutEffect, useReducer, useRef, useState } from "react";
|
|
4
|
+
|
|
5
|
+
// src/rpa/extension-bridge.ts
|
|
6
|
+
/**
|
|
7
|
+
* The builder end of the browser extension bridge `fluidgrids:rpa-bridge` v1
|
|
8
|
+
* (RPA plan P1-12; the extension end is P1-10, `docs/RPA_BRIDGE.md` in
|
|
9
|
+
* fluidgrids-browser-extension; threat review document 20, B1 to B10).
|
|
10
|
+
*
|
|
11
|
+
* The builder talks to the extension with `window.postMessage` only:
|
|
12
|
+
*
|
|
13
|
+
* - every request is posted to the page's own origin, never to `"*"`;
|
|
14
|
+
* - an answer is accepted only from this window (`event.source`), from this
|
|
15
|
+
* origin (`event.origin`), on the bridge channel and version, and only as a
|
|
16
|
+
* `response` to a request this bridge sent, or as an `event`;
|
|
17
|
+
* - `hello` returns the extension's version, its capabilities and a nonce.
|
|
18
|
+
* Every other call sends the latest nonce, and every answer carries the next
|
|
19
|
+
* one. A nonce is single use, so a `NONCE_INVALID` answer says `hello` again
|
|
20
|
+
* and retries the call once.
|
|
21
|
+
*
|
|
22
|
+
* The extension answers only on the top frame of `https://app.fluidgrids.ai`
|
|
23
|
+
* and `https://alphaapp.fluidgrids.ai` (local builds also on localhost), so the
|
|
24
|
+
* builder offers the recorder only there ({@link isBridgeOrigin}). A page sees
|
|
25
|
+
* no answer at all when the extension is missing or older than 0.4.0; which of
|
|
26
|
+
* the two it is comes from the person's paired browsers
|
|
27
|
+
* ({@link classifyBridgeProbe}).
|
|
28
|
+
*
|
|
29
|
+
* Nothing here loads `@burdenoff/ui-engine` or React.
|
|
30
|
+
*/
|
|
31
|
+
/** The bridge's message channel. */
|
|
32
|
+
const BRIDGE_CHANNEL = "fluidgrids:rpa-bridge";
|
|
33
|
+
/** The protocol version this builder speaks. */
|
|
34
|
+
const BRIDGE_VERSION = 1;
|
|
35
|
+
/** The app origins the extension's bridge answers on (threat review B2). */
|
|
36
|
+
const BRIDGE_APP_ORIGINS = ["https://app.fluidgrids.ai", "https://alphaapp.fluidgrids.ai"];
|
|
37
|
+
/** The first extension version with the bridge. */
|
|
38
|
+
const MIN_BRIDGE_EXTENSION_VERSION = "0.4.0";
|
|
39
|
+
/** How long `hello` waits before the extension counts as absent or too old. */
|
|
40
|
+
const HELLO_TIMEOUT_MS = 1e3;
|
|
41
|
+
/** How long any other call waits for its answer. */
|
|
42
|
+
const CALL_TIMEOUT_MS = 15e3;
|
|
43
|
+
/** The capabilities the builder needs from a bridge. */
|
|
44
|
+
const RECORD_CAPABILITIES = ["bridge:1", "record:targets"];
|
|
45
|
+
const PICK_CAPABILITIES = ["bridge:1", "pick:target"];
|
|
46
|
+
const EXTENSION_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
47
|
+
"BAD_REQUEST",
|
|
48
|
+
"UNSUPPORTED_VERSION",
|
|
49
|
+
"NONCE_INVALID",
|
|
50
|
+
"NOT_SIGNED_IN",
|
|
51
|
+
"WORKSPACE_MISMATCH",
|
|
52
|
+
"INVALID_URL",
|
|
53
|
+
"BUSY",
|
|
54
|
+
"NOT_FOUND",
|
|
55
|
+
"NOT_READY",
|
|
56
|
+
"EMPTY_RECORDING",
|
|
57
|
+
"TOO_LARGE",
|
|
58
|
+
"FAILED"
|
|
59
|
+
]);
|
|
60
|
+
/** A call the extension refused, or that got no answer. */
|
|
61
|
+
var BridgeCallError = class extends Error {
|
|
62
|
+
code;
|
|
63
|
+
constructor(code, message) {
|
|
64
|
+
super(message);
|
|
65
|
+
this.name = "BridgeCallError";
|
|
66
|
+
this.code = code;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const BRIDGE_EVENT_NAMES = /* @__PURE__ */ new Set([
|
|
70
|
+
"recordingStarted",
|
|
71
|
+
"recordingReady",
|
|
72
|
+
"recording",
|
|
73
|
+
"pickerStarted",
|
|
74
|
+
"pickReady",
|
|
75
|
+
"pick",
|
|
76
|
+
"declined",
|
|
77
|
+
"cancelled",
|
|
78
|
+
"failed"
|
|
79
|
+
]);
|
|
80
|
+
const LOCAL_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1"]);
|
|
81
|
+
/**
|
|
82
|
+
* Whether a page on `origin` can use the bridge: exactly one of the two app
|
|
83
|
+
* origins, or a local development server on `http://localhost:<port>` or
|
|
84
|
+
* `http://127.0.0.1:<port>` (the extension answers there only in its local
|
|
85
|
+
* builds). Every other shell, the apex domain and `www` are outside.
|
|
86
|
+
*/
|
|
87
|
+
function isBridgeOrigin(origin) {
|
|
88
|
+
if (!origin) return false;
|
|
89
|
+
if (BRIDGE_APP_ORIGINS.includes(origin)) return true;
|
|
90
|
+
try {
|
|
91
|
+
const url = new URL(origin);
|
|
92
|
+
return url.protocol === "http:" && LOCAL_HOSTS.has(url.hostname) && url.origin === origin;
|
|
93
|
+
} catch {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function isRecord(value) {
|
|
98
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
99
|
+
}
|
|
100
|
+
/** A dotted version as numbers (`"0.4.0"` → `[0, 4, 0]`); null when it is not one. */
|
|
101
|
+
function versionParts(version) {
|
|
102
|
+
const match = /^v?(\d+)\.(\d+)(?:\.(\d+))?/.exec(version.trim());
|
|
103
|
+
if (!match) return null;
|
|
104
|
+
return [
|
|
105
|
+
Number(match[1]),
|
|
106
|
+
Number(match[2]),
|
|
107
|
+
Number(match[3] ?? 0)
|
|
108
|
+
];
|
|
109
|
+
}
|
|
110
|
+
/** Whether `version` is at least `minimum`. An unreadable version is not. */
|
|
111
|
+
function isVersionAtLeast(version, minimum = MIN_BRIDGE_EXTENSION_VERSION) {
|
|
112
|
+
if (!version) return false;
|
|
113
|
+
const have = versionParts(version);
|
|
114
|
+
const need = versionParts(minimum);
|
|
115
|
+
if (!have || !need) return false;
|
|
116
|
+
for (let index = 0; index < need.length; index++) {
|
|
117
|
+
const a = have[index] ?? 0;
|
|
118
|
+
const b = need[index] ?? 0;
|
|
119
|
+
if (a !== b) return a > b;
|
|
120
|
+
}
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
/** Whether a bridge's capabilities hold every one `needed`. */
|
|
124
|
+
function hasCapabilities(capabilities, needed) {
|
|
125
|
+
const have = new Set(capabilities);
|
|
126
|
+
return needed.every((capability) => have.has(capability));
|
|
127
|
+
}
|
|
128
|
+
/** The answer of `hello`, checked; null when it is not one. */
|
|
129
|
+
function readHello(result) {
|
|
130
|
+
if (typeof result.version !== "string") return null;
|
|
131
|
+
const capabilities = Array.isArray(result.capabilities) ? result.capabilities.filter((capability) => typeof capability === "string") : [];
|
|
132
|
+
return {
|
|
133
|
+
version: result.version,
|
|
134
|
+
capabilities
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
let requestCounter = 0;
|
|
138
|
+
function defaultRequestId() {
|
|
139
|
+
requestCounter += 1;
|
|
140
|
+
return `fg-${Date.now().toString(36)}-${requestCounter.toString(36)}`;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* One bridge to the extension for a window. It keeps the latest nonce, matches
|
|
144
|
+
* answers to requests and hands operation events to its listeners.
|
|
145
|
+
*/
|
|
146
|
+
var ExtensionBridge = class {
|
|
147
|
+
win;
|
|
148
|
+
origin;
|
|
149
|
+
helloTimeoutMs;
|
|
150
|
+
callTimeoutMs;
|
|
151
|
+
newRequestId;
|
|
152
|
+
pending = /* @__PURE__ */ new Map();
|
|
153
|
+
listeners = /* @__PURE__ */ new Set();
|
|
154
|
+
nonce = null;
|
|
155
|
+
disposed = false;
|
|
156
|
+
constructor(win, options = {}) {
|
|
157
|
+
this.win = win;
|
|
158
|
+
this.origin = win.location.origin;
|
|
159
|
+
this.helloTimeoutMs = options.helloTimeoutMs ?? 1e3;
|
|
160
|
+
this.callTimeoutMs = options.callTimeoutMs ?? 15e3;
|
|
161
|
+
this.newRequestId = options.newRequestId ?? defaultRequestId;
|
|
162
|
+
this.win.addEventListener("message", this.onMessage);
|
|
163
|
+
}
|
|
164
|
+
/** Whether this page may use the bridge at all. */
|
|
165
|
+
get available() {
|
|
166
|
+
return !this.disposed && isBridgeOrigin(this.origin);
|
|
167
|
+
}
|
|
168
|
+
/** Says `hello`: the extension's version and capabilities, and a fresh nonce. */
|
|
169
|
+
async hello() {
|
|
170
|
+
const hello = readHello(await this.send("hello", void 0, this.helloTimeoutMs));
|
|
171
|
+
if (!hello) throw new BridgeCallError("FAILED", "The extension answered hello without a version.");
|
|
172
|
+
return hello;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* One operation other than `hello`. Says `hello` first when no nonce is
|
|
176
|
+
* held, and once more when the extension refuses the nonce.
|
|
177
|
+
*/
|
|
178
|
+
async call(op, args) {
|
|
179
|
+
if (this.nonce === null) await this.hello();
|
|
180
|
+
try {
|
|
181
|
+
return await this.send(op, args, this.callTimeoutMs);
|
|
182
|
+
} catch (error) {
|
|
183
|
+
if (!(error instanceof BridgeCallError) || error.code !== "NONCE_INVALID") throw error;
|
|
184
|
+
await this.hello();
|
|
185
|
+
return this.send(op, args, this.callTimeoutMs);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/** Listens to operation events; returns the function that stops listening. */
|
|
189
|
+
onEvent(listener) {
|
|
190
|
+
this.listeners.add(listener);
|
|
191
|
+
return () => {
|
|
192
|
+
this.listeners.delete(listener);
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
/** Stops listening and fails every open call. */
|
|
196
|
+
dispose() {
|
|
197
|
+
if (this.disposed) return;
|
|
198
|
+
this.disposed = true;
|
|
199
|
+
this.win.removeEventListener("message", this.onMessage);
|
|
200
|
+
for (const [id, call] of this.pending) {
|
|
201
|
+
clearTimeout(call.timer);
|
|
202
|
+
call.reject(new BridgeCallError("UNAVAILABLE", "The bridge was closed."));
|
|
203
|
+
this.pending.delete(id);
|
|
204
|
+
}
|
|
205
|
+
this.listeners.clear();
|
|
206
|
+
}
|
|
207
|
+
send(op, args, timeoutMs) {
|
|
208
|
+
if (!this.available) return Promise.reject(new BridgeCallError("UNAVAILABLE", "The browser extension cannot be reached from this page."));
|
|
209
|
+
const id = this.newRequestId();
|
|
210
|
+
const nonce = op === "hello" ? void 0 : this.nonce;
|
|
211
|
+
if (op !== "hello") this.nonce = null;
|
|
212
|
+
return new Promise((resolve, reject) => {
|
|
213
|
+
const timer = setTimeout(() => {
|
|
214
|
+
this.pending.delete(id);
|
|
215
|
+
reject(new BridgeCallError("TIMEOUT", `The extension did not answer ${op}.`));
|
|
216
|
+
}, timeoutMs);
|
|
217
|
+
this.pending.set(id, {
|
|
218
|
+
resolve,
|
|
219
|
+
reject,
|
|
220
|
+
timer
|
|
221
|
+
});
|
|
222
|
+
this.win.postMessage({
|
|
223
|
+
channel: BRIDGE_CHANNEL,
|
|
224
|
+
v: 1,
|
|
225
|
+
kind: "request",
|
|
226
|
+
id,
|
|
227
|
+
op,
|
|
228
|
+
...nonce ? { nonce } : {},
|
|
229
|
+
...args ? { args } : {}
|
|
230
|
+
}, this.origin);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
onMessage = (event) => {
|
|
234
|
+
if (event.source !== this.win || event.origin !== this.origin) return;
|
|
235
|
+
const data = event.data;
|
|
236
|
+
if (!isRecord(data) || data.channel !== "fluidgrids:rpa-bridge" || data.v !== 1) return;
|
|
237
|
+
if (data.kind === "response") this.onResponse(data);
|
|
238
|
+
else if (data.kind === "event") this.onBridgeEvent(data);
|
|
239
|
+
};
|
|
240
|
+
onResponse(data) {
|
|
241
|
+
const id = typeof data.id === "string" ? data.id : null;
|
|
242
|
+
const call = id === null ? void 0 : this.pending.get(id);
|
|
243
|
+
if (!call || id === null) return;
|
|
244
|
+
this.pending.delete(id);
|
|
245
|
+
clearTimeout(call.timer);
|
|
246
|
+
if (data.ok === true) {
|
|
247
|
+
const result = isRecord(data.result) ? { ...data.result } : {};
|
|
248
|
+
if (typeof result.nonce === "string") this.nonce = result.nonce;
|
|
249
|
+
delete result.nonce;
|
|
250
|
+
call.resolve(result);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
const error = isRecord(data.error) ? data.error : {};
|
|
254
|
+
if (typeof error.nonce === "string") this.nonce = error.nonce;
|
|
255
|
+
const code = typeof error.code === "string" && EXTENSION_ERROR_CODES.has(error.code) ? error.code : "FAILED";
|
|
256
|
+
const message = typeof error.message === "string" && error.message ? error.message : "The extension refused the request.";
|
|
257
|
+
call.reject(new BridgeCallError(code, message));
|
|
258
|
+
}
|
|
259
|
+
onBridgeEvent(data) {
|
|
260
|
+
if (typeof data.event !== "string" || !BRIDGE_EVENT_NAMES.has(data.event)) return;
|
|
261
|
+
if (typeof data.operationId !== "string" || !data.operationId) return;
|
|
262
|
+
const bridgeEvent = {
|
|
263
|
+
event: data.event,
|
|
264
|
+
operationId: data.operationId,
|
|
265
|
+
data: isRecord(data.data) ? data.data : {}
|
|
266
|
+
};
|
|
267
|
+
for (const listener of [...this.listeners]) listener(bridgeEvent);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
/**
|
|
271
|
+
* What a `hello` probe means. `hello` is the answer (null when it timed out);
|
|
272
|
+
* `paired` are the person's paired browsers, read only when it timed out.
|
|
273
|
+
*/
|
|
274
|
+
function classifyBridgeProbe(hello, paired, needed = RECORD_CAPABILITIES) {
|
|
275
|
+
if (hello) return isVersionAtLeast(hello.version) && hasCapabilities(hello.capabilities, needed) ? {
|
|
276
|
+
kind: "ready",
|
|
277
|
+
hello
|
|
278
|
+
} : {
|
|
279
|
+
kind: "tooOld",
|
|
280
|
+
version: hello.version
|
|
281
|
+
};
|
|
282
|
+
const newest = paired.filter((client) => client.kind === "BROWSER" && !isVersionAtLeast(client.extensionVersion)).sort((a, b) => (Date.parse(b.lastSeenAt) || 0) - (Date.parse(a.lastSeenAt) || 0))[0];
|
|
283
|
+
return newest ? {
|
|
284
|
+
kind: "tooOld",
|
|
285
|
+
version: newest.extensionVersion
|
|
286
|
+
} : { kind: "absent" };
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// src/rpa/bridge-operation.ts
|
|
290
|
+
const IDLE_OPERATION = { phase: "idle" };
|
|
291
|
+
/** The operation this state follows, when it follows one. */
|
|
292
|
+
function operationIdOf(state) {
|
|
293
|
+
return "operationId" in state ? state.operationId : null;
|
|
294
|
+
}
|
|
295
|
+
/** Whether the operation is open in the extension (it can be cancelled there). */
|
|
296
|
+
function isOperationOpen(state) {
|
|
297
|
+
return state.phase === "consent" || state.phase === "active" || state.phase === "confirming" || state.phase === "declined";
|
|
298
|
+
}
|
|
299
|
+
/** The events that end an operation in the result, by kind. */
|
|
300
|
+
const RESULT_EVENT = {
|
|
301
|
+
record: "recording",
|
|
302
|
+
pick: "pick"
|
|
303
|
+
};
|
|
304
|
+
/** The events that say the result is ready to ask for, by kind. */
|
|
305
|
+
const READY_EVENT = {
|
|
306
|
+
record: "recordingReady",
|
|
307
|
+
pick: "pickReady"
|
|
308
|
+
};
|
|
309
|
+
/** The events that say the recording or picker started, by kind. */
|
|
310
|
+
const STARTED_EVENT = {
|
|
311
|
+
record: "recordingStarted",
|
|
312
|
+
pick: "pickerStarted"
|
|
313
|
+
};
|
|
314
|
+
function stepCountOf(data) {
|
|
315
|
+
return typeof data.stepCount === "number" && Number.isFinite(data.stepCount) ? data.stepCount : void 0;
|
|
316
|
+
}
|
|
317
|
+
function failedMessage(data) {
|
|
318
|
+
return typeof data.message === "string" && data.message ? data.message : "The extension stopped the operation.";
|
|
319
|
+
}
|
|
320
|
+
/** The next state of a `kind` operation after `action`. */
|
|
321
|
+
function bridgeOperationReducer(kind, state, action) {
|
|
322
|
+
switch (action.type) {
|
|
323
|
+
case "reset": return IDLE_OPERATION;
|
|
324
|
+
case "start": return { phase: "starting" };
|
|
325
|
+
case "started": return state.phase === "starting" ? {
|
|
326
|
+
phase: "consent",
|
|
327
|
+
operationId: action.operationId
|
|
328
|
+
} : state;
|
|
329
|
+
case "handOffAsked": return operationIdOf(state) === action.operationId && isOperationOpen(state) ? {
|
|
330
|
+
phase: "confirming",
|
|
331
|
+
operationId: action.operationId,
|
|
332
|
+
stepCount: "stepCount" in state ? state.stepCount : void 0
|
|
333
|
+
} : state;
|
|
334
|
+
case "error": return {
|
|
335
|
+
phase: "failed",
|
|
336
|
+
code: action.code,
|
|
337
|
+
message: action.message
|
|
338
|
+
};
|
|
339
|
+
case "cancelled": return {
|
|
340
|
+
phase: "ended",
|
|
341
|
+
reason: "cancelled"
|
|
342
|
+
};
|
|
343
|
+
case "event": return onEvent(kind, state, action.event);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
function onEvent(kind, state, event) {
|
|
347
|
+
if (operationIdOf(state) !== event.operationId || !isOperationOpen(state)) return state;
|
|
348
|
+
const operationId = event.operationId;
|
|
349
|
+
switch (event.event) {
|
|
350
|
+
case STARTED_EVENT[kind]: return {
|
|
351
|
+
phase: "active",
|
|
352
|
+
operationId
|
|
353
|
+
};
|
|
354
|
+
case READY_EVENT[kind]: return {
|
|
355
|
+
phase: "active",
|
|
356
|
+
operationId,
|
|
357
|
+
stepCount: stepCountOf(event.data)
|
|
358
|
+
};
|
|
359
|
+
case RESULT_EVENT[kind]: return {
|
|
360
|
+
phase: "received",
|
|
361
|
+
operationId,
|
|
362
|
+
data: event.data
|
|
363
|
+
};
|
|
364
|
+
case "declined": return state.phase === "consent" ? {
|
|
365
|
+
phase: "ended",
|
|
366
|
+
reason: "notAllowed"
|
|
367
|
+
} : {
|
|
368
|
+
phase: "declined",
|
|
369
|
+
operationId,
|
|
370
|
+
stepCount: "stepCount" in state ? state.stepCount : void 0
|
|
371
|
+
};
|
|
372
|
+
case "cancelled": return {
|
|
373
|
+
phase: "ended",
|
|
374
|
+
reason: "cancelled"
|
|
375
|
+
};
|
|
376
|
+
case "failed": {
|
|
377
|
+
const code = event.data.code;
|
|
378
|
+
return {
|
|
379
|
+
phase: "failed",
|
|
380
|
+
code: code === "TOO_LARGE" || code === "EMPTY_RECORDING" ? code : "FAILED",
|
|
381
|
+
message: failedMessage(event.data)
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
default: return state;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
/** Whether an event carries the operation's result. */
|
|
388
|
+
function isResultEvent(kind, event) {
|
|
389
|
+
return event.event === RESULT_EVENT[kind];
|
|
390
|
+
}
|
|
391
|
+
/** Whether an event says the result can be asked for now. */
|
|
392
|
+
function isReadyEvent(kind, event) {
|
|
393
|
+
return event.event === READY_EVENT[kind];
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// src/rpa/use-extension-bridge.ts
|
|
397
|
+
/**
|
|
398
|
+
* React hooks over the extension bridge (RPA plan P1-12):
|
|
399
|
+
*
|
|
400
|
+
* - {@link useBridgeAvailability} says `hello` and tells the recorder screens
|
|
401
|
+
* which state to show: ready, extension too old (spec 19 M3b panel F), no
|
|
402
|
+
* extension (panel E) or a shell the extension does not answer on. It checks
|
|
403
|
+
* again when the person comes back to the tab (after installing or
|
|
404
|
+
* updating the extension).
|
|
405
|
+
* - {@link useBridgeOperation} runs one recording or picker operation: start,
|
|
406
|
+
* ask for the result as soon as the extension says it is ready, ask again
|
|
407
|
+
* after "Don't send", and cancel (also when the screen closes).
|
|
408
|
+
*
|
|
409
|
+
* One bridge serves the window ({@link getExtensionBridge}). Nothing here
|
|
410
|
+
* loads the RPA engine.
|
|
411
|
+
*/
|
|
412
|
+
let shared = null;
|
|
413
|
+
let sharedWindow = null;
|
|
414
|
+
/** The window's bridge, or null on a page the extension does not answer on. */
|
|
415
|
+
function getExtensionBridge() {
|
|
416
|
+
if (typeof window === "undefined") return null;
|
|
417
|
+
if (!isBridgeOrigin(window.location.origin)) return null;
|
|
418
|
+
if (!shared || sharedWindow !== window) {
|
|
419
|
+
shared?.dispose();
|
|
420
|
+
shared = new ExtensionBridge(window);
|
|
421
|
+
sharedWindow = window;
|
|
422
|
+
}
|
|
423
|
+
return shared;
|
|
424
|
+
}
|
|
425
|
+
/** Whether this page can use the recorder at all (the FluidGrids app origins). */
|
|
426
|
+
function canUseBridgeHere() {
|
|
427
|
+
return typeof window !== "undefined" && isBridgeOrigin(window.location.origin);
|
|
428
|
+
}
|
|
429
|
+
/** Says `hello` and classifies the answer (or the silence). */
|
|
430
|
+
async function probeBridge(deps) {
|
|
431
|
+
const { bridge } = deps;
|
|
432
|
+
if (!bridge?.available) return { kind: "unsupported" };
|
|
433
|
+
let hello = null;
|
|
434
|
+
try {
|
|
435
|
+
hello = await bridge.hello();
|
|
436
|
+
} catch (error) {
|
|
437
|
+
if (!(error instanceof BridgeCallError) || error.code !== "TIMEOUT") return {
|
|
438
|
+
kind: "tooOld",
|
|
439
|
+
version: null
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
if (hello) return classifyBridgeProbe(hello, [], deps.needed ?? RECORD_CAPABILITIES);
|
|
443
|
+
const paired = await deps.pairedBrowsers().catch(() => []);
|
|
444
|
+
return classifyBridgeProbe(null, paired, deps.needed ?? RECORD_CAPABILITIES);
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Which recorder state to show. `enabled` false skips the check (a closed
|
|
448
|
+
* dialog). Checks again on focus until the bridge is ready.
|
|
449
|
+
*/
|
|
450
|
+
function useBridgeAvailability(enabled = true, needed = RECORD_CAPABILITIES) {
|
|
451
|
+
const [availability, setAvailability] = useState(null);
|
|
452
|
+
const [round, setRound] = useState(0);
|
|
453
|
+
const neededKey = needed.join(" ");
|
|
454
|
+
useEffect(() => {
|
|
455
|
+
if (!enabled) return;
|
|
456
|
+
let current = true;
|
|
457
|
+
probeBridge({
|
|
458
|
+
bridge: getExtensionBridge(),
|
|
459
|
+
pairedBrowsers: fetchMyBrowserClients,
|
|
460
|
+
needed: neededKey.split(" ")
|
|
461
|
+
}).then((result) => {
|
|
462
|
+
if (current) setAvailability(result);
|
|
463
|
+
});
|
|
464
|
+
return () => {
|
|
465
|
+
current = false;
|
|
466
|
+
};
|
|
467
|
+
}, [
|
|
468
|
+
enabled,
|
|
469
|
+
round,
|
|
470
|
+
neededKey
|
|
471
|
+
]);
|
|
472
|
+
const ready = availability?.kind === "ready" || availability?.kind === "unsupported";
|
|
473
|
+
useEffect(() => {
|
|
474
|
+
if (!enabled || ready || typeof window === "undefined") return;
|
|
475
|
+
const onFocus = () => setRound((value) => value + 1);
|
|
476
|
+
window.addEventListener("focus", onFocus);
|
|
477
|
+
return () => window.removeEventListener("focus", onFocus);
|
|
478
|
+
}, [enabled, ready]);
|
|
479
|
+
return {
|
|
480
|
+
availability,
|
|
481
|
+
recheck: useCallback(() => setRound((value) => value + 1), [])
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
const START_OP = {
|
|
485
|
+
record: "startRecording",
|
|
486
|
+
pick: "startPicker"
|
|
487
|
+
};
|
|
488
|
+
const HAND_OFF_OP = {
|
|
489
|
+
record: "getRecording",
|
|
490
|
+
pick: "pickResult"
|
|
491
|
+
};
|
|
492
|
+
function errorAction(error) {
|
|
493
|
+
return error instanceof BridgeCallError ? {
|
|
494
|
+
type: "error",
|
|
495
|
+
code: error.code,
|
|
496
|
+
message: error.message
|
|
497
|
+
} : {
|
|
498
|
+
type: "error",
|
|
499
|
+
code: "FAILED",
|
|
500
|
+
message: "The extension did not answer."
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* One recording (`record`) or picker (`pick`) operation for `workspaceId`.
|
|
505
|
+
* `onReceived` gets the result as it arrives (from the bridge's event, never
|
|
506
|
+
* from an effect); the operation then starts over.
|
|
507
|
+
*/
|
|
508
|
+
function useBridgeOperation(kind, workspaceId, onReceived) {
|
|
509
|
+
const [state, dispatch] = useReducer((current, action) => bridgeOperationReducer(kind, current, action), IDLE_OPERATION);
|
|
510
|
+
const stateRef = useRef(state);
|
|
511
|
+
const workspaceRef = useRef(workspaceId);
|
|
512
|
+
const receivedRef = useRef(onReceived);
|
|
513
|
+
useLayoutEffect(() => {
|
|
514
|
+
stateRef.current = state;
|
|
515
|
+
workspaceRef.current = workspaceId;
|
|
516
|
+
receivedRef.current = onReceived;
|
|
517
|
+
});
|
|
518
|
+
const askHandOff = useCallback((operationId) => {
|
|
519
|
+
const bridge = getExtensionBridge();
|
|
520
|
+
if (!bridge) return;
|
|
521
|
+
bridge.call(HAND_OFF_OP[kind], {
|
|
522
|
+
workspaceId: workspaceRef.current,
|
|
523
|
+
operationId
|
|
524
|
+
}).then(() => dispatch({
|
|
525
|
+
type: "handOffAsked",
|
|
526
|
+
operationId
|
|
527
|
+
})).catch((error) => {
|
|
528
|
+
if (error instanceof BridgeCallError && error.code === "NOT_READY") return;
|
|
529
|
+
dispatch(errorAction(error));
|
|
530
|
+
});
|
|
531
|
+
}, [kind]);
|
|
532
|
+
useEffect(() => {
|
|
533
|
+
const bridge = getExtensionBridge();
|
|
534
|
+
if (!bridge) return;
|
|
535
|
+
return bridge.onEvent((event) => {
|
|
536
|
+
const current = stateRef.current;
|
|
537
|
+
const ours = operationIdOf(current) === event.operationId && isOperationOpen(current);
|
|
538
|
+
if (ours && isResultEvent(kind, event) && receivedRef.current) {
|
|
539
|
+
stateRef.current = IDLE_OPERATION;
|
|
540
|
+
dispatch({ type: "reset" });
|
|
541
|
+
receivedRef.current(event.data);
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
dispatch({
|
|
545
|
+
type: "event",
|
|
546
|
+
event
|
|
547
|
+
});
|
|
548
|
+
if (ours && isReadyEvent(kind, event)) askHandOff(event.operationId);
|
|
549
|
+
});
|
|
550
|
+
}, [kind, askHandOff]);
|
|
551
|
+
useEffect(() => () => {
|
|
552
|
+
const open = stateRef.current;
|
|
553
|
+
const operationId = operationIdOf(open);
|
|
554
|
+
if (operationId && isOperationOpen(open)) getExtensionBridge()?.call("cancel", {
|
|
555
|
+
workspaceId: workspaceRef.current,
|
|
556
|
+
operationId
|
|
557
|
+
}).catch(() => void 0);
|
|
558
|
+
}, []);
|
|
559
|
+
return {
|
|
560
|
+
state,
|
|
561
|
+
start: useCallback((url) => {
|
|
562
|
+
const bridge = getExtensionBridge();
|
|
563
|
+
if (!bridge) {
|
|
564
|
+
dispatch({
|
|
565
|
+
type: "error",
|
|
566
|
+
code: "UNAVAILABLE",
|
|
567
|
+
message: "The browser extension cannot be reached from this page."
|
|
568
|
+
});
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
dispatch({ type: "start" });
|
|
572
|
+
bridge.call(START_OP[kind], {
|
|
573
|
+
workspaceId: workspaceRef.current,
|
|
574
|
+
url
|
|
575
|
+
}).then((result) => {
|
|
576
|
+
const operationId = typeof result.operationId === "string" ? result.operationId : null;
|
|
577
|
+
if (!operationId) {
|
|
578
|
+
dispatch({
|
|
579
|
+
type: "error",
|
|
580
|
+
code: "FAILED",
|
|
581
|
+
message: "The extension did not start."
|
|
582
|
+
});
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
dispatch({
|
|
586
|
+
type: "started",
|
|
587
|
+
operationId
|
|
588
|
+
});
|
|
589
|
+
}).catch((error) => dispatch(errorAction(error)));
|
|
590
|
+
}, [kind]),
|
|
591
|
+
askAgain: useCallback(() => {
|
|
592
|
+
const current = stateRef.current;
|
|
593
|
+
if (current.phase === "declined") askHandOff(current.operationId);
|
|
594
|
+
}, [askHandOff]),
|
|
595
|
+
cancel: useCallback(() => {
|
|
596
|
+
const current = stateRef.current;
|
|
597
|
+
const operationId = operationIdOf(current);
|
|
598
|
+
if (operationId && isOperationOpen(current)) getExtensionBridge()?.call("cancel", {
|
|
599
|
+
workspaceId: workspaceRef.current,
|
|
600
|
+
operationId
|
|
601
|
+
}).catch(() => void 0);
|
|
602
|
+
dispatch({ type: "cancelled" });
|
|
603
|
+
}, []),
|
|
604
|
+
reset: useCallback(() => dispatch({ type: "reset" }), [])
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
export { MIN_BRIDGE_EXTENSION_VERSION as a, isOperationOpen as i, useBridgeAvailability as n, PICK_CAPABILITIES as o, useBridgeOperation as r, canUseBridgeHere as t };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
|
|
4
|
+
// src/builder/components/hooks/use-mobile.tsx
|
|
5
|
+
/**
|
|
6
|
+
* Subscribe to a CSS media query.
|
|
7
|
+
*
|
|
8
|
+
* Returns `false` on the first render (before the effect runs) so server and
|
|
9
|
+
* hydration output stay stable; callers should treat `false` as "not yet
|
|
10
|
+
* known" and render the layout that degrades most gracefully.
|
|
11
|
+
*/
|
|
12
|
+
function useMediaQuery(query) {
|
|
13
|
+
const [matches, setMatches] = React.useState(false);
|
|
14
|
+
React.useEffect(() => {
|
|
15
|
+
const mql = window.matchMedia(query);
|
|
16
|
+
const onChange = (e) => setMatches(e.matches);
|
|
17
|
+
setMatches(mql.matches);
|
|
18
|
+
mql.addEventListener("change", onChange);
|
|
19
|
+
return () => mql.removeEventListener("change", onChange);
|
|
20
|
+
}, [query]);
|
|
21
|
+
return matches;
|
|
22
|
+
}
|
|
23
|
+
function useIsMobile() {
|
|
24
|
+
return useMediaQuery(`(max-width: 767px)`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { useMediaQuery as n, useIsMobile as t };
|