@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,349 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional host-declared actions — the low-friction way for complex Apps
|
|
3
|
+
* (OneKey / Tamagui) when native dump cannot see icons without a11y/testID.
|
|
4
|
+
*
|
|
5
|
+
* Hosts register controls only while mounted and visible. Callbacks supplement
|
|
6
|
+
* native controls; registration does not establish visibility or identity.
|
|
7
|
+
*
|
|
8
|
+
* IMPORTANT: host ids are NOT dump nodeIds. Never emit `id=host:…` in the
|
|
9
|
+
* screen model — planners will tap them and fail with "nodeId not found".
|
|
10
|
+
*
|
|
11
|
+
* Optional `run`: after a unique current native control is bound, a callback
|
|
12
|
+
* may execute its behavior instead of dispatching a geometric touch.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { flattenTree, textMatches } from '../selector/match';
|
|
16
|
+
import type { ViewNode } from '../types';
|
|
17
|
+
|
|
18
|
+
export type HostActionKind =
|
|
19
|
+
| 'button'
|
|
20
|
+
| 'tab'
|
|
21
|
+
| 'nav'
|
|
22
|
+
| 'field'
|
|
23
|
+
| 'sheet'
|
|
24
|
+
| 'other';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Host action matching: also consider optional aliases (e.g. prior-locale tab copy).
|
|
28
|
+
*/
|
|
29
|
+
export type HostAction = {
|
|
30
|
+
/** Stable id, e.g. "tab.home" / "header.settings". */
|
|
31
|
+
id: string;
|
|
32
|
+
/** Human label shown to the planner (prefer host locale). */
|
|
33
|
+
label: string;
|
|
34
|
+
kind?: HostActionKind;
|
|
35
|
+
/** Prefer testID when the host already has one. */
|
|
36
|
+
testID?: string;
|
|
37
|
+
/** Free-text / a11y match fallback. */
|
|
38
|
+
text?: string;
|
|
39
|
+
/** Extra NL match strings (other locales / synonyms). */
|
|
40
|
+
aliases?: string[];
|
|
41
|
+
/** Optional deep-link or route hint for narration only. */
|
|
42
|
+
route?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Host-provided invoke. Used only after unique native target binding.
|
|
45
|
+
* Register only while the CTA is mounted and visible; unregister on blur.
|
|
46
|
+
*/
|
|
47
|
+
run?: () => void | Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* When true (default for one-shot CTAs), unregister after a successful host run.
|
|
50
|
+
* Tabs / persistent chrome should set `oneshot: false`.
|
|
51
|
+
*/
|
|
52
|
+
oneshot?: boolean;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
type Listener = (actions: HostAction[]) => void;
|
|
56
|
+
|
|
57
|
+
class HostActionsStoreImpl {
|
|
58
|
+
private actions: HostAction[] = [];
|
|
59
|
+
private listeners = new Set<Listener>();
|
|
60
|
+
|
|
61
|
+
/** Replace the whole catalog (typical: once at app start). */
|
|
62
|
+
setActions(actions: HostAction[]) {
|
|
63
|
+
this.actions = sanitize(actions);
|
|
64
|
+
this.emit();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Append / upsert by id. */
|
|
68
|
+
registerActions(actions: HostAction[]) {
|
|
69
|
+
const map = new Map(this.actions.map((a) => [a.id, a]));
|
|
70
|
+
for (const a of sanitize(actions)) map.set(a.id, a);
|
|
71
|
+
this.actions = [...map.values()];
|
|
72
|
+
this.emit();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Drop a previously registered action (e.g. EmptyWallet unmount). */
|
|
76
|
+
unregisterAction(id: string) {
|
|
77
|
+
const key = String(id ?? '').replace(/^host:/, '').trim();
|
|
78
|
+
if (!key) return;
|
|
79
|
+
const next = this.actions.filter((a) => a.id !== key);
|
|
80
|
+
if (next.length === this.actions.length) return;
|
|
81
|
+
this.actions = next;
|
|
82
|
+
this.emit();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
clear() {
|
|
86
|
+
this.actions = [];
|
|
87
|
+
this.emit();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
getActions(): HostAction[] {
|
|
91
|
+
return this.actions.slice();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
getById(id: string): HostAction | undefined {
|
|
95
|
+
const key = id.replace(/^host:/, '').trim();
|
|
96
|
+
return this.actions.find((a) => a.id === key);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Match by label / text / testID (planner taps by copy, not host id). */
|
|
100
|
+
findForTap(needle: {
|
|
101
|
+
label?: string;
|
|
102
|
+
text?: string;
|
|
103
|
+
testID?: string;
|
|
104
|
+
}): HostAction | undefined {
|
|
105
|
+
const testID = (needle.testID || '').trim();
|
|
106
|
+
if (testID) {
|
|
107
|
+
const matches = this.actions.filter((a) => a.testID === testID);
|
|
108
|
+
// An explicit native identity must not fall back to a different callback.
|
|
109
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
110
|
+
}
|
|
111
|
+
const raw = (needle.text || needle.label || '').trim();
|
|
112
|
+
if (!raw) return undefined;
|
|
113
|
+
// Also match 「发现」 inside narration like「打开「发现」标签页」.
|
|
114
|
+
const quoted = raw.match(/「([^」]+)」/)?.[1]?.trim();
|
|
115
|
+
const needles = quoted && quoted !== raw ? [raw, quoted] : [raw];
|
|
116
|
+
|
|
117
|
+
const hits = this.actions.filter(a => {
|
|
118
|
+
const candidates = [a.label, a.text, ...(a.aliases ?? [])].filter(
|
|
119
|
+
Boolean,
|
|
120
|
+
) as string[];
|
|
121
|
+
return needles.some(label => candidates.some(c => textMatches(c, label, true)));
|
|
122
|
+
});
|
|
123
|
+
// Repeated row labels need the native selector/geometry or a unique testID.
|
|
124
|
+
// Picking the first callback silently targets a different item.
|
|
125
|
+
return hits.length === 1 ? hits[0] : undefined;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
subscribe(listener: Listener): () => void {
|
|
129
|
+
this.listeners.add(listener);
|
|
130
|
+
listener(this.getActions());
|
|
131
|
+
return () => this.listeners.delete(listener);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
private emit() {
|
|
135
|
+
const snap = this.getActions();
|
|
136
|
+
for (const l of this.listeners) l(snap);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function sanitize(actions: HostAction[]): HostAction[] {
|
|
141
|
+
const out: HostAction[] = [];
|
|
142
|
+
for (const a of actions) {
|
|
143
|
+
const id = String(a?.id ?? '').trim();
|
|
144
|
+
const label = String(a?.label ?? '').trim();
|
|
145
|
+
if (!id || !label) continue;
|
|
146
|
+
const kind = a.kind ?? 'button';
|
|
147
|
+
const hasRun = typeof a.run === 'function';
|
|
148
|
+
// Tabs stay registered; button CTAs with run are one-shot by default.
|
|
149
|
+
const oneshot =
|
|
150
|
+
typeof a.oneshot === 'boolean'
|
|
151
|
+
? a.oneshot
|
|
152
|
+
: hasRun && kind !== 'tab';
|
|
153
|
+
out.push({
|
|
154
|
+
id: id.slice(0, 80),
|
|
155
|
+
label: label.slice(0, 80),
|
|
156
|
+
kind,
|
|
157
|
+
testID: a.testID?.trim().slice(0, 120) || undefined,
|
|
158
|
+
text: a.text?.trim().slice(0, 80) || undefined,
|
|
159
|
+
aliases: Array.isArray(a.aliases)
|
|
160
|
+
? a.aliases
|
|
161
|
+
.map((s) => String(s ?? '').trim().slice(0, 80))
|
|
162
|
+
.filter(Boolean)
|
|
163
|
+
.slice(0, 8)
|
|
164
|
+
: undefined,
|
|
165
|
+
route: a.route?.trim().slice(0, 120) || undefined,
|
|
166
|
+
// Keep host callback by reference — not serializable, intentional.
|
|
167
|
+
run: hasRun ? a.run : undefined,
|
|
168
|
+
oneshot,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
return out.slice(0, 80);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function hostNeedle(a: HostAction): string {
|
|
175
|
+
return (a.text || a.label || '').trim();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* A unique callback catalog entry is not a unique native control. Bind it to
|
|
180
|
+
* the node already chosen by the full selector (including index/nearText),
|
|
181
|
+
* otherwise the caller must preserve that selector and use a native touch.
|
|
182
|
+
*/
|
|
183
|
+
export function canRunHostActionForNode(
|
|
184
|
+
action: HostAction,
|
|
185
|
+
selected: ViewNode | null | undefined,
|
|
186
|
+
root: ViewNode | null | undefined,
|
|
187
|
+
): boolean {
|
|
188
|
+
if (!selected || !root || typeof action.run !== 'function') return false;
|
|
189
|
+
const nodes = new Map<string, ViewNode>();
|
|
190
|
+
const parents = new Map<string, ViewNode>();
|
|
191
|
+
const collect = (node: ViewNode, parent?: ViewNode) => {
|
|
192
|
+
if (node.visible === false || node.enabled === false) return;
|
|
193
|
+
nodes.set(node.id, node);
|
|
194
|
+
if (parent) parents.set(node.id, parent);
|
|
195
|
+
for (const child of node.children) collect(child, node);
|
|
196
|
+
};
|
|
197
|
+
collect(root);
|
|
198
|
+
const current = nodes.get(selected.id);
|
|
199
|
+
if (!current || current.type !== selected.type || current.text !== selected.text ||
|
|
200
|
+
current.accessibilityLabel !== selected.accessibilityLabel || current.testID !== selected.testID) return false;
|
|
201
|
+
const usable = (node: ViewNode) => {
|
|
202
|
+
const frame = node.frame;
|
|
203
|
+
const cx = frame.x + frame.width / 2, cy = frame.y + frame.height / 2;
|
|
204
|
+
return node.id !== root.id && frame.width > 0 && frame.height > 0 &&
|
|
205
|
+
frame.width * frame.height < root.frame.width * root.frame.height * 0.55 &&
|
|
206
|
+
cx >= root.frame.x && cx <= root.frame.x + root.frame.width &&
|
|
207
|
+
cy >= root.frame.y && cy <= root.frame.y + root.frame.height;
|
|
208
|
+
};
|
|
209
|
+
const owner = (node: ViewNode): ViewNode | undefined => {
|
|
210
|
+
for (let current: ViewNode | undefined = node; current; current = parents.get(current.id)) {
|
|
211
|
+
if (usable(current) && (current.clickable || current.toggle || current.adjustable ||
|
|
212
|
+
/button|tabbaritem|bottomnavigationitem/i.test(current.type))) return current;
|
|
213
|
+
}
|
|
214
|
+
return undefined;
|
|
215
|
+
};
|
|
216
|
+
const targetOwner = owner(current);
|
|
217
|
+
if (action.testID) {
|
|
218
|
+
const matches = [...nodes.values()].filter(node => node.testID === action.testID && usable(node));
|
|
219
|
+
if (matches.length !== 1) return false;
|
|
220
|
+
const anchor = matches[0];
|
|
221
|
+
// A unique explicit testID may identify a non-clickable text leaf, which
|
|
222
|
+
// Fabric commonly nests inside the actual Pressable selected by geometry.
|
|
223
|
+
return anchor.id === current.id || (!!targetOwner && owner(anchor)?.id === targetOwner.id);
|
|
224
|
+
}
|
|
225
|
+
if (!targetOwner) return false;
|
|
226
|
+
const needles = [action.text || action.label, ...(action.aliases || [])].filter(Boolean);
|
|
227
|
+
const owners = new Set<string>();
|
|
228
|
+
for (const node of nodes.values()) {
|
|
229
|
+
if (!needles.some(label => textMatches(node.text, label, true) || textMatches(node.accessibilityLabel, label, true))) continue;
|
|
230
|
+
const control = owner(node);
|
|
231
|
+
if (control) owners.add(control.id);
|
|
232
|
+
}
|
|
233
|
+
return owners.size === 1 && owners.has(targetOwner.id);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Callbacks declare behavior, not visibility. Only current visible native
|
|
238
|
+
* evidence enters the model; missing native content can use fresh local OCR.
|
|
239
|
+
*/
|
|
240
|
+
export function filterVisibleHostActions(
|
|
241
|
+
actions: HostAction[],
|
|
242
|
+
root: ViewNode | null | undefined,
|
|
243
|
+
): HostAction[] {
|
|
244
|
+
if (!actions.length) return [];
|
|
245
|
+
if (!root) return [];
|
|
246
|
+
const nodes = flattenTree(root).filter(n => n.visible !== false && n.enabled !== false);
|
|
247
|
+
const inDump = (a: HostAction, exact = false): boolean => {
|
|
248
|
+
if (a.testID && nodes.some((n) => n.testID === a.testID)) return true;
|
|
249
|
+
const needles = [hostNeedle(a), ...(a.aliases ?? [])]
|
|
250
|
+
.map((s) => s.trim())
|
|
251
|
+
.filter(Boolean);
|
|
252
|
+
if (!needles.length) return false;
|
|
253
|
+
for (const needle of needles) {
|
|
254
|
+
const hit = nodes.some((n) => {
|
|
255
|
+
if (exact) {
|
|
256
|
+
return (
|
|
257
|
+
textMatches(n.text, needle, true) ||
|
|
258
|
+
textMatches(n.accessibilityLabel, needle, true)
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
return (
|
|
262
|
+
textMatches(n.text, needle) ||
|
|
263
|
+
textMatches(n.accessibilityLabel, needle)
|
|
264
|
+
);
|
|
265
|
+
});
|
|
266
|
+
if (hit) return true;
|
|
267
|
+
}
|
|
268
|
+
return false;
|
|
269
|
+
};
|
|
270
|
+
return actions.filter((a) => {
|
|
271
|
+
// Exact: avoid「钱包」tab matching「创建助记词钱包」onboarding copy.
|
|
272
|
+
if (a.kind === 'tab') return inDump(a, true);
|
|
273
|
+
return inDump(a, true);
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Compact lines merged into ui_screen_model.
|
|
279
|
+
* No fake node ids — tap must use text「…」 / testID, never id=host:….
|
|
280
|
+
*/
|
|
281
|
+
export function hostActionsModelText(actions: HostAction[]): string {
|
|
282
|
+
if (!actions.length) return '';
|
|
283
|
+
return actions
|
|
284
|
+
.map((a) => {
|
|
285
|
+
const kind = a.kind ?? 'button';
|
|
286
|
+
const tip = a.testID
|
|
287
|
+
? ` testID=${a.testID}`
|
|
288
|
+
: a.text
|
|
289
|
+
? ` text「${a.text}」`
|
|
290
|
+
: ` text「${a.label}」`;
|
|
291
|
+
const via = typeof a.run === 'function' ? '(host run)' : '(按文案 tap,禁止用 host id)';
|
|
292
|
+
return `- [host:${kind}] 「${a.label}」${tip}${via}`;
|
|
293
|
+
})
|
|
294
|
+
.join('\n');
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export const HostActionsStore = new HostActionsStoreImpl();
|
|
298
|
+
|
|
299
|
+
export function setHostActions(actions: HostAction[]) {
|
|
300
|
+
HostActionsStore.setActions(actions);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export function registerHostActions(actions: HostAction[]) {
|
|
304
|
+
HostActionsStore.registerActions(actions);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export function unregisterHostAction(id: string) {
|
|
308
|
+
HostActionsStore.unregisterAction(id);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export function clearHostActions() {
|
|
312
|
+
HostActionsStore.clear();
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Upper bound on a single host action. These callbacks are app code we do not
|
|
317
|
+
* control: one that never settles wedges the whole goal with no step, no log
|
|
318
|
+
* line and no timeout above it. Observed as a goal sitting for minutes without
|
|
319
|
+
* ever reaching the planner.
|
|
320
|
+
*/
|
|
321
|
+
export const HOST_ACTION_TIMEOUT_MS = 8000;
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Await a host callback without letting it hang the agent. Resolves false when
|
|
325
|
+
* it throws or outruns its budget. False means the outcome is unknown: the
|
|
326
|
+
* callback may already have committed work, so callers must not replay a tap.
|
|
327
|
+
*/
|
|
328
|
+
export async function runHostAction(
|
|
329
|
+
run: () => void | Promise<void>,
|
|
330
|
+
timeoutMs: number = HOST_ACTION_TIMEOUT_MS,
|
|
331
|
+
): Promise<boolean> {
|
|
332
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
333
|
+
try {
|
|
334
|
+
await Promise.race([
|
|
335
|
+
Promise.resolve(run()),
|
|
336
|
+
new Promise<never>((_, reject) => {
|
|
337
|
+
timer = setTimeout(
|
|
338
|
+
() => reject(new Error(`host action exceeded ${timeoutMs}ms`)),
|
|
339
|
+
timeoutMs,
|
|
340
|
+
);
|
|
341
|
+
}),
|
|
342
|
+
]);
|
|
343
|
+
return true;
|
|
344
|
+
} catch {
|
|
345
|
+
return false;
|
|
346
|
+
} finally {
|
|
347
|
+
if (timer) clearTimeout(timer);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { runtimeEn, runtimeZh, type RuntimeMessageKey } from './runtimeMessages';
|
|
2
|
+
import { HostAppearanceStore } from '../provider/HostAppearanceStore';
|
|
3
|
+
import type { KokoLocale } from '../types';
|
|
4
|
+
|
|
5
|
+
export type MessageKey = RuntimeMessageKey
|
|
6
|
+
| 'brand.defaultName'
|
|
7
|
+
| 'brand.defaultTagline'
|
|
8
|
+
| 'brand.defaultPlaceholder'
|
|
9
|
+
| 'brand.defaultMark'
|
|
10
|
+
| 'sheet.recentTasks'
|
|
11
|
+
| 'sheet.timeline'
|
|
12
|
+
| 'sheet.emptyTasks'
|
|
13
|
+
| 'sheet.emptyNodesTitle'
|
|
14
|
+
| 'sheet.emptyNodesHint'
|
|
15
|
+
| 'sheet.send'
|
|
16
|
+
| 'sheet.closeA11y'
|
|
17
|
+
| 'sheet.stopA11y'
|
|
18
|
+
| 'sheet.inputA11y'
|
|
19
|
+
| 'sheet.deleteTaskTitle'
|
|
20
|
+
| 'sheet.deleteTaskBody'
|
|
21
|
+
| 'sheet.deleteTask'
|
|
22
|
+
| 'status.running'
|
|
23
|
+
| 'status.success'
|
|
24
|
+
| 'status.failed'
|
|
25
|
+
| 'status.cancelled'
|
|
26
|
+
| 'kind.user'
|
|
27
|
+
| 'kind.plan'
|
|
28
|
+
| 'kind.dump'
|
|
29
|
+
| 'kind.find'
|
|
30
|
+
| 'kind.tap'
|
|
31
|
+
| 'kind.swipe'
|
|
32
|
+
| 'kind.type'
|
|
33
|
+
| 'kind.confirm'
|
|
34
|
+
| 'kind.info'
|
|
35
|
+
| 'kind.error'
|
|
36
|
+
| 'resume.note'
|
|
37
|
+
| 'resume.verifyFirst'
|
|
38
|
+
| 'progress.running'
|
|
39
|
+
| 'progress.success'
|
|
40
|
+
| 'progress.failed'
|
|
41
|
+
| 'progress.cancelled'
|
|
42
|
+
| 'progress.openA11y'
|
|
43
|
+
| 'progress.stopA11y'
|
|
44
|
+
| 'gate.check'
|
|
45
|
+
| 'gate.checking'
|
|
46
|
+
| 'gate.stillPrivate'
|
|
47
|
+
| 'gate.unreadable'
|
|
48
|
+
| 'gate.verifyResultFirst'
|
|
49
|
+
| 'gate.replayStopped'
|
|
50
|
+
| 'dialog.cancel'
|
|
51
|
+
| 'dialog.confirm'
|
|
52
|
+
| 'dialog.continue'
|
|
53
|
+
| 'dialog.askTitle'
|
|
54
|
+
| 'dialog.askPlaceholder'
|
|
55
|
+
| 'confirm.preflightTitle'
|
|
56
|
+
| 'confirm.preflightBody'
|
|
57
|
+
| 'confirm.inlineTitle'
|
|
58
|
+
| 'confirm.inlineBody';
|
|
59
|
+
|
|
60
|
+
const zh: Record<MessageKey, string> = {
|
|
61
|
+
...runtimeZh,
|
|
62
|
+
'brand.defaultName': 'Koko',
|
|
63
|
+
'brand.defaultTagline': '用自然语言操作当前 App',
|
|
64
|
+
'brand.defaultPlaceholder': '跟 Koko 说你想做什么…',
|
|
65
|
+
'brand.defaultMark': 'K',
|
|
66
|
+
'sheet.recentTasks': '最近任务',
|
|
67
|
+
'sheet.timeline': '执行记录',
|
|
68
|
+
'sheet.emptyTasks': '还没有任务,在下方说一句开始',
|
|
69
|
+
'sheet.emptyNodesTitle': '暂无步骤',
|
|
70
|
+
'sheet.emptyNodesHint': '发送指令后,这里会显示每一步操作',
|
|
71
|
+
'sheet.send': '发送',
|
|
72
|
+
'sheet.closeA11y': '关闭会话',
|
|
73
|
+
'sheet.stopA11y': '停止当前任务',
|
|
74
|
+
'sheet.inputA11y': '自然语言指令',
|
|
75
|
+
'sheet.deleteTaskTitle': '删除任务',
|
|
76
|
+
'sheet.deleteTaskBody': '删除「{title}」?此操作不可撤销。',
|
|
77
|
+
'sheet.deleteTask': '删除',
|
|
78
|
+
'status.running': '进行中',
|
|
79
|
+
'status.success': '完成',
|
|
80
|
+
'status.failed': '失败',
|
|
81
|
+
'status.cancelled': '已取消',
|
|
82
|
+
'kind.user': '用户',
|
|
83
|
+
'kind.plan': '规划',
|
|
84
|
+
'kind.dump': '扫描',
|
|
85
|
+
'kind.find': '定位',
|
|
86
|
+
'kind.tap': '点击',
|
|
87
|
+
'kind.swipe': '滑动',
|
|
88
|
+
'kind.type': '输入',
|
|
89
|
+
'kind.confirm': '确认',
|
|
90
|
+
'kind.info': '信息',
|
|
91
|
+
'kind.error': '错误',
|
|
92
|
+
'resume.note': 'App 重载中断了上一次执行,已自动继续',
|
|
93
|
+
'resume.verifyFirst':
|
|
94
|
+
'注意:App 在上一次执行中途重载了,这个目标可能已经完成。请先观察当前界面判断目标是否已达成;如已达成,直接返回 done(success=true) 并说明依据,不要重复操作。另外,重载前学到的界面文案可能已失效,请以当前界面为准。',
|
|
95
|
+
'progress.running': '执行中…',
|
|
96
|
+
'progress.success': '成功',
|
|
97
|
+
'progress.failed': '失败',
|
|
98
|
+
'progress.cancelled': '已取消',
|
|
99
|
+
'progress.openA11y': '打开会话',
|
|
100
|
+
'progress.stopA11y': '停止当前任务',
|
|
101
|
+
'gate.check': '检查状态',
|
|
102
|
+
'gate.checking': '正在本机检查是否已离开隐私页面…',
|
|
103
|
+
'gate.stillPrivate': '仍在隐私页面,请在宿主中点击下一步并完成操作;离开此页后自动继续',
|
|
104
|
+
'gate.unreadable': '暂时无法确认页面状态,请在宿主中完成操作后再检查',
|
|
105
|
+
'gate.verifyResultFirst': '已将进行中的操作交给用户处理。先核验这次操作的结果,继续剩余步骤;若失败或退回之前的入口/说明页,报告问题并停止,禁止从头重新创建、导入或提交。不能把返回入口当作尚未开始。',
|
|
106
|
+
'gate.replayStopped': '检测到人工接管后再次进入已发起过的操作,已停止,避免重复创建或提交。请先确认上一次操作的结果。',
|
|
107
|
+
'dialog.cancel': '取消',
|
|
108
|
+
'dialog.confirm': '确认',
|
|
109
|
+
'dialog.continue': '继续',
|
|
110
|
+
'dialog.askTitle': '需要你的确认',
|
|
111
|
+
'dialog.askPlaceholder': '输入补充信息',
|
|
112
|
+
'confirm.preflightTitle': '确认执行此任务?',
|
|
113
|
+
'confirm.preflightBody':
|
|
114
|
+
'该操作可能涉及资金或敏感数据:\n「{label}」\n\n确认后将自动执行,过程中可点停止取消。',
|
|
115
|
+
'confirm.inlineTitle': '需要你的确认',
|
|
116
|
+
'confirm.inlineBody': '即将执行敏感操作:{label}',
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const en: Record<MessageKey, string> = {
|
|
120
|
+
...runtimeEn,
|
|
121
|
+
'brand.defaultName': 'Koko',
|
|
122
|
+
'brand.defaultTagline': 'Control this app with natural language',
|
|
123
|
+
'brand.defaultPlaceholder': 'Tell Koko what you want to do…',
|
|
124
|
+
'brand.defaultMark': 'K',
|
|
125
|
+
'sheet.recentTasks': 'Recent tasks',
|
|
126
|
+
'sheet.timeline': 'Activity',
|
|
127
|
+
'sheet.emptyTasks': 'No tasks yet — type a goal below',
|
|
128
|
+
'sheet.emptyNodesTitle': 'No steps yet',
|
|
129
|
+
'sheet.emptyNodesHint': 'After you send a goal, each step shows up here',
|
|
130
|
+
'sheet.send': 'Send',
|
|
131
|
+
'sheet.closeA11y': 'Close chat',
|
|
132
|
+
'sheet.stopA11y': 'Stop current task',
|
|
133
|
+
'sheet.inputA11y': 'Natural language command',
|
|
134
|
+
'sheet.deleteTaskTitle': 'Delete task',
|
|
135
|
+
'sheet.deleteTaskBody': 'Delete “{title}”? This cannot be undone.',
|
|
136
|
+
'sheet.deleteTask': 'Delete',
|
|
137
|
+
'status.running': 'Running',
|
|
138
|
+
'status.success': 'Done',
|
|
139
|
+
'status.failed': 'Failed',
|
|
140
|
+
'status.cancelled': 'Cancelled',
|
|
141
|
+
'kind.user': 'User',
|
|
142
|
+
'kind.plan': 'Plan',
|
|
143
|
+
'kind.dump': 'Scan',
|
|
144
|
+
'kind.find': 'Find',
|
|
145
|
+
'kind.tap': 'Tap',
|
|
146
|
+
'kind.swipe': 'Swipe',
|
|
147
|
+
'kind.type': 'Type',
|
|
148
|
+
'kind.confirm': 'Confirm',
|
|
149
|
+
'kind.info': 'Info',
|
|
150
|
+
'kind.error': 'Error',
|
|
151
|
+
'resume.note': 'A reload interrupted the previous run; continuing it',
|
|
152
|
+
'resume.verifyFirst':
|
|
153
|
+
'Note: the App reloaded partway through the previous run, so this goal may already be complete. Inspect the current screen first and decide whether it is already satisfied; if it is, return done(success=true) with your evidence and change nothing. Labels learned before the reload may no longer exist — trust the current screen.',
|
|
154
|
+
'progress.running': 'Working…',
|
|
155
|
+
'progress.success': 'Done',
|
|
156
|
+
'progress.failed': 'Failed',
|
|
157
|
+
'progress.cancelled': 'Cancelled',
|
|
158
|
+
'progress.openA11y': 'Open chat',
|
|
159
|
+
'progress.stopA11y': 'Stop current task',
|
|
160
|
+
'gate.check': 'Check status',
|
|
161
|
+
'gate.checking': 'Checking locally whether you have left the private screen…',
|
|
162
|
+
'gate.stillPrivate': 'Still on a private screen. Complete the next steps in the app; the assistant resumes after you leave it.',
|
|
163
|
+
'gate.unreadable': 'Unable to confirm the screen. Complete the step in the app, then check again.',
|
|
164
|
+
'gate.verifyResultFirst': 'An in-flight operation was handed to the user. Verify its result and continue remaining steps. If it failed or returned to a previous entry or instruction screen, report the issue and stop. Do not restart creation, import, or submission from the beginning.',
|
|
165
|
+
'gate.replayStopped': 'Stopped a repeated operation after user handoff to avoid duplicate creation or submission. Check the previous operation result first.',
|
|
166
|
+
'dialog.cancel': 'Cancel',
|
|
167
|
+
'dialog.confirm': 'Confirm',
|
|
168
|
+
'dialog.continue': 'Continue',
|
|
169
|
+
'dialog.askTitle': 'We need your input',
|
|
170
|
+
'dialog.askPlaceholder': 'Type a reply',
|
|
171
|
+
'confirm.preflightTitle': 'Run this task?',
|
|
172
|
+
'confirm.preflightBody':
|
|
173
|
+
'This may involve money or sensitive data:\n「{label}」\n\nAfter you confirm, it runs unattended — tap stop to cancel.',
|
|
174
|
+
'confirm.inlineTitle': 'Confirmation needed',
|
|
175
|
+
'confirm.inlineBody': 'About to run a sensitive action: {label}',
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const catalogs: Record<KokoLocale, Record<MessageKey, string>> = { zh, en };
|
|
179
|
+
|
|
180
|
+
export function normalizeLocale(locale?: string | null): KokoLocale {
|
|
181
|
+
if (!locale) return 'en';
|
|
182
|
+
const lower = locale.toLowerCase();
|
|
183
|
+
if (lower.startsWith('zh')) return 'zh';
|
|
184
|
+
if (lower.startsWith('en')) return 'en';
|
|
185
|
+
return 'en';
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function gatewayLocale(locale: KokoLocale): string {
|
|
189
|
+
return locale === 'zh' ? 'zh-CN' : 'en-US';
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function t(
|
|
193
|
+
locale: KokoLocale,
|
|
194
|
+
key: MessageKey,
|
|
195
|
+
vars?: Record<string, string | number>,
|
|
196
|
+
): string {
|
|
197
|
+
const table = catalogs[locale] ?? catalogs.en;
|
|
198
|
+
let out = table[key] ?? catalogs.en[key] ?? key;
|
|
199
|
+
if (vars) {
|
|
200
|
+
for (const [k, v] of Object.entries(vars)) {
|
|
201
|
+
out = out.replace(new RegExp(`\\{${k}\\}`, 'g'), () => String(v));
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return out;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
export type MessageVars = Record<string, string | number>;
|
|
209
|
+
export type LocalizedMessage = {
|
|
210
|
+
readonly kokoMessage: true;
|
|
211
|
+
readonly key: MessageKey;
|
|
212
|
+
readonly vars?: MessageVars;
|
|
213
|
+
readonly fallbackLocale?: string;
|
|
214
|
+
};
|
|
215
|
+
export type LocalizedText = string | LocalizedMessage;
|
|
216
|
+
|
|
217
|
+
/** Resolve at use time so an in-flight task follows host language changes. */
|
|
218
|
+
export function currentLocale(fallbackLocale?: string | null): KokoLocale {
|
|
219
|
+
return normalizeLocale(HostAppearanceStore.get().locale ?? fallbackLocale);
|
|
220
|
+
}
|
|
221
|
+
export function message(key: MessageKey, vars?: MessageVars, fallbackLocale?: string): LocalizedMessage {
|
|
222
|
+
return { kokoMessage: true, key, vars, fallbackLocale };
|
|
223
|
+
}
|
|
224
|
+
export function resolveText(value: LocalizedText): string {
|
|
225
|
+
return typeof value === 'string' ? value : t(currentLocale(value.fallbackLocale), value.key, value.vars);
|
|
226
|
+
}
|
|
227
|
+
export function runtimeText(key: MessageKey, vars?: MessageVars, fallbackLocale?: string | null): string {
|
|
228
|
+
return t(currentLocale(fallbackLocale), key, vars);
|
|
229
|
+
}
|