@intentcomputing/koko-agent-sdk 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/CODE_OF_CONDUCT.md +3 -0
- package/CONTRIBUTING.md +9 -0
- package/LICENSE +21 -0
- package/README.md +65 -0
- package/README.zh-CN.md +50 -0
- package/SECURITY.md +5 -0
- package/android/build.gradle +40 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/cn/intentcomputing/kokoagentsdk/KokoAgentSdkModule.java +1356 -0
- package/android/src/main/java/cn/intentcomputing/kokoagentsdk/KokoAgentSdkPackage.java +23 -0
- package/docs/INTEGRATION.md +168 -0
- package/docs/INTEGRATION.zh-CN.md +140 -0
- package/docs/PRIVACY.md +11 -0
- package/docs/PRIVACY.zh-CN.md +11 -0
- package/docs/PUBLISH.md +11 -0
- package/docs/PUBLISH.zh-CN.md +11 -0
- package/ios/KokoAgentSdk/KokoAgentSdk.h +5 -0
- package/ios/KokoAgentSdk/KokoAgentSdk.m +2464 -0
- package/ios/KokoAgentSdk/KokoOcrBounds.h +20 -0
- package/ios/KokoAgentSdk/KokoScrollBounds.h +21 -0
- package/koko-agent-sdk.podspec +23 -0
- package/lib/commonjs/KokoAgent.js +1427 -0
- package/lib/commonjs/KokoAgent.js.map +1 -0
- package/lib/commonjs/assist/OnDeviceAssist.js +94 -0
- package/lib/commonjs/assist/OnDeviceAssist.js.map +1 -0
- package/lib/commonjs/assist/intentClassify.js +100 -0
- package/lib/commonjs/assist/intentClassify.js.map +1 -0
- package/lib/commonjs/assist/nodeRank.js +120 -0
- package/lib/commonjs/assist/nodeRank.js.map +1 -0
- package/lib/commonjs/assist/ocrTarget.js +135 -0
- package/lib/commonjs/assist/ocrTarget.js.map +1 -0
- package/lib/commonjs/assist/webVisualChange.js +29 -0
- package/lib/commonjs/assist/webVisualChange.js.map +1 -0
- package/lib/commonjs/client/ActionOutcomeUnknownError.js +28 -0
- package/lib/commonjs/client/ActionOutcomeUnknownError.js.map +1 -0
- package/lib/commonjs/client/AgentSession.js +858 -0
- package/lib/commonjs/client/AgentSession.js.map +1 -0
- package/lib/commonjs/client/GatewayClient.js +302 -0
- package/lib/commonjs/client/GatewayClient.js.map +1 -0
- package/lib/commonjs/client/OperationReplayGuard.js +62 -0
- package/lib/commonjs/client/OperationReplayGuard.js.map +1 -0
- package/lib/commonjs/client/RunCheckpoint.js +139 -0
- package/lib/commonjs/client/RunCheckpoint.js.map +1 -0
- package/lib/commonjs/client/loopDetect.js +184 -0
- package/lib/commonjs/client/loopDetect.js.map +1 -0
- package/lib/commonjs/client/recentSearch.js +50 -0
- package/lib/commonjs/client/recentSearch.js.map +1 -0
- package/lib/commonjs/client/walletChoiceGuard.js +18 -0
- package/lib/commonjs/client/walletChoiceGuard.js.map +1 -0
- package/lib/commonjs/client/webResultCategory.js +38 -0
- package/lib/commonjs/client/webResultCategory.js.map +1 -0
- package/lib/commonjs/commercial/AccountStore.js +78 -0
- package/lib/commonjs/commercial/AccountStore.js.map +1 -0
- package/lib/commonjs/commercial/AgentDebug.js +104 -0
- package/lib/commonjs/commercial/AgentDebug.js.map +1 -0
- package/lib/commonjs/commercial/ExecutionGuard.js +53 -0
- package/lib/commonjs/commercial/ExecutionGuard.js.map +1 -0
- package/lib/commonjs/commercial/UsageBus.js +42 -0
- package/lib/commonjs/commercial/UsageBus.js.map +1 -0
- package/lib/commonjs/commercial/branding.js +69 -0
- package/lib/commonjs/commercial/branding.js.map +1 -0
- package/lib/commonjs/commercial/devMode.js +52 -0
- package/lib/commonjs/commercial/devMode.js.map +1 -0
- package/lib/commonjs/commercial/trust.js +69 -0
- package/lib/commonjs/commercial/trust.js.map +1 -0
- package/lib/commonjs/confirmation/gate.js +62 -0
- package/lib/commonjs/confirmation/gate.js.map +1 -0
- package/lib/commonjs/cursor/CursorOverlay.js +141 -0
- package/lib/commonjs/cursor/CursorOverlay.js.map +1 -0
- package/lib/commonjs/cursor/PointerHand.js +51 -0
- package/lib/commonjs/cursor/PointerHand.js.map +1 -0
- package/lib/commonjs/cursor/controller.js +91 -0
- package/lib/commonjs/cursor/controller.js.map +1 -0
- package/lib/commonjs/cursor/pointer.js +49 -0
- package/lib/commonjs/cursor/pointer.js.map +1 -0
- package/lib/commonjs/debug/KokoRemoteSmoke.js +611 -0
- package/lib/commonjs/debug/KokoRemoteSmoke.js.map +1 -0
- package/lib/commonjs/explore/ExplorationGraph.js +418 -0
- package/lib/commonjs/explore/ExplorationGraph.js.map +1 -0
- package/lib/commonjs/explore/bootstrapExplore.js +59 -0
- package/lib/commonjs/explore/bootstrapExplore.js.map +1 -0
- package/lib/commonjs/host/HostActions.js +266 -0
- package/lib/commonjs/host/HostActions.js.map +1 -0
- package/lib/commonjs/i18n/index.js +169 -0
- package/lib/commonjs/i18n/index.js.map +1 -0
- package/lib/commonjs/i18n/runtimeMessages.js +184 -0
- package/lib/commonjs/i18n/runtimeMessages.js.map +1 -0
- package/lib/commonjs/index.js +640 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/native/NativeBridge.js +132 -0
- package/lib/commonjs/native/NativeBridge.js.map +1 -0
- package/lib/commonjs/native/navigationLabel.js +16 -0
- package/lib/commonjs/native/navigationLabel.js.map +1 -0
- package/lib/commonjs/native/normalizeViewTree.js +28 -0
- package/lib/commonjs/native/normalizeViewTree.js.map +1 -0
- package/lib/commonjs/native/pruneOffscreen.js +76 -0
- package/lib/commonjs/native/pruneOffscreen.js.map +1 -0
- package/lib/commonjs/native/scrollViewport.js +69 -0
- package/lib/commonjs/native/scrollViewport.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/privacy/redact.js +108 -0
- package/lib/commonjs/privacy/redact.js.map +1 -0
- package/lib/commonjs/privacy/screenEvidence.js +59 -0
- package/lib/commonjs/privacy/screenEvidence.js.map +1 -0
- package/lib/commonjs/privacy/screenModel.js +404 -0
- package/lib/commonjs/privacy/screenModel.js.map +1 -0
- package/lib/commonjs/privacy/sensitiveScreen.js +58 -0
- package/lib/commonjs/privacy/sensitiveScreen.js.map +1 -0
- package/lib/commonjs/privacy/userGate.js +213 -0
- package/lib/commonjs/privacy/userGate.js.map +1 -0
- package/lib/commonjs/protocol/actions.js +112 -0
- package/lib/commonjs/protocol/actions.js.map +1 -0
- package/lib/commonjs/provider/HostAppearanceStore.js +111 -0
- package/lib/commonjs/provider/HostAppearanceStore.js.map +1 -0
- package/lib/commonjs/provider/KokoProvider.js +81 -0
- package/lib/commonjs/provider/KokoProvider.js.map +1 -0
- package/lib/commonjs/provider/KokoUiContext.js +102 -0
- package/lib/commonjs/provider/KokoUiContext.js.map +1 -0
- package/lib/commonjs/selector/match.js +378 -0
- package/lib/commonjs/selector/match.js.map +1 -0
- package/lib/commonjs/task/TaskStore.js +361 -0
- package/lib/commonjs/task/TaskStore.js.map +1 -0
- package/lib/commonjs/task/types.js +2 -0
- package/lib/commonjs/task/types.js.map +1 -0
- package/lib/commonjs/task/useTaskStore.js +14 -0
- package/lib/commonjs/task/useTaskStore.js.map +1 -0
- package/lib/commonjs/types.js +2 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/ui/KokoChatSheet.js +885 -0
- package/lib/commonjs/ui/KokoChatSheet.js.map +1 -0
- package/lib/commonjs/ui/KokoComposer.js +161 -0
- package/lib/commonjs/ui/KokoComposer.js.map +1 -0
- package/lib/commonjs/ui/KokoDialogHost.js +254 -0
- package/lib/commonjs/ui/KokoDialogHost.js.map +1 -0
- package/lib/commonjs/ui/KokoEntryButton.js +81 -0
- package/lib/commonjs/ui/KokoEntryButton.js.map +1 -0
- package/lib/commonjs/ui/KokoObserver.js +522 -0
- package/lib/commonjs/ui/KokoObserver.js.map +1 -0
- package/lib/commonjs/ui/KokoOverlayLayer.js +45 -0
- package/lib/commonjs/ui/KokoOverlayLayer.js.map +1 -0
- package/lib/commonjs/ui/KokoSubtitle.js +95 -0
- package/lib/commonjs/ui/KokoSubtitle.js.map +1 -0
- package/lib/commonjs/ui/KokoTaskPanel.js +322 -0
- package/lib/commonjs/ui/KokoTaskPanel.js.map +1 -0
- package/lib/commonjs/ui/hostOverlay.js +126 -0
- package/lib/commonjs/ui/hostOverlay.js.map +1 -0
- package/lib/commonjs/ui/icons.js +132 -0
- package/lib/commonjs/ui/icons.js.map +1 -0
- package/lib/commonjs/ui/progressChrome.js +66 -0
- package/lib/commonjs/ui/progressChrome.js.map +1 -0
- package/lib/commonjs/ui/safeArea.js +96 -0
- package/lib/commonjs/ui/safeArea.js.map +1 -0
- package/lib/commonjs/ui/useOverlayOrigin.js +40 -0
- package/lib/commonjs/ui/useOverlayOrigin.js.map +1 -0
- package/lib/module/KokoAgent.js +1418 -0
- package/lib/module/KokoAgent.js.map +1 -0
- package/lib/module/assist/OnDeviceAssist.js +89 -0
- package/lib/module/assist/OnDeviceAssist.js.map +1 -0
- package/lib/module/assist/intentClassify.js +95 -0
- package/lib/module/assist/intentClassify.js.map +1 -0
- package/lib/module/assist/nodeRank.js +115 -0
- package/lib/module/assist/nodeRank.js.map +1 -0
- package/lib/module/assist/ocrTarget.js +123 -0
- package/lib/module/assist/ocrTarget.js.map +1 -0
- package/lib/module/assist/webVisualChange.js +24 -0
- package/lib/module/assist/webVisualChange.js.map +1 -0
- package/lib/module/client/ActionOutcomeUnknownError.js +23 -0
- package/lib/module/client/ActionOutcomeUnknownError.js.map +1 -0
- package/lib/module/client/AgentSession.js +854 -0
- package/lib/module/client/AgentSession.js.map +1 -0
- package/lib/module/client/GatewayClient.js +293 -0
- package/lib/module/client/GatewayClient.js.map +1 -0
- package/lib/module/client/OperationReplayGuard.js +58 -0
- package/lib/module/client/OperationReplayGuard.js.map +1 -0
- package/lib/module/client/RunCheckpoint.js +135 -0
- package/lib/module/client/RunCheckpoint.js.map +1 -0
- package/lib/module/client/loopDetect.js +177 -0
- package/lib/module/client/loopDetect.js.map +1 -0
- package/lib/module/client/recentSearch.js +46 -0
- package/lib/module/client/recentSearch.js.map +1 -0
- package/lib/module/client/walletChoiceGuard.js +14 -0
- package/lib/module/client/walletChoiceGuard.js.map +1 -0
- package/lib/module/client/webResultCategory.js +34 -0
- package/lib/module/client/webResultCategory.js.map +1 -0
- package/lib/module/commercial/AccountStore.js +75 -0
- package/lib/module/commercial/AccountStore.js.map +1 -0
- package/lib/module/commercial/AgentDebug.js +99 -0
- package/lib/module/commercial/AgentDebug.js.map +1 -0
- package/lib/module/commercial/ExecutionGuard.js +49 -0
- package/lib/module/commercial/ExecutionGuard.js.map +1 -0
- package/lib/module/commercial/UsageBus.js +38 -0
- package/lib/module/commercial/UsageBus.js.map +1 -0
- package/lib/module/commercial/branding.js +63 -0
- package/lib/module/commercial/branding.js.map +1 -0
- package/lib/module/commercial/devMode.js +45 -0
- package/lib/module/commercial/devMode.js.map +1 -0
- package/lib/module/commercial/trust.js +62 -0
- package/lib/module/commercial/trust.js.map +1 -0
- package/lib/module/confirmation/gate.js +54 -0
- package/lib/module/confirmation/gate.js.map +1 -0
- package/lib/module/cursor/CursorOverlay.js +136 -0
- package/lib/module/cursor/CursorOverlay.js.map +1 -0
- package/lib/module/cursor/PointerHand.js +47 -0
- package/lib/module/cursor/PointerHand.js.map +1 -0
- package/lib/module/cursor/controller.js +87 -0
- package/lib/module/cursor/controller.js.map +1 -0
- package/lib/module/cursor/pointer.js +45 -0
- package/lib/module/cursor/pointer.js.map +1 -0
- package/lib/module/debug/KokoRemoteSmoke.js +608 -0
- package/lib/module/debug/KokoRemoteSmoke.js.map +1 -0
- package/lib/module/explore/ExplorationGraph.js +406 -0
- package/lib/module/explore/ExplorationGraph.js.map +1 -0
- package/lib/module/explore/bootstrapExplore.js +55 -0
- package/lib/module/explore/bootstrapExplore.js.map +1 -0
- package/lib/module/host/HostActions.js +255 -0
- package/lib/module/host/HostActions.js.map +1 -0
- package/lib/module/i18n/index.js +159 -0
- package/lib/module/i18n/index.js.map +1 -0
- package/lib/module/i18n/runtimeMessages.js +180 -0
- package/lib/module/i18n/runtimeMessages.js.map +1 -0
- package/lib/module/index.js +44 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/native/NativeBridge.js +128 -0
- package/lib/module/native/NativeBridge.js.map +1 -0
- package/lib/module/native/navigationLabel.js +12 -0
- package/lib/module/native/navigationLabel.js.map +1 -0
- package/lib/module/native/normalizeViewTree.js +25 -0
- package/lib/module/native/normalizeViewTree.js.map +1 -0
- package/lib/module/native/pruneOffscreen.js +72 -0
- package/lib/module/native/pruneOffscreen.js.map +1 -0
- package/lib/module/native/scrollViewport.js +63 -0
- package/lib/module/native/scrollViewport.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/privacy/redact.js +103 -0
- package/lib/module/privacy/redact.js.map +1 -0
- package/lib/module/privacy/screenEvidence.js +50 -0
- package/lib/module/privacy/screenEvidence.js.map +1 -0
- package/lib/module/privacy/screenModel.js +397 -0
- package/lib/module/privacy/screenModel.js.map +1 -0
- package/lib/module/privacy/sensitiveScreen.js +52 -0
- package/lib/module/privacy/sensitiveScreen.js.map +1 -0
- package/lib/module/privacy/userGate.js +202 -0
- package/lib/module/privacy/userGate.js.map +1 -0
- package/lib/module/protocol/actions.js +108 -0
- package/lib/module/protocol/actions.js.map +1 -0
- package/lib/module/provider/HostAppearanceStore.js +101 -0
- package/lib/module/provider/HostAppearanceStore.js.map +1 -0
- package/lib/module/provider/KokoProvider.js +74 -0
- package/lib/module/provider/KokoProvider.js.map +1 -0
- package/lib/module/provider/KokoUiContext.js +96 -0
- package/lib/module/provider/KokoUiContext.js.map +1 -0
- package/lib/module/selector/match.js +366 -0
- package/lib/module/selector/match.js.map +1 -0
- package/lib/module/task/TaskStore.js +356 -0
- package/lib/module/task/TaskStore.js.map +1 -0
- package/lib/module/task/types.js +2 -0
- package/lib/module/task/types.js.map +1 -0
- package/lib/module/task/useTaskStore.js +10 -0
- package/lib/module/task/useTaskStore.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/ui/KokoChatSheet.js +879 -0
- package/lib/module/ui/KokoChatSheet.js.map +1 -0
- package/lib/module/ui/KokoComposer.js +155 -0
- package/lib/module/ui/KokoComposer.js.map +1 -0
- package/lib/module/ui/KokoDialogHost.js +247 -0
- package/lib/module/ui/KokoDialogHost.js.map +1 -0
- package/lib/module/ui/KokoEntryButton.js +74 -0
- package/lib/module/ui/KokoEntryButton.js.map +1 -0
- package/lib/module/ui/KokoObserver.js +516 -0
- package/lib/module/ui/KokoObserver.js.map +1 -0
- package/lib/module/ui/KokoOverlayLayer.js +39 -0
- package/lib/module/ui/KokoOverlayLayer.js.map +1 -0
- package/lib/module/ui/KokoSubtitle.js +90 -0
- package/lib/module/ui/KokoSubtitle.js.map +1 -0
- package/lib/module/ui/KokoTaskPanel.js +316 -0
- package/lib/module/ui/KokoTaskPanel.js.map +1 -0
- package/lib/module/ui/hostOverlay.js +120 -0
- package/lib/module/ui/hostOverlay.js.map +1 -0
- package/lib/module/ui/icons.js +124 -0
- package/lib/module/ui/icons.js.map +1 -0
- package/lib/module/ui/progressChrome.js +58 -0
- package/lib/module/ui/progressChrome.js.map +1 -0
- package/lib/module/ui/safeArea.js +92 -0
- package/lib/module/ui/safeArea.js.map +1 -0
- package/lib/module/ui/useOverlayOrigin.js +36 -0
- package/lib/module/ui/useOverlayOrigin.js.map +1 -0
- package/lib/typescript/commonjs/KokoAgent.d.ts +167 -0
- package/lib/typescript/commonjs/KokoAgent.d.ts.map +1 -0
- package/lib/typescript/commonjs/assist/OnDeviceAssist.d.ts +31 -0
- package/lib/typescript/commonjs/assist/OnDeviceAssist.d.ts.map +1 -0
- package/lib/typescript/commonjs/assist/intentClassify.d.ts +18 -0
- package/lib/typescript/commonjs/assist/intentClassify.d.ts.map +1 -0
- package/lib/typescript/commonjs/assist/nodeRank.d.ts +32 -0
- package/lib/typescript/commonjs/assist/nodeRank.d.ts.map +1 -0
- package/lib/typescript/commonjs/assist/ocrTarget.d.ts +25 -0
- package/lib/typescript/commonjs/assist/ocrTarget.d.ts.map +1 -0
- package/lib/typescript/commonjs/assist/webVisualChange.d.ts +6 -0
- package/lib/typescript/commonjs/assist/webVisualChange.d.ts.map +1 -0
- package/lib/typescript/commonjs/client/ActionOutcomeUnknownError.d.ts +13 -0
- package/lib/typescript/commonjs/client/ActionOutcomeUnknownError.d.ts.map +1 -0
- package/lib/typescript/commonjs/client/AgentSession.d.ts +56 -0
- package/lib/typescript/commonjs/client/AgentSession.d.ts.map +1 -0
- package/lib/typescript/commonjs/client/GatewayClient.d.ts +149 -0
- package/lib/typescript/commonjs/client/GatewayClient.d.ts.map +1 -0
- package/lib/typescript/commonjs/client/OperationReplayGuard.d.ts +13 -0
- package/lib/typescript/commonjs/client/OperationReplayGuard.d.ts.map +1 -0
- package/lib/typescript/commonjs/client/RunCheckpoint.d.ts +57 -0
- package/lib/typescript/commonjs/client/RunCheckpoint.d.ts.map +1 -0
- package/lib/typescript/commonjs/client/loopDetect.d.ts +15 -0
- package/lib/typescript/commonjs/client/loopDetect.d.ts.map +1 -0
- package/lib/typescript/commonjs/client/recentSearch.d.ts +5 -0
- package/lib/typescript/commonjs/client/recentSearch.d.ts.map +1 -0
- package/lib/typescript/commonjs/client/walletChoiceGuard.d.ts +4 -0
- package/lib/typescript/commonjs/client/walletChoiceGuard.d.ts.map +1 -0
- package/lib/typescript/commonjs/client/webResultCategory.d.ts +5 -0
- package/lib/typescript/commonjs/client/webResultCategory.d.ts.map +1 -0
- package/lib/typescript/commonjs/commercial/AccountStore.d.ts +17 -0
- package/lib/typescript/commonjs/commercial/AccountStore.d.ts.map +1 -0
- package/lib/typescript/commonjs/commercial/AgentDebug.d.ts +25 -0
- package/lib/typescript/commonjs/commercial/AgentDebug.d.ts.map +1 -0
- package/lib/typescript/commonjs/commercial/ExecutionGuard.d.ts +18 -0
- package/lib/typescript/commonjs/commercial/ExecutionGuard.d.ts.map +1 -0
- package/lib/typescript/commonjs/commercial/UsageBus.d.ts +18 -0
- package/lib/typescript/commonjs/commercial/UsageBus.d.ts.map +1 -0
- package/lib/typescript/commonjs/commercial/branding.d.ts +25 -0
- package/lib/typescript/commonjs/commercial/branding.d.ts.map +1 -0
- package/lib/typescript/commonjs/commercial/devMode.d.ts +26 -0
- package/lib/typescript/commonjs/commercial/devMode.d.ts.map +1 -0
- package/lib/typescript/commonjs/commercial/trust.d.ts +21 -0
- package/lib/typescript/commonjs/commercial/trust.d.ts.map +1 -0
- package/lib/typescript/commonjs/confirmation/gate.d.ts +18 -0
- package/lib/typescript/commonjs/confirmation/gate.d.ts.map +1 -0
- package/lib/typescript/commonjs/cursor/CursorOverlay.d.ts +13 -0
- package/lib/typescript/commonjs/cursor/CursorOverlay.d.ts.map +1 -0
- package/lib/typescript/commonjs/cursor/PointerHand.d.ts +16 -0
- package/lib/typescript/commonjs/cursor/PointerHand.d.ts.map +1 -0
- package/lib/typescript/commonjs/cursor/controller.d.ts +30 -0
- package/lib/typescript/commonjs/cursor/controller.d.ts.map +1 -0
- package/lib/typescript/commonjs/cursor/pointer.d.ts +23 -0
- package/lib/typescript/commonjs/cursor/pointer.d.ts.map +1 -0
- package/lib/typescript/commonjs/debug/KokoRemoteSmoke.d.ts +96 -0
- package/lib/typescript/commonjs/debug/KokoRemoteSmoke.d.ts.map +1 -0
- package/lib/typescript/commonjs/explore/ExplorationGraph.d.ts +96 -0
- package/lib/typescript/commonjs/explore/ExplorationGraph.d.ts.map +1 -0
- package/lib/typescript/commonjs/explore/bootstrapExplore.d.ts +40 -0
- package/lib/typescript/commonjs/explore/bootstrapExplore.d.ts.map +1 -0
- package/lib/typescript/commonjs/host/HostActions.d.ts +101 -0
- package/lib/typescript/commonjs/host/HostActions.d.ts.map +1 -0
- package/lib/typescript/commonjs/i18n/index.d.ts +20 -0
- package/lib/typescript/commonjs/i18n/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/i18n/runtimeMessages.d.ts +178 -0
- package/lib/typescript/commonjs/i18n/runtimeMessages.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +66 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/native/NativeBridge.d.ts +70 -0
- package/lib/typescript/commonjs/native/NativeBridge.d.ts.map +1 -0
- package/lib/typescript/commonjs/native/navigationLabel.d.ts +4 -0
- package/lib/typescript/commonjs/native/navigationLabel.d.ts.map +1 -0
- package/lib/typescript/commonjs/native/normalizeViewTree.d.ts +4 -0
- package/lib/typescript/commonjs/native/normalizeViewTree.d.ts.map +1 -0
- package/lib/typescript/commonjs/native/pruneOffscreen.d.ts +3 -0
- package/lib/typescript/commonjs/native/pruneOffscreen.d.ts.map +1 -0
- package/lib/typescript/commonjs/native/scrollViewport.d.ts +13 -0
- package/lib/typescript/commonjs/native/scrollViewport.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/privacy/redact.d.ts +9 -0
- package/lib/typescript/commonjs/privacy/redact.d.ts.map +1 -0
- package/lib/typescript/commonjs/privacy/screenEvidence.d.ts +14 -0
- package/lib/typescript/commonjs/privacy/screenEvidence.d.ts.map +1 -0
- package/lib/typescript/commonjs/privacy/screenModel.d.ts +26 -0
- package/lib/typescript/commonjs/privacy/screenModel.d.ts.map +1 -0
- package/lib/typescript/commonjs/privacy/sensitiveScreen.d.ts +8 -0
- package/lib/typescript/commonjs/privacy/sensitiveScreen.d.ts.map +1 -0
- package/lib/typescript/commonjs/privacy/userGate.d.ts +58 -0
- package/lib/typescript/commonjs/privacy/userGate.d.ts.map +1 -0
- package/lib/typescript/commonjs/protocol/actions.d.ts +7 -0
- package/lib/typescript/commonjs/protocol/actions.d.ts.map +1 -0
- package/lib/typescript/commonjs/provider/HostAppearanceStore.d.ts +64 -0
- package/lib/typescript/commonjs/provider/HostAppearanceStore.d.ts.map +1 -0
- package/lib/typescript/commonjs/provider/KokoProvider.d.ts +39 -0
- package/lib/typescript/commonjs/provider/KokoProvider.d.ts.map +1 -0
- package/lib/typescript/commonjs/provider/KokoUiContext.d.ts +22 -0
- package/lib/typescript/commonjs/provider/KokoUiContext.d.ts.map +1 -0
- package/lib/typescript/commonjs/selector/match.d.ts +27 -0
- package/lib/typescript/commonjs/selector/match.d.ts.map +1 -0
- package/lib/typescript/commonjs/task/TaskStore.d.ts +65 -0
- package/lib/typescript/commonjs/task/TaskStore.d.ts.map +1 -0
- package/lib/typescript/commonjs/task/types.d.ts +66 -0
- package/lib/typescript/commonjs/task/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/task/useTaskStore.d.ts +3 -0
- package/lib/typescript/commonjs/task/useTaskStore.d.ts.map +1 -0
- package/lib/typescript/commonjs/types.d.ts +372 -0
- package/lib/typescript/commonjs/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/KokoChatSheet.d.ts +8 -0
- package/lib/typescript/commonjs/ui/KokoChatSheet.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/KokoComposer.d.ts +13 -0
- package/lib/typescript/commonjs/ui/KokoComposer.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/KokoDialogHost.d.ts +32 -0
- package/lib/typescript/commonjs/ui/KokoDialogHost.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/KokoEntryButton.d.ts +18 -0
- package/lib/typescript/commonjs/ui/KokoEntryButton.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/KokoObserver.d.ts +13 -0
- package/lib/typescript/commonjs/ui/KokoObserver.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/KokoOverlayLayer.d.ts +35 -0
- package/lib/typescript/commonjs/ui/KokoOverlayLayer.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/KokoSubtitle.d.ts +7 -0
- package/lib/typescript/commonjs/ui/KokoSubtitle.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/KokoTaskPanel.d.ts +7 -0
- package/lib/typescript/commonjs/ui/KokoTaskPanel.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/hostOverlay.d.ts +28 -0
- package/lib/typescript/commonjs/ui/hostOverlay.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/icons.d.ts +26 -0
- package/lib/typescript/commonjs/ui/icons.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/progressChrome.d.ts +21 -0
- package/lib/typescript/commonjs/ui/progressChrome.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/safeArea.d.ts +12 -0
- package/lib/typescript/commonjs/ui/safeArea.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/useOverlayOrigin.d.ts +22 -0
- package/lib/typescript/commonjs/ui/useOverlayOrigin.d.ts.map +1 -0
- package/lib/typescript/module/KokoAgent.d.ts +167 -0
- package/lib/typescript/module/KokoAgent.d.ts.map +1 -0
- package/lib/typescript/module/assist/OnDeviceAssist.d.ts +31 -0
- package/lib/typescript/module/assist/OnDeviceAssist.d.ts.map +1 -0
- package/lib/typescript/module/assist/intentClassify.d.ts +18 -0
- package/lib/typescript/module/assist/intentClassify.d.ts.map +1 -0
- package/lib/typescript/module/assist/nodeRank.d.ts +32 -0
- package/lib/typescript/module/assist/nodeRank.d.ts.map +1 -0
- package/lib/typescript/module/assist/ocrTarget.d.ts +25 -0
- package/lib/typescript/module/assist/ocrTarget.d.ts.map +1 -0
- package/lib/typescript/module/assist/webVisualChange.d.ts +6 -0
- package/lib/typescript/module/assist/webVisualChange.d.ts.map +1 -0
- package/lib/typescript/module/client/ActionOutcomeUnknownError.d.ts +13 -0
- package/lib/typescript/module/client/ActionOutcomeUnknownError.d.ts.map +1 -0
- package/lib/typescript/module/client/AgentSession.d.ts +56 -0
- package/lib/typescript/module/client/AgentSession.d.ts.map +1 -0
- package/lib/typescript/module/client/GatewayClient.d.ts +149 -0
- package/lib/typescript/module/client/GatewayClient.d.ts.map +1 -0
- package/lib/typescript/module/client/OperationReplayGuard.d.ts +13 -0
- package/lib/typescript/module/client/OperationReplayGuard.d.ts.map +1 -0
- package/lib/typescript/module/client/RunCheckpoint.d.ts +57 -0
- package/lib/typescript/module/client/RunCheckpoint.d.ts.map +1 -0
- package/lib/typescript/module/client/loopDetect.d.ts +15 -0
- package/lib/typescript/module/client/loopDetect.d.ts.map +1 -0
- package/lib/typescript/module/client/recentSearch.d.ts +5 -0
- package/lib/typescript/module/client/recentSearch.d.ts.map +1 -0
- package/lib/typescript/module/client/walletChoiceGuard.d.ts +4 -0
- package/lib/typescript/module/client/walletChoiceGuard.d.ts.map +1 -0
- package/lib/typescript/module/client/webResultCategory.d.ts +5 -0
- package/lib/typescript/module/client/webResultCategory.d.ts.map +1 -0
- package/lib/typescript/module/commercial/AccountStore.d.ts +17 -0
- package/lib/typescript/module/commercial/AccountStore.d.ts.map +1 -0
- package/lib/typescript/module/commercial/AgentDebug.d.ts +25 -0
- package/lib/typescript/module/commercial/AgentDebug.d.ts.map +1 -0
- package/lib/typescript/module/commercial/ExecutionGuard.d.ts +18 -0
- package/lib/typescript/module/commercial/ExecutionGuard.d.ts.map +1 -0
- package/lib/typescript/module/commercial/UsageBus.d.ts +18 -0
- package/lib/typescript/module/commercial/UsageBus.d.ts.map +1 -0
- package/lib/typescript/module/commercial/branding.d.ts +25 -0
- package/lib/typescript/module/commercial/branding.d.ts.map +1 -0
- package/lib/typescript/module/commercial/devMode.d.ts +26 -0
- package/lib/typescript/module/commercial/devMode.d.ts.map +1 -0
- package/lib/typescript/module/commercial/trust.d.ts +21 -0
- package/lib/typescript/module/commercial/trust.d.ts.map +1 -0
- package/lib/typescript/module/confirmation/gate.d.ts +18 -0
- package/lib/typescript/module/confirmation/gate.d.ts.map +1 -0
- package/lib/typescript/module/cursor/CursorOverlay.d.ts +13 -0
- package/lib/typescript/module/cursor/CursorOverlay.d.ts.map +1 -0
- package/lib/typescript/module/cursor/PointerHand.d.ts +16 -0
- package/lib/typescript/module/cursor/PointerHand.d.ts.map +1 -0
- package/lib/typescript/module/cursor/controller.d.ts +30 -0
- package/lib/typescript/module/cursor/controller.d.ts.map +1 -0
- package/lib/typescript/module/cursor/pointer.d.ts +23 -0
- package/lib/typescript/module/cursor/pointer.d.ts.map +1 -0
- package/lib/typescript/module/debug/KokoRemoteSmoke.d.ts +96 -0
- package/lib/typescript/module/debug/KokoRemoteSmoke.d.ts.map +1 -0
- package/lib/typescript/module/explore/ExplorationGraph.d.ts +96 -0
- package/lib/typescript/module/explore/ExplorationGraph.d.ts.map +1 -0
- package/lib/typescript/module/explore/bootstrapExplore.d.ts +40 -0
- package/lib/typescript/module/explore/bootstrapExplore.d.ts.map +1 -0
- package/lib/typescript/module/host/HostActions.d.ts +101 -0
- package/lib/typescript/module/host/HostActions.d.ts.map +1 -0
- package/lib/typescript/module/i18n/index.d.ts +20 -0
- package/lib/typescript/module/i18n/index.d.ts.map +1 -0
- package/lib/typescript/module/i18n/runtimeMessages.d.ts +178 -0
- package/lib/typescript/module/i18n/runtimeMessages.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +66 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/native/NativeBridge.d.ts +70 -0
- package/lib/typescript/module/native/NativeBridge.d.ts.map +1 -0
- package/lib/typescript/module/native/navigationLabel.d.ts +4 -0
- package/lib/typescript/module/native/navigationLabel.d.ts.map +1 -0
- package/lib/typescript/module/native/normalizeViewTree.d.ts +4 -0
- package/lib/typescript/module/native/normalizeViewTree.d.ts.map +1 -0
- package/lib/typescript/module/native/pruneOffscreen.d.ts +3 -0
- package/lib/typescript/module/native/pruneOffscreen.d.ts.map +1 -0
- package/lib/typescript/module/native/scrollViewport.d.ts +13 -0
- package/lib/typescript/module/native/scrollViewport.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/privacy/redact.d.ts +9 -0
- package/lib/typescript/module/privacy/redact.d.ts.map +1 -0
- package/lib/typescript/module/privacy/screenEvidence.d.ts +14 -0
- package/lib/typescript/module/privacy/screenEvidence.d.ts.map +1 -0
- package/lib/typescript/module/privacy/screenModel.d.ts +26 -0
- package/lib/typescript/module/privacy/screenModel.d.ts.map +1 -0
- package/lib/typescript/module/privacy/sensitiveScreen.d.ts +8 -0
- package/lib/typescript/module/privacy/sensitiveScreen.d.ts.map +1 -0
- package/lib/typescript/module/privacy/userGate.d.ts +58 -0
- package/lib/typescript/module/privacy/userGate.d.ts.map +1 -0
- package/lib/typescript/module/protocol/actions.d.ts +7 -0
- package/lib/typescript/module/protocol/actions.d.ts.map +1 -0
- package/lib/typescript/module/provider/HostAppearanceStore.d.ts +64 -0
- package/lib/typescript/module/provider/HostAppearanceStore.d.ts.map +1 -0
- package/lib/typescript/module/provider/KokoProvider.d.ts +39 -0
- package/lib/typescript/module/provider/KokoProvider.d.ts.map +1 -0
- package/lib/typescript/module/provider/KokoUiContext.d.ts +22 -0
- package/lib/typescript/module/provider/KokoUiContext.d.ts.map +1 -0
- package/lib/typescript/module/selector/match.d.ts +27 -0
- package/lib/typescript/module/selector/match.d.ts.map +1 -0
- package/lib/typescript/module/task/TaskStore.d.ts +65 -0
- package/lib/typescript/module/task/TaskStore.d.ts.map +1 -0
- package/lib/typescript/module/task/types.d.ts +66 -0
- package/lib/typescript/module/task/types.d.ts.map +1 -0
- package/lib/typescript/module/task/useTaskStore.d.ts +3 -0
- package/lib/typescript/module/task/useTaskStore.d.ts.map +1 -0
- package/lib/typescript/module/types.d.ts +372 -0
- package/lib/typescript/module/types.d.ts.map +1 -0
- package/lib/typescript/module/ui/KokoChatSheet.d.ts +8 -0
- package/lib/typescript/module/ui/KokoChatSheet.d.ts.map +1 -0
- package/lib/typescript/module/ui/KokoComposer.d.ts +13 -0
- package/lib/typescript/module/ui/KokoComposer.d.ts.map +1 -0
- package/lib/typescript/module/ui/KokoDialogHost.d.ts +32 -0
- package/lib/typescript/module/ui/KokoDialogHost.d.ts.map +1 -0
- package/lib/typescript/module/ui/KokoEntryButton.d.ts +18 -0
- package/lib/typescript/module/ui/KokoEntryButton.d.ts.map +1 -0
- package/lib/typescript/module/ui/KokoObserver.d.ts +13 -0
- package/lib/typescript/module/ui/KokoObserver.d.ts.map +1 -0
- package/lib/typescript/module/ui/KokoOverlayLayer.d.ts +35 -0
- package/lib/typescript/module/ui/KokoOverlayLayer.d.ts.map +1 -0
- package/lib/typescript/module/ui/KokoSubtitle.d.ts +7 -0
- package/lib/typescript/module/ui/KokoSubtitle.d.ts.map +1 -0
- package/lib/typescript/module/ui/KokoTaskPanel.d.ts +7 -0
- package/lib/typescript/module/ui/KokoTaskPanel.d.ts.map +1 -0
- package/lib/typescript/module/ui/hostOverlay.d.ts +28 -0
- package/lib/typescript/module/ui/hostOverlay.d.ts.map +1 -0
- package/lib/typescript/module/ui/icons.d.ts +26 -0
- package/lib/typescript/module/ui/icons.d.ts.map +1 -0
- package/lib/typescript/module/ui/progressChrome.d.ts +21 -0
- package/lib/typescript/module/ui/progressChrome.d.ts.map +1 -0
- package/lib/typescript/module/ui/safeArea.d.ts +12 -0
- package/lib/typescript/module/ui/safeArea.d.ts.map +1 -0
- package/lib/typescript/module/ui/useOverlayOrigin.d.ts +22 -0
- package/lib/typescript/module/ui/useOverlayOrigin.d.ts.map +1 -0
- package/package.json +153 -0
- package/react-native.config.js +12 -0
- package/src/KokoAgent.ts +1415 -0
- package/src/assist/OnDeviceAssist.ts +133 -0
- package/src/assist/intentClassify.ts +122 -0
- package/src/assist/nodeRank.ts +167 -0
- package/src/assist/ocrTarget.ts +146 -0
- package/src/assist/webVisualChange.ts +24 -0
- package/src/client/ActionOutcomeUnknownError.ts +18 -0
- package/src/client/AgentSession.ts +952 -0
- package/src/client/GatewayClient.ts +439 -0
- package/src/client/OperationReplayGuard.ts +61 -0
- package/src/client/RunCheckpoint.ts +154 -0
- package/src/client/loopDetect.ts +213 -0
- package/src/client/recentSearch.ts +47 -0
- package/src/client/walletChoiceGuard.ts +15 -0
- package/src/client/webResultCategory.ts +28 -0
- package/src/commercial/AccountStore.ts +85 -0
- package/src/commercial/AgentDebug.ts +142 -0
- package/src/commercial/ExecutionGuard.ts +67 -0
- package/src/commercial/UsageBus.ts +44 -0
- package/src/commercial/branding.ts +97 -0
- package/src/commercial/devMode.ts +48 -0
- package/src/commercial/trust.ts +67 -0
- package/src/confirmation/gate.ts +82 -0
- package/src/cursor/CursorOverlay.tsx +138 -0
- package/src/cursor/PointerHand.tsx +49 -0
- package/src/cursor/controller.ts +98 -0
- package/src/cursor/pointer.ts +40 -0
- package/src/debug/KokoRemoteSmoke.tsx +561 -0
- package/src/explore/ExplorationGraph.ts +518 -0
- package/src/explore/bootstrapExplore.ts +89 -0
- package/src/host/HostActions.ts +349 -0
- package/src/i18n/index.ts +229 -0
- package/src/i18n/runtimeMessages.ts +180 -0
- package/src/index.ts +203 -0
- package/src/native/NativeBridge.ts +207 -0
- package/src/native/navigationLabel.ts +11 -0
- package/src/native/normalizeViewTree.ts +16 -0
- package/src/native/pruneOffscreen.ts +72 -0
- package/src/native/scrollViewport.ts +51 -0
- package/src/privacy/redact.ts +115 -0
- package/src/privacy/screenEvidence.ts +55 -0
- package/src/privacy/screenModel.ts +504 -0
- package/src/privacy/sensitiveScreen.ts +55 -0
- package/src/privacy/userGate.ts +233 -0
- package/src/protocol/actions.ts +66 -0
- package/src/provider/HostAppearanceStore.ts +148 -0
- package/src/provider/KokoProvider.tsx +118 -0
- package/src/provider/KokoUiContext.tsx +162 -0
- package/src/selector/match.ts +417 -0
- package/src/task/TaskStore.ts +387 -0
- package/src/task/types.ts +82 -0
- package/src/task/useTaskStore.ts +9 -0
- package/src/types.ts +318 -0
- package/src/ui/KokoChatSheet.tsx +930 -0
- package/src/ui/KokoComposer.tsx +174 -0
- package/src/ui/KokoDialogHost.tsx +249 -0
- package/src/ui/KokoEntryButton.tsx +74 -0
- package/src/ui/KokoObserver.tsx +587 -0
- package/src/ui/KokoOverlayLayer.tsx +53 -0
- package/src/ui/KokoSubtitle.tsx +80 -0
- package/src/ui/KokoTaskPanel.tsx +299 -0
- package/src/ui/hostOverlay.tsx +148 -0
- package/src/ui/icons.tsx +145 -0
- package/src/ui/progressChrome.ts +73 -0
- package/src/ui/safeArea.ts +95 -0
- package/src/ui/useOverlayOrigin.ts +29 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
createContext,
|
|
3
|
+
useContext,
|
|
4
|
+
useEffect,
|
|
5
|
+
useMemo,
|
|
6
|
+
useRef,
|
|
7
|
+
type ReactNode,
|
|
8
|
+
} from 'react';
|
|
9
|
+
import { useSyncExternalStore } from 'react';
|
|
10
|
+
import type {
|
|
11
|
+
KokoAccountSnapshot,
|
|
12
|
+
KokoAgentConfig,
|
|
13
|
+
KokoBrandingConfig,
|
|
14
|
+
KokoLocale,
|
|
15
|
+
KokoTheme,
|
|
16
|
+
} from '../types';
|
|
17
|
+
import { AccountStore } from '../commercial/AccountStore';
|
|
18
|
+
import {
|
|
19
|
+
resolveBranding,
|
|
20
|
+
type ResolvedBranding,
|
|
21
|
+
} from '../commercial/branding';
|
|
22
|
+
import { UsageBus } from '../commercial/UsageBus';
|
|
23
|
+
import { normalizeLocale, t, type MessageKey } from '../i18n';
|
|
24
|
+
import {
|
|
25
|
+
HostAppearanceStore,
|
|
26
|
+
invertTheme,
|
|
27
|
+
resolveThemeColors,
|
|
28
|
+
type KokoThemeColors,
|
|
29
|
+
} from './HostAppearanceStore';
|
|
30
|
+
|
|
31
|
+
export type KokoUiContextValue = {
|
|
32
|
+
locale: KokoLocale;
|
|
33
|
+
/** Theme Koko chrome paints in — the inverse of `appTheme`. */
|
|
34
|
+
theme: KokoTheme;
|
|
35
|
+
/** What the host App itself is running, as reported by the host. */
|
|
36
|
+
appTheme: KokoTheme;
|
|
37
|
+
colors: KokoThemeColors;
|
|
38
|
+
branding: ResolvedBranding;
|
|
39
|
+
account: KokoAccountSnapshot | null;
|
|
40
|
+
t: (key: MessageKey, vars?: Record<string, string | number>) => string;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const KokoUiContext = createContext<KokoUiContextValue | null>(null);
|
|
44
|
+
|
|
45
|
+
function subscribeAccount(cb: () => void) {
|
|
46
|
+
return AccountStore.subscribe(() => cb());
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function getAccountSnapshot() {
|
|
50
|
+
return AccountStore.get();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function subscribeAppearance(cb: () => void) {
|
|
54
|
+
return HostAppearanceStore.subscribe(cb);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function getAppearanceSnapshot() {
|
|
58
|
+
return HostAppearanceStore.get();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function KokoUiProvider({
|
|
62
|
+
config,
|
|
63
|
+
children,
|
|
64
|
+
}: {
|
|
65
|
+
config?: KokoAgentConfig;
|
|
66
|
+
children: ReactNode;
|
|
67
|
+
}) {
|
|
68
|
+
const appearance = useSyncExternalStore(
|
|
69
|
+
subscribeAppearance,
|
|
70
|
+
getAppearanceSnapshot,
|
|
71
|
+
getAppearanceSnapshot,
|
|
72
|
+
);
|
|
73
|
+
const locale = normalizeLocale(appearance.locale ?? config?.locale);
|
|
74
|
+
// `theme` names the host App's theme; chrome takes the other one so it stays
|
|
75
|
+
// readable against the App behind it. Absent a report, assume a light App —
|
|
76
|
+
// that keeps chrome dark, as it has always been.
|
|
77
|
+
const appTheme: KokoTheme = appearance.theme ?? config?.theme ?? 'light';
|
|
78
|
+
const theme = invertTheme(appTheme);
|
|
79
|
+
const colors = useMemo(() => resolveThemeColors(theme), [theme]);
|
|
80
|
+
const account = useSyncExternalStore(
|
|
81
|
+
subscribeAccount,
|
|
82
|
+
getAccountSnapshot,
|
|
83
|
+
getAccountSnapshot,
|
|
84
|
+
);
|
|
85
|
+
const downgradeEmitted = useRef(false);
|
|
86
|
+
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
const unsub = config?.onUsageEvent
|
|
89
|
+
? UsageBus.subscribe(config.onUsageEvent)
|
|
90
|
+
: undefined;
|
|
91
|
+
return () => {
|
|
92
|
+
unsub?.();
|
|
93
|
+
};
|
|
94
|
+
}, [config?.onUsageEvent]);
|
|
95
|
+
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
const token = config?.gateway?.token;
|
|
98
|
+
if (!token) return;
|
|
99
|
+
void AccountStore.refresh({
|
|
100
|
+
token,
|
|
101
|
+
baseUrl: config?.gateway?.baseUrl,
|
|
102
|
+
});
|
|
103
|
+
}, [config?.gateway?.token, config?.gateway?.baseUrl]);
|
|
104
|
+
|
|
105
|
+
const branding = useMemo(
|
|
106
|
+
() =>
|
|
107
|
+
resolveBranding(
|
|
108
|
+
locale,
|
|
109
|
+
config?.branding as KokoBrandingConfig | undefined,
|
|
110
|
+
account?.entitlements,
|
|
111
|
+
),
|
|
112
|
+
[locale, config?.branding, account?.entitlements],
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
if (branding.downgraded && !downgradeEmitted.current) {
|
|
117
|
+
downgradeEmitted.current = true;
|
|
118
|
+
UsageBus.emit({
|
|
119
|
+
type: 'branding_downgraded',
|
|
120
|
+
reason: 'missing_entitlement',
|
|
121
|
+
at: Date.now(),
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
if (!branding.downgraded) downgradeEmitted.current = false;
|
|
125
|
+
}, [branding.downgraded]);
|
|
126
|
+
|
|
127
|
+
const value = useMemo<KokoUiContextValue>(
|
|
128
|
+
() => ({
|
|
129
|
+
locale,
|
|
130
|
+
theme,
|
|
131
|
+
appTheme,
|
|
132
|
+
colors,
|
|
133
|
+
branding,
|
|
134
|
+
account,
|
|
135
|
+
t: (key, vars) => t(locale, key, vars),
|
|
136
|
+
}),
|
|
137
|
+
[locale, theme, appTheme, colors, branding, account],
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<KokoUiContext.Provider value={value}>{children}</KokoUiContext.Provider>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function useKokoUi(): KokoUiContextValue {
|
|
146
|
+
const ctx = useContext(KokoUiContext);
|
|
147
|
+
if (!ctx) {
|
|
148
|
+
const locale: KokoLocale = 'en';
|
|
149
|
+
const appTheme: KokoTheme = 'light';
|
|
150
|
+
const theme = invertTheme(appTheme);
|
|
151
|
+
return {
|
|
152
|
+
locale,
|
|
153
|
+
theme,
|
|
154
|
+
appTheme,
|
|
155
|
+
colors: resolveThemeColors(theme),
|
|
156
|
+
branding: resolveBranding(locale, undefined, undefined),
|
|
157
|
+
account: null,
|
|
158
|
+
t: (key, vars) => t(locale, key, vars),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
return ctx;
|
|
162
|
+
}
|
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import type { Frame, MatchRule, Selector, ViewNode } from '../types';
|
|
2
|
+
|
|
3
|
+
function norm(s: string): string {
|
|
4
|
+
return s.trim().toLowerCase();
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Strip particles models often invent around a real on-screen label
|
|
9
|
+
* (「创建钱包」→「创建新钱包」/「立即创建钱包」). Host-agnostic fillers only.
|
|
10
|
+
*/
|
|
11
|
+
function softKey(s: string): string {
|
|
12
|
+
return norm(s)
|
|
13
|
+
.replace(/[\s\-_./·•::()()【】[\]]+/g, '')
|
|
14
|
+
.replace(
|
|
15
|
+
/^(请|立即|马上|点击|轻点|去|进入|开始|打开)+|(按钮|button|btn)$/gi,
|
|
16
|
+
'',
|
|
17
|
+
)
|
|
18
|
+
// Infix noise the model adds between shared stems (创建「新」钱包).
|
|
19
|
+
.replace(
|
|
20
|
+
/(创建|新建|添加|新增|开通|注册|登录|登入|提交|确认|发送|保存|删除|取消|返回|下一步|完成)(?:全新|新的|新|一个|一下)*/g,
|
|
21
|
+
'$1',
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function levenshtein(a: string, b: string): number {
|
|
26
|
+
if (a === b) return 0;
|
|
27
|
+
if (!a.length) return b.length;
|
|
28
|
+
if (!b.length) return a.length;
|
|
29
|
+
const row = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
30
|
+
for (let i = 0; i < a.length; i++) {
|
|
31
|
+
let prev = i + 1;
|
|
32
|
+
for (let j = 0; j < b.length; j++) {
|
|
33
|
+
const cur =
|
|
34
|
+
a[i] === b[j]
|
|
35
|
+
? row[j]!
|
|
36
|
+
: 1 + Math.min(row[j]!, row[j + 1]!, prev);
|
|
37
|
+
row[j] = prev;
|
|
38
|
+
prev = cur;
|
|
39
|
+
}
|
|
40
|
+
row[b.length] = prev;
|
|
41
|
+
}
|
|
42
|
+
return row[b.length]!;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Scripts where one character carries a whole morpheme. */
|
|
46
|
+
const IDEOGRAPHIC =
|
|
47
|
+
/[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uac00-\ud7af]/;
|
|
48
|
+
|
|
49
|
+
function isIdeographic(s: string): boolean {
|
|
50
|
+
const chars = [...s];
|
|
51
|
+
if (!chars.length) return false;
|
|
52
|
+
const hits = chars.filter((c) => IDEOGRAPHIC.test(c)).length;
|
|
53
|
+
return hits / chars.length >= 0.5;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Digit runs identify a specific thing — Account #1 vs #2, 1.2x vs 1.6x,
|
|
58
|
+
* 第2个 vs 第3个. Loose matching must never cross them, or the agent acts on
|
|
59
|
+
* the wrong account.
|
|
60
|
+
*/
|
|
61
|
+
function digitsConflict(a: string, b: string): boolean {
|
|
62
|
+
const da = (a.match(/\d+/g) || []).join('.');
|
|
63
|
+
const db = (b.match(/\d+/g) || []).join('.');
|
|
64
|
+
return !!da && !!db && da !== db;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Edit budget for a fuzzy label match.
|
|
69
|
+
*
|
|
70
|
+
* Latin typos are cheap to forgive. One substituted ideograph is a different
|
|
71
|
+
* word — 发送/发现, 交换/交易, 合同/合约, 钱币/钱包 all sit at distance 1 — so
|
|
72
|
+
* ideographic labels get no budget until they are long enough that a single
|
|
73
|
+
* edit cannot flip the meaning. Differing digits get no budget at all.
|
|
74
|
+
*/
|
|
75
|
+
function editBudget(a: string, b: string): number {
|
|
76
|
+
if (digitsConflict(a, b)) return 0;
|
|
77
|
+
const len = Math.max(a.length, b.length);
|
|
78
|
+
if (isIdeographic(a) || isIdeographic(b)) return len >= 6 ? 1 : 0;
|
|
79
|
+
return len <= 4 ? 1 : 2;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Loose label match: substring either way, soft filler strip, small edit distance. */
|
|
83
|
+
export function textMatches(
|
|
84
|
+
haystack: string | undefined,
|
|
85
|
+
needle: string,
|
|
86
|
+
exact?: boolean,
|
|
87
|
+
): boolean {
|
|
88
|
+
if (!haystack) return false;
|
|
89
|
+
const h = norm(haystack);
|
|
90
|
+
const n = norm(needle);
|
|
91
|
+
if (!n) return false;
|
|
92
|
+
if (exact) return h === n;
|
|
93
|
+
if (h === n) return true;
|
|
94
|
+
|
|
95
|
+
const hs = softKey(haystack);
|
|
96
|
+
const ns = softKey(needle);
|
|
97
|
+
if (hs && ns && hs === ns) return true;
|
|
98
|
+
|
|
99
|
+
// Short CJK labels name distinct controls: 服务设置 is a section heading,
|
|
100
|
+
// not the 设置 button. Substring matching must not invent a visible target.
|
|
101
|
+
if (n.length <= 2 && isIdeographic(n) && isIdeographic(h)) return false;
|
|
102
|
+
|
|
103
|
+
// Screen text contains the full needle (safe).
|
|
104
|
+
if (h.includes(n) && n.length >= 2) return true;
|
|
105
|
+
if (hs && ns && hs.includes(ns) && ns.length >= 2) {
|
|
106
|
+
const ratio = ns.length / hs.length;
|
|
107
|
+
if (ratio >= 0.5) return true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Needle contains screen text only when nearly the same after softKey
|
|
111
|
+
// (「创建新钱包」→「创建钱包»). Never match 「创建钱包」 onto bare 「钱包」.
|
|
112
|
+
if (hs && ns && ns.includes(hs) && hs.length >= 2 && !digitsConflict(hs, ns)) {
|
|
113
|
+
if (hs.length / ns.length >= 0.72) return true;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (h.length <= 16 && n.length <= 16) {
|
|
117
|
+
// Require similar length — else 「添加钱包」≈「钱包」(dist 2) false-positives.
|
|
118
|
+
const maxLen = Math.max(h.length, n.length);
|
|
119
|
+
const minLen = Math.min(h.length, n.length);
|
|
120
|
+
const budget = editBudget(h, n);
|
|
121
|
+
if (budget > 0 && minLen / maxLen >= 0.75) {
|
|
122
|
+
if (levenshtein(h, n) <= budget) return true;
|
|
123
|
+
}
|
|
124
|
+
if (hs && ns && hs.length <= 16 && ns.length <= 16) {
|
|
125
|
+
const maxL = Math.max(hs.length, ns.length);
|
|
126
|
+
const minL = Math.min(hs.length, ns.length);
|
|
127
|
+
const softBudget = editBudget(hs, ns);
|
|
128
|
+
if (softBudget > 0 && minL / maxL >= 0.75) {
|
|
129
|
+
if (levenshtein(hs, ns) <= softBudget) return true;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function regionContains(frame: Frame, region: MatchRule & { region: string }, window?: Frame): boolean {
|
|
137
|
+
const ratio = 'ratio' in region && typeof region.ratio === 'number' ? region.ratio : 0.2;
|
|
138
|
+
// Without window size, approximate using large canvas; callers may refine later.
|
|
139
|
+
const W = window?.width ?? Math.max(frame.x + frame.width, 400);
|
|
140
|
+
const H = window?.height ?? Math.max(frame.y + frame.height, 800);
|
|
141
|
+
const cx = frame.x + frame.width / 2;
|
|
142
|
+
const cy = frame.y + frame.height / 2;
|
|
143
|
+
|
|
144
|
+
switch (region.region) {
|
|
145
|
+
case 'top':
|
|
146
|
+
return cy <= H * ratio;
|
|
147
|
+
case 'bottom':
|
|
148
|
+
return cy >= H * (1 - ratio);
|
|
149
|
+
case 'left':
|
|
150
|
+
return cx <= W * ratio;
|
|
151
|
+
case 'right':
|
|
152
|
+
return cx >= W * (1 - ratio);
|
|
153
|
+
case 'center': {
|
|
154
|
+
const m = ratio;
|
|
155
|
+
return cx >= W * m && cx <= W * (1 - m) && cy >= H * m && cy <= H * (1 - m);
|
|
156
|
+
}
|
|
157
|
+
default:
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function collectTexts(node: ViewNode, depth = 0, maxDepth = 3): string[] {
|
|
163
|
+
const out: string[] = [];
|
|
164
|
+
if (node.text) out.push(node.text);
|
|
165
|
+
if (node.accessibilityLabel) out.push(node.accessibilityLabel);
|
|
166
|
+
if (depth >= maxDepth) return out;
|
|
167
|
+
for (const c of node.children) out.push(...collectTexts(c, depth + 1, maxDepth));
|
|
168
|
+
return out;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function parentTextsNear(root: ViewNode, targetId: string): string[] {
|
|
172
|
+
// Walk tree; when we find target, return texts from parent and siblings.
|
|
173
|
+
let parentOfTarget: ViewNode | null = null;
|
|
174
|
+
let found = false;
|
|
175
|
+
|
|
176
|
+
const walk = (n: ViewNode, parent: ViewNode | null) => {
|
|
177
|
+
if (n.id === targetId) {
|
|
178
|
+
parentOfTarget = parent;
|
|
179
|
+
found = true;
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
for (const c of n.children) {
|
|
183
|
+
walk(c, n);
|
|
184
|
+
if (found) return;
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
walk(root, null);
|
|
188
|
+
if (!parentOfTarget) return collectTexts(root).slice(0, 20);
|
|
189
|
+
return collectTexts(parentOfTarget);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function flattenTree(root: ViewNode): ViewNode[] {
|
|
193
|
+
const out: ViewNode[] = [];
|
|
194
|
+
const walk = (n: ViewNode) => {
|
|
195
|
+
out.push(n);
|
|
196
|
+
for (const c of n.children) walk(c);
|
|
197
|
+
};
|
|
198
|
+
walk(root);
|
|
199
|
+
return out;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export function findNodeById(root: ViewNode, id: string): ViewNode | null {
|
|
203
|
+
if (root.id === id) return root;
|
|
204
|
+
for (const c of root.children) {
|
|
205
|
+
const hit = findNodeById(c, id);
|
|
206
|
+
if (hit) return hit;
|
|
207
|
+
}
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function nodeHasText(node: ViewNode, needle: string, exact?: boolean): boolean {
|
|
212
|
+
if (
|
|
213
|
+
textMatches(node.text, needle, exact) ||
|
|
214
|
+
textMatches(node.accessibilityLabel, needle, exact)
|
|
215
|
+
) {
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
// Wrapper Pressable often has empty text; label sits on a child Text.
|
|
219
|
+
if (exact) return false;
|
|
220
|
+
return collectTexts(node).some((t) => textMatches(t, needle, false));
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function matchesRule(node: ViewNode, rule: MatchRule, root: ViewNode): boolean {
|
|
224
|
+
if ('text' in rule) {
|
|
225
|
+
return nodeHasText(node, rule.text, rule.exact);
|
|
226
|
+
}
|
|
227
|
+
if ('nearText' in rule) {
|
|
228
|
+
const nearby = parentTextsNear(root, node.id).join(' ');
|
|
229
|
+
return textMatches(nearby, rule.nearText, rule.exact);
|
|
230
|
+
}
|
|
231
|
+
if ('clickable' in rule) {
|
|
232
|
+
return node.clickable === rule.clickable;
|
|
233
|
+
}
|
|
234
|
+
if ('type' in rule) {
|
|
235
|
+
return norm(node.type).includes(norm(rule.type));
|
|
236
|
+
}
|
|
237
|
+
if ('testID' in rule) {
|
|
238
|
+
return !!node.testID && node.testID === rule.testID;
|
|
239
|
+
}
|
|
240
|
+
if ('accessibilityLabel' in rule) {
|
|
241
|
+
return textMatches(node.accessibilityLabel, rule.accessibilityLabel, rule.exact);
|
|
242
|
+
}
|
|
243
|
+
if ('region' in rule) {
|
|
244
|
+
return regionContains(node.frame, rule as MatchRule & { region: string });
|
|
245
|
+
}
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export function nodeMatches(node: ViewNode, selector: Selector, root: ViewNode): boolean {
|
|
250
|
+
if (node.visible === false || node.enabled === false) return false;
|
|
251
|
+
if (!selector.match.length) return false;
|
|
252
|
+
return selector.match.every((rule) => matchesRule(node, rule, root));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export function findAll(root: ViewNode, selector: Selector): ViewNode[] {
|
|
256
|
+
return flattenTree(root).filter((n) => nodeMatches(n, selector, root));
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** Climb to the nearest clickable / toggle / sheet ancestor (inclusive). */
|
|
260
|
+
function nearestInteractive(root: ViewNode, node: ViewNode): ViewNode {
|
|
261
|
+
const byId = new Map(flattenTree(root).map((n) => [n.id, n]));
|
|
262
|
+
// parent id = everything before last /
|
|
263
|
+
let cur: ViewNode | undefined = node;
|
|
264
|
+
while (cur) {
|
|
265
|
+
if (cur.visible !== false && cur.enabled !== false && (cur.clickable || cur.toggle || cur.adjustable || cur.sheet)) return cur;
|
|
266
|
+
const parentId: string = cur.id.includes('/')
|
|
267
|
+
? cur.id.slice(0, cur.id.lastIndexOf('/'))
|
|
268
|
+
: '';
|
|
269
|
+
cur = parentId ? byId.get(parentId) : undefined;
|
|
270
|
+
}
|
|
271
|
+
return node;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function isDegenerateHit(root: ViewNode, n: ViewNode): boolean {
|
|
275
|
+
// Full-window / root wrappers are never useful tap targets.
|
|
276
|
+
if (!n.id || n.id === root.id || n.id === '0') return true;
|
|
277
|
+
const rw = Math.max(1, root.frame.width);
|
|
278
|
+
const rh = Math.max(1, root.frame.height);
|
|
279
|
+
const areaRatio = (n.frame.width * n.frame.height) / (rw * rh);
|
|
280
|
+
if (areaRatio >= 0.55) return true;
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function isInputOrInputWrapper(node: ViewNode): boolean {
|
|
285
|
+
if (/textfield|textinput|edittext|uitextview|textarea|searchbar/i.test(node.type)) return true;
|
|
286
|
+
return node.children.some(child => child.visible !== false && isInputOrInputWrapper(child));
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export function find(root: ViewNode, selector: Selector, options?: { preferNonInput?: boolean }): ViewNode | null {
|
|
290
|
+
let all = findAll(root, selector);
|
|
291
|
+
// Common RN case: model asks clickable+text, but text is on a child Text
|
|
292
|
+
// while Pressable wrapper is the only clickable node (handled by nodeHasText).
|
|
293
|
+
// If still empty, drop clickable requirement, match text, then climb to wrapper.
|
|
294
|
+
if (!all.length) {
|
|
295
|
+
const withoutClick = {
|
|
296
|
+
...selector,
|
|
297
|
+
match: selector.match.filter((r) => !('clickable' in r)),
|
|
298
|
+
};
|
|
299
|
+
if (withoutClick.match.length > 0 && withoutClick.match.length < selector.match.length) {
|
|
300
|
+
const leaves = findAll(root, withoutClick);
|
|
301
|
+
const upgraded = leaves.map((n) => nearestInteractive(root, n));
|
|
302
|
+
const wantClickable = selector.match.some(
|
|
303
|
+
(r) => 'clickable' in r && r.clickable === true,
|
|
304
|
+
);
|
|
305
|
+
all = wantClickable
|
|
306
|
+
? upgraded.filter((n) => n.clickable || n.toggle || n.sheet || n.adjustable)
|
|
307
|
+
: upgraded;
|
|
308
|
+
// De-dupe by id
|
|
309
|
+
const seen = new Set<string>();
|
|
310
|
+
all = all.filter((n) => (seen.has(n.id) ? false : (seen.add(n.id), true)));
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
all = all.filter((n) => !isDegenerateHit(root, n));
|
|
314
|
+
if (!all.length) return null;
|
|
315
|
+
// A query field can contain the same text as a search result. For a tap on
|
|
316
|
+
// an action, prefer matching non-input controls, including when the input is
|
|
317
|
+
// wrapped in a clickable RN view. An explicit input type remains authoritative.
|
|
318
|
+
const explicitlyInput = selector.match.some(rule => 'type' in rule &&
|
|
319
|
+
/textfield|textinput|edittext|uitextview|textarea|searchbar/i.test(rule.type));
|
|
320
|
+
if (options?.preferNonInput && !explicitlyInput) {
|
|
321
|
+
const actions = all.filter(node => !isInputOrInputWrapper(node));
|
|
322
|
+
if (actions.length) all = actions;
|
|
323
|
+
}
|
|
324
|
+
// Prefer interactive + compact controls (not giant containers).
|
|
325
|
+
const ranked = selector.index !== undefined ? all : [...all].sort((a, b) =>
|
|
326
|
+
rankMatch(b) + labelSpecificity(b, selector) - rankMatch(a) - labelSpecificity(a, selector) ||
|
|
327
|
+
a.frame.width * a.frame.height - b.frame.width * b.frame.height,
|
|
328
|
+
);
|
|
329
|
+
const index = selector.index ?? 0;
|
|
330
|
+
return ranked[index] ?? null;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Last-resort: find best interactive node whose visible text soft-matches needle.
|
|
335
|
+
* Used when the planner invents near-synonym copy not present verbatim.
|
|
336
|
+
*/
|
|
337
|
+
export function findBySoftLabel(root: ViewNode, needle: string, options?: { preferNonInput?: boolean }): ViewNode | null {
|
|
338
|
+
const n = needle.trim();
|
|
339
|
+
if (!n) return null;
|
|
340
|
+
let best: ViewNode | null = null;
|
|
341
|
+
let bestScore = -1;
|
|
342
|
+
for (const node of flattenTree(root)) {
|
|
343
|
+
if (node.visible === false || node.enabled === false) continue;
|
|
344
|
+
if (isDegenerateHit(root, node)) continue;
|
|
345
|
+
const labels = [
|
|
346
|
+
node.text,
|
|
347
|
+
node.accessibilityLabel,
|
|
348
|
+
...collectTexts(node, 0, 2),
|
|
349
|
+
].filter((t): t is string => !!t && t.trim().length > 0);
|
|
350
|
+
if (!labels.some((t) => textMatches(t, n))) continue;
|
|
351
|
+
let score = rankMatch(node) + labelSpecificity(node, { match: [{ text: n }] });
|
|
352
|
+
if (options?.preferNonInput && isInputOrInputWrapper(node)) score -= 200;
|
|
353
|
+
// Prefer roomy-but-not-huge tap targets (real buttons over tiny glyphs).
|
|
354
|
+
const area = node.frame.width * node.frame.height;
|
|
355
|
+
score += Math.min(40, area / 800);
|
|
356
|
+
// Penalize oversized containers.
|
|
357
|
+
score -= Math.min(60, area / 20_000);
|
|
358
|
+
if (score > bestScore) {
|
|
359
|
+
bestScore = score;
|
|
360
|
+
best = nearestInteractive(root, node);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
if (best && isDegenerateHit(root, best)) return null;
|
|
364
|
+
return best;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function rankMatch(n: ViewNode): number {
|
|
368
|
+
let s = 0;
|
|
369
|
+
if (n.toggle) s += 100;
|
|
370
|
+
if (n.adjustable) s += 80;
|
|
371
|
+
if (n.sheet && n.clickable) s += 70;
|
|
372
|
+
if (n.clickable) s += 40;
|
|
373
|
+
if (n.enabled) s += 5;
|
|
374
|
+
if (n.visible) s += 2;
|
|
375
|
+
// Prefer tighter frames among equals.
|
|
376
|
+
const area = n.frame.width * n.frame.height;
|
|
377
|
+
if (area > 0 && area < 120_000) s += 3;
|
|
378
|
+
return s;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/** A control's own label is stronger evidence than an ancestor's aggregated text. */
|
|
382
|
+
function labelSpecificity(node: ViewNode, selector: Selector): number {
|
|
383
|
+
let score = 0;
|
|
384
|
+
for (const rule of selector.match) {
|
|
385
|
+
const wanted = 'text' in rule ? rule.text :
|
|
386
|
+
'accessibilityLabel' in rule ? rule.accessibilityLabel : undefined;
|
|
387
|
+
if (!wanted) continue;
|
|
388
|
+
const own = [node.text, node.accessibilityLabel].filter((x): x is string => !!x);
|
|
389
|
+
if (own.some(text => norm(text) === norm(wanted))) score += 100;
|
|
390
|
+
else if (own.some(text => softKey(text) === softKey(wanted))) score += 90;
|
|
391
|
+
else {
|
|
392
|
+
const labels = new Set(collectTexts(node, 0, 3).map(softKey).filter(Boolean));
|
|
393
|
+
if (labels.size === 1 && labels.has(softKey(wanted))) score += 90;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return score;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/** Keep a broad actionable container from centering between adjacent controls. */
|
|
400
|
+
export function centerOfLabel(node: ViewNode, label?: string): { x: number; y: number } {
|
|
401
|
+
if (!label) return centerOf(node);
|
|
402
|
+
const key = softKey(label);
|
|
403
|
+
if (!key || [node.text, node.accessibilityLabel].some(text => text && softKey(text) === key)) return centerOf(node);
|
|
404
|
+
const targets = flattenTree(node).filter(child => child !== node && child.visible !== false &&
|
|
405
|
+
child.enabled !== false && child.frame.width > 0 && child.frame.height > 0 &&
|
|
406
|
+
[child.text, child.accessibilityLabel].some(text => text && softKey(text) === key));
|
|
407
|
+
targets.sort((a, b) => rankMatch(b) - rankMatch(a) ||
|
|
408
|
+
a.frame.width * a.frame.height - b.frame.width * b.frame.height);
|
|
409
|
+
return centerOf(targets[0] || node);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
export function centerOf(node: ViewNode): { x: number; y: number } {
|
|
413
|
+
return {
|
|
414
|
+
x: node.frame.x + node.frame.width / 2,
|
|
415
|
+
y: node.frame.y + node.frame.height / 2,
|
|
416
|
+
};
|
|
417
|
+
}
|