@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,854 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { Platform } from 'react-native';
|
|
4
|
+
import { runPreflightConfirm } from "../confirmation/gate.js";
|
|
5
|
+
import { viewTreeOutline } from "../privacy/redact.js";
|
|
6
|
+
import { sensitiveScreenKind, SensitiveScreenError } from "../privacy/sensitiveScreen.js";
|
|
7
|
+
import { screenModelText, screenSnapshotLine, extractAffordances } from "../privacy/screenModel.js";
|
|
8
|
+
import { HostActionsStore, filterVisibleHostActions, hostActionsModelText } from "../host/HostActions.js";
|
|
9
|
+
import { AppUserGateStore, detectAppUserGate, gateMessageValue, userGateModelText } from "../privacy/userGate.js";
|
|
10
|
+
import { GatewayClient, GatewayError } from "./GatewayClient.js";
|
|
11
|
+
import { UsageBus } from "../commercial/UsageBus.js";
|
|
12
|
+
import { AccountStore } from "../commercial/AccountStore.js";
|
|
13
|
+
import { ExecutionGuard } from "../commercial/ExecutionGuard.js";
|
|
14
|
+
import { AgentDebug } from "../commercial/AgentDebug.js";
|
|
15
|
+
import { scrollPosition } from "../native/scrollViewport.js";
|
|
16
|
+
import { TaskStore } from "../task/TaskStore.js";
|
|
17
|
+
import { isLooping } from "./loopDetect.js";
|
|
18
|
+
import { ExplorationGraph, exploreHintsModelText, goalExploreQuery } from "../explore/ExplorationGraph.js";
|
|
19
|
+
import { RunCheckpoint } from "./RunCheckpoint.js";
|
|
20
|
+
import { ActionOutcomeUnknownError, ActionValidationError } from "./ActionOutcomeUnknownError.js";
|
|
21
|
+
import { OperationReplayGuard } from "./OperationReplayGuard.js";
|
|
22
|
+
import { recentSearchAction } from "./recentSearch.js";
|
|
23
|
+
import { webResultCategory } from "./webResultCategory.js";
|
|
24
|
+
import { wrongHostWalletChoice } from "./walletChoiceGuard.js";
|
|
25
|
+
import { currentLocale, gatewayLocale, runtimeText, message, resolveText } from "../i18n/index.js";
|
|
26
|
+
import { buildOnDeviceAssist } from "../assist/OnDeviceAssist.js";
|
|
27
|
+
import { NativeBridge } from "../native/NativeBridge.js";
|
|
28
|
+
import { webVisualChanged, webVisualLabels } from "../assist/webVisualChange.js";
|
|
29
|
+
import { ocrHitInFrames, visibleWebViewFrames } from "../assist/ocrTarget.js";
|
|
30
|
+
|
|
31
|
+
/** Soft ETA-style start; extend while progressing. Absolute safety wall only. */
|
|
32
|
+
const SOFT_MAX_STEPS = 40;
|
|
33
|
+
const HARD_MAX_STEPS = 200;
|
|
34
|
+
function affordanceLabels(tree) {
|
|
35
|
+
if (!tree) return [];
|
|
36
|
+
return extractAffordances(tree, 40).map(a => a.label);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Cursor-like session with:
|
|
40
|
+
* - Preflight risk confirm (before loop)
|
|
41
|
+
* - Unattended execution (stop only)
|
|
42
|
+
* - Pause when App shows password/PIN/OTP until user finishes
|
|
43
|
+
*/
|
|
44
|
+
export class AgentSession {
|
|
45
|
+
history = [];
|
|
46
|
+
stopped = false;
|
|
47
|
+
running = false;
|
|
48
|
+
operationReplayGuard = new OperationReplayGuard();
|
|
49
|
+
constructor(agent, opts) {
|
|
50
|
+
this.agent = agent;
|
|
51
|
+
this.gateway = new GatewayClient({
|
|
52
|
+
token: opts.token,
|
|
53
|
+
baseUrl: opts.baseUrl
|
|
54
|
+
});
|
|
55
|
+
this.opts = opts;
|
|
56
|
+
}
|
|
57
|
+
stop() {
|
|
58
|
+
this.stopped = true;
|
|
59
|
+
this.agent.cancelPendingActions();
|
|
60
|
+
}
|
|
61
|
+
uiLocale() {
|
|
62
|
+
return currentLocale(this.opts.locale ?? this.agent.getConfig().locale);
|
|
63
|
+
}
|
|
64
|
+
text(key, vars) {
|
|
65
|
+
return runtimeText(key, vars, this.opts.locale ?? this.agent.getConfig().locale);
|
|
66
|
+
}
|
|
67
|
+
message(key, vars) {
|
|
68
|
+
return message(key, vars, this.opts.locale ?? this.agent.getConfig().locale);
|
|
69
|
+
}
|
|
70
|
+
assertRunning() {
|
|
71
|
+
if (this.stopped) throw new Error('KokoAgent: task cancelled');
|
|
72
|
+
}
|
|
73
|
+
async run(goal) {
|
|
74
|
+
if (this.running) throw new Error(this.text('runtime.alreadyRunning'));
|
|
75
|
+
const acquired = this.agent.acquireSession(this);
|
|
76
|
+
this.running = true;
|
|
77
|
+
try {
|
|
78
|
+
return await this.runInternal(goal);
|
|
79
|
+
} finally {
|
|
80
|
+
this.running = false;
|
|
81
|
+
if (acquired) this.agent.releaseSession(this);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async runInternal(goal) {
|
|
85
|
+
// A stop issued while runGoal persists its checkpoint must remain effective.
|
|
86
|
+
this.operationReplayGuard.reset();
|
|
87
|
+
this.history = [];
|
|
88
|
+
this.sessionId = undefined;
|
|
89
|
+
// Mark running immediately so host freezeOnBlur stays off across sheet→run gap.
|
|
90
|
+
this.agent.startTask(goal);
|
|
91
|
+
const cfg = this.agent.getConfig();
|
|
92
|
+
AgentDebug.runStart(cfg, goal);
|
|
93
|
+
// Only after startTask: appendNode with no active task invents a task of
|
|
94
|
+
// its own that nothing ever finishes.
|
|
95
|
+
if (this.opts.resumedFromReload) {
|
|
96
|
+
this.agent.log('info', this.message('resume.note'));
|
|
97
|
+
}
|
|
98
|
+
// A resumed run starts blind: the action that reloaded the App probably
|
|
99
|
+
// already achieved the goal, and labels learned before the reload may be
|
|
100
|
+
// gone (a locale change renames every one of them). Without this the
|
|
101
|
+
// planner starts over, fails to re-find its entry point and reports a
|
|
102
|
+
// false failure for work that in fact succeeded. Planner-only — the task
|
|
103
|
+
// title and every goal heuristic keep the user's original wording.
|
|
104
|
+
const plannerGoal = () => this.opts.resumedFromReload ? `${goal}\n\n${this.text('resume.verifyFirst')}` : goal;
|
|
105
|
+
if (this.stopped) {
|
|
106
|
+
this.agent.finishTask('cancelled', this.message('runtime.cancelled'));
|
|
107
|
+
return {
|
|
108
|
+
success: false,
|
|
109
|
+
summary: this.text('runtime.cancelled'),
|
|
110
|
+
steps: 0,
|
|
111
|
+
sessionId: ''
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
const preflightOk = await runPreflightConfirm(goal, cfg.confirmation, cfg.onConfirmSensitive);
|
|
115
|
+
if (!preflightOk || this.stopped) {
|
|
116
|
+
const summary = this.stopped ? this.text('runtime.cancelled') : this.text('runtime.confirmationCancelled');
|
|
117
|
+
this.agent.finishTask('cancelled', summary);
|
|
118
|
+
return {
|
|
119
|
+
success: false,
|
|
120
|
+
summary,
|
|
121
|
+
steps: 0,
|
|
122
|
+
sessionId: ''
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Soft budget extends while making progress; only HARD + isLooping stop a run.
|
|
127
|
+
let stepBudget = SOFT_MAX_STEPS;
|
|
128
|
+
let userReply;
|
|
129
|
+
let awaitingObservationVerdict = false;
|
|
130
|
+
this.agent.activeGoal = goal;
|
|
131
|
+
try {
|
|
132
|
+
// Session + permit before first dump (production soft gate).
|
|
133
|
+
this.assertRunning();
|
|
134
|
+
const began = await this.gateway.beginSession();
|
|
135
|
+
this.assertRunning();
|
|
136
|
+
this.sessionId = began.session_id;
|
|
137
|
+
ExecutionGuard.setPermit(began.execution_permit, began.session_id);
|
|
138
|
+
const initialGate = await this.waitForAppUserGateIfNeeded();
|
|
139
|
+
if (initialGate === 'stopped' || initialGate === 'timeout') {
|
|
140
|
+
const summary = initialGate === 'stopped' ? this.text('runtime.cancelled') : this.text('runtime.gateTimeout');
|
|
141
|
+
this.agent.finishTask(initialGate === 'stopped' ? 'cancelled' : 'failed', summary);
|
|
142
|
+
return {
|
|
143
|
+
success: false,
|
|
144
|
+
summary,
|
|
145
|
+
steps: 0,
|
|
146
|
+
sessionId: this.sessionId || ''
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
await ExplorationGraph.ensureLoaded();
|
|
150
|
+
this.assertRunning();
|
|
151
|
+
const exploreQuery = goalExploreQuery(goal);
|
|
152
|
+
|
|
153
|
+
// Learned paths are suggestions in the screen model. Every action still
|
|
154
|
+
// goes through the planner, current-screen guards and result observation.
|
|
155
|
+
|
|
156
|
+
for (let step = 0; step < HARD_MAX_STEPS; step++) {
|
|
157
|
+
// Age of the checkpoint gates resume, so it has to track liveness
|
|
158
|
+
// rather than when the run began.
|
|
159
|
+
void RunCheckpoint.touch().catch(() => {});
|
|
160
|
+
if (this.stopped) {
|
|
161
|
+
this.agent.finishTask('cancelled', this.message('runtime.cancelled'));
|
|
162
|
+
return {
|
|
163
|
+
success: false,
|
|
164
|
+
summary: this.text('runtime.cancelled'),
|
|
165
|
+
steps: this.history.length,
|
|
166
|
+
sessionId: this.sessionId || ''
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Still progressing → extend soft budget (KokoAgent-style).
|
|
171
|
+
if (step >= stepBudget && stepBudget < HARD_MAX_STEPS && !isLooping(this.history)) {
|
|
172
|
+
stepBudget = Math.min(HARD_MAX_STEPS, stepBudget + 8);
|
|
173
|
+
this.agent.log('info', this.message('runtime.progressBudget', {
|
|
174
|
+
steps: stepBudget
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// App-owned auth: wait for user, do not open Koko Q&A.
|
|
179
|
+
const gateWait = await this.waitForAppUserGateIfNeeded();
|
|
180
|
+
if (gateWait === 'stopped') {
|
|
181
|
+
this.agent.finishTask('cancelled', this.message('runtime.cancelled'));
|
|
182
|
+
return {
|
|
183
|
+
success: false,
|
|
184
|
+
summary: this.text('runtime.cancelled'),
|
|
185
|
+
steps: this.history.length,
|
|
186
|
+
sessionId: this.sessionId || ''
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
if (gateWait === 'timeout') {
|
|
190
|
+
this.agent.finishTask('failed', this.message('runtime.gateTimeout'));
|
|
191
|
+
return {
|
|
192
|
+
success: false,
|
|
193
|
+
summary: this.text('runtime.gateTimeout'),
|
|
194
|
+
steps: this.history.length,
|
|
195
|
+
sessionId: this.sessionId || ''
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
const tree = await this.safeDump();
|
|
199
|
+
this.assertRunning();
|
|
200
|
+
// The screen can change between the gate poll and this dump. Do not
|
|
201
|
+
// run OCR or construct a cloud request for a newly presented gate.
|
|
202
|
+
if (detectAppUserGate(tree)) {
|
|
203
|
+
step--;
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
this.agent.setPlanningTree(tree);
|
|
207
|
+
const outline = tree ? viewTreeOutline(tree) : undefined;
|
|
208
|
+
const gate = detectAppUserGate(tree);
|
|
209
|
+
const visibleHosts = filterVisibleHostActions(HostActionsStore.getActions(), tree);
|
|
210
|
+
const exploreHints = tree ? ExplorationGraph.hintLabelsTowardGoal(affordanceLabels(tree), exploreQuery.targetTokens, 6) : [];
|
|
211
|
+
// On-device assist (JS intent/rank + iOS Vision/Core ML OCR) enriches
|
|
212
|
+
// the planner model; cloud LLM still owns action planning.
|
|
213
|
+
const assist = await buildOnDeviceAssist(goal, tree);
|
|
214
|
+
this.assertRunning();
|
|
215
|
+
let hostWalletAliases = cfg.webWalletAliases || [];
|
|
216
|
+
if (assist.walletChoices?.length && hostWalletAliases.length && tree) {
|
|
217
|
+
const frame = visibleWebViewFrames(tree)[0];
|
|
218
|
+
if (frame) {
|
|
219
|
+
try {
|
|
220
|
+
const flags = await NativeBridge.inspectWebWalletProvider({
|
|
221
|
+
x: frame.x + frame.width / 2,
|
|
222
|
+
y: frame.y + frame.height / 2
|
|
223
|
+
});
|
|
224
|
+
if (flags && (!flags.present || !flags.hasRequest)) hostWalletAliases = [];else if (flags && !flags.isMetaMask) hostWalletAliases = hostWalletAliases.filter(alias => alias !== 'MetaMask');
|
|
225
|
+
} catch {
|
|
226
|
+
// A failed provider inspection is not evidence of an injected wallet.
|
|
227
|
+
hostWalletAliases = [];
|
|
228
|
+
}
|
|
229
|
+
this.assertRunning();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
const hostModel = [hostActionsModelText(visibleHosts), exploreHintsModelText(exploreHints), userGateModelText(gate), assist.modelText].filter(Boolean).join('\n');
|
|
233
|
+
const model = tree ? screenModelText(tree, 40, hostModel || undefined) : hostModel || undefined;
|
|
234
|
+
if (assist.modelText && AgentDebug.enabled(cfg)) {
|
|
235
|
+
// eslint-disable-next-line no-console
|
|
236
|
+
console.log(`[koko] on-device assist: intent=${assist.intent} backend=${assist.backend} ranked=${assist.ranked.length} ocr=${assist.ocrTokens.length}`);
|
|
237
|
+
}
|
|
238
|
+
// Debug: what raw texts did native dump actually return?
|
|
239
|
+
if (tree && AgentDebug.enabled(cfg)) {
|
|
240
|
+
const texts = [];
|
|
241
|
+
const walk = n => {
|
|
242
|
+
const t = (n.text || n.accessibilityLabel || '').trim();
|
|
243
|
+
if (t && t.length <= 40) texts.push(t);
|
|
244
|
+
if (n.testID) texts.push(`#${n.testID}`);
|
|
245
|
+
for (const c of n.children) walk(c);
|
|
246
|
+
};
|
|
247
|
+
walk(tree);
|
|
248
|
+
const uniq = [...new Set(texts)].slice(0, 40);
|
|
249
|
+
// eslint-disable-next-line no-console
|
|
250
|
+
console.log(`[koko] dump texts (${uniq.length}): ${uniq.join(' · ').slice(0, 500)}`);
|
|
251
|
+
}
|
|
252
|
+
AgentDebug.screenCapabilities(cfg, tree);
|
|
253
|
+
const planningLocale = gatewayLocale(this.uiLocale());
|
|
254
|
+
let next;
|
|
255
|
+
try {
|
|
256
|
+
next = await this.nextWithRetry({
|
|
257
|
+
session_id: this.sessionId,
|
|
258
|
+
goal: this.operationReplayGuard.hasHandoff ? `${plannerGoal()}\n\n${this.text('gate.verifyResultFirst')}` : plannerGoal(),
|
|
259
|
+
ui_tree: tree || undefined,
|
|
260
|
+
ui_outline: outline,
|
|
261
|
+
ui_screen_model: model,
|
|
262
|
+
local_ocr_goal_labels: assist.goalOcrLabels,
|
|
263
|
+
local_ocr_wallet_choices: assist.walletChoices,
|
|
264
|
+
local_web_wallet_aliases: hostWalletAliases,
|
|
265
|
+
history: this.history,
|
|
266
|
+
locale: planningLocale,
|
|
267
|
+
user_reply: userReply,
|
|
268
|
+
platform: Platform.OS === 'ios' ? 'ios' : Platform.OS === 'android' ? 'android' : 'unknown'
|
|
269
|
+
});
|
|
270
|
+
} catch (error) {
|
|
271
|
+
if (error instanceof SensitiveScreenError) {
|
|
272
|
+
this.operationReplayGuard.markHandoff();
|
|
273
|
+
this.history = [];
|
|
274
|
+
step--;
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
throw error;
|
|
278
|
+
}
|
|
279
|
+
this.assertRunning();
|
|
280
|
+
userReply = undefined;
|
|
281
|
+
this.sessionId = next.session_id;
|
|
282
|
+
ExecutionGuard.setPermit(next.execution_permit, next.session_id);
|
|
283
|
+
// A response planned in the previous language must not put stale
|
|
284
|
+
// narration/questions/results back into the live progress UI.
|
|
285
|
+
if (planningLocale !== gatewayLocale(this.uiLocale())) {
|
|
286
|
+
this.pushHistory({
|
|
287
|
+
tool: 'dump',
|
|
288
|
+
args: {}
|
|
289
|
+
}, this.text('runtime.localeChanged'), false);
|
|
290
|
+
step--;
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
UsageBus.emit({
|
|
294
|
+
type: 'agent_step',
|
|
295
|
+
sessionId: next.session_id,
|
|
296
|
+
step: next.step,
|
|
297
|
+
tool: next.action.tool,
|
|
298
|
+
at: Date.now()
|
|
299
|
+
});
|
|
300
|
+
AgentDebug.appAction(cfg, next.step, next.action.tool, actionDetail(next.action));
|
|
301
|
+
|
|
302
|
+
// After repeated read-only observations, the gateway may only return a
|
|
303
|
+
// final evidence-based verdict. Never turn this review into another act.
|
|
304
|
+
if (awaitingObservationVerdict && next.action.tool !== 'done') {
|
|
305
|
+
this.agent.finishTask('failed', this.message('runtime.loopStopped'));
|
|
306
|
+
return {
|
|
307
|
+
success: false,
|
|
308
|
+
summary: this.text('runtime.loopStopped'),
|
|
309
|
+
steps: this.history.length,
|
|
310
|
+
sessionId: this.sessionId || ''
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
let recentAction = recentSearchAction(next.action, tree, goal) || (!awaitingObservationVerdict ? webResultCategory(next.action, tree, goal, this.history) : null);
|
|
314
|
+
let hostWalletChoice = false;
|
|
315
|
+
if (!recentAction && !awaitingObservationVerdict && next.action.tool === 'dump' && tree && assist.walletChoices?.length) {
|
|
316
|
+
const aliases = hostWalletAliases.filter(alias => assist.walletChoices.includes(alias));
|
|
317
|
+
const alias = aliases.length === 1 ? aliases[0] : undefined;
|
|
318
|
+
const attempted = alias && this.history.some(item => item.tool === 'tap' && String(item.args?.label || '').toLocaleLowerCase().includes(alias.toLocaleLowerCase()));
|
|
319
|
+
if (alias && !attempted) {
|
|
320
|
+
const target = await this.agent.find({
|
|
321
|
+
match: [{
|
|
322
|
+
text: alias,
|
|
323
|
+
exact: true
|
|
324
|
+
}]
|
|
325
|
+
}, tree);
|
|
326
|
+
this.assertRunning();
|
|
327
|
+
if (target && ocrHitInFrames({
|
|
328
|
+
text: alias,
|
|
329
|
+
confidence: 1,
|
|
330
|
+
frame: target.frame
|
|
331
|
+
}, visibleWebViewFrames(tree))) {
|
|
332
|
+
recentAction = {
|
|
333
|
+
tool: 'tap',
|
|
334
|
+
args: {
|
|
335
|
+
nodeId: target.id,
|
|
336
|
+
label: alias
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
hostWalletChoice = true;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (recentAction) {
|
|
344
|
+
this.agent.log('info', gatewayLocale(this.uiLocale()) === 'zh' ? hostWalletChoice ? '选择宿主钱包入口。' : next.action.tool === 'type' ? '使用匹配的最近搜索。' : '选择相关应用分类。' : hostWalletChoice ? 'Selecting the host wallet.' : next.action.tool === 'type' ? 'Using the matching recent search.' : 'Selecting the relevant app category.');
|
|
345
|
+
} else if (next.narration) {
|
|
346
|
+
this.opts.onNarration?.(next.narration);
|
|
347
|
+
this.agent.log('info', next.narration);
|
|
348
|
+
}
|
|
349
|
+
const action = recentAction || next.action;
|
|
350
|
+
if (wrongHostWalletChoice(goal, action, assist.walletChoices || [], hostWalletAliases, action.tool === 'tap' ? this.agent.observedOcrLabel(action.args.nodeId) : undefined)) {
|
|
351
|
+
this.pushHistory(action, 'Host wallet does not match this option; select the configured host wallet or try another browser mode.', false);
|
|
352
|
+
if (isLooping(this.history)) {
|
|
353
|
+
this.agent.finishTask('failed', this.message('runtime.loopStopped'));
|
|
354
|
+
return {
|
|
355
|
+
success: false,
|
|
356
|
+
summary: this.text('runtime.loopStopped'),
|
|
357
|
+
steps: this.history.length,
|
|
358
|
+
sessionId: this.sessionId || ''
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
if (action.tool === 'done') {
|
|
364
|
+
this.pushHistory(action, action.args.summary, action.args.success);
|
|
365
|
+
this.agent.finishTask(action.args.success ? 'success' : 'failed', action.args.summary);
|
|
366
|
+
AgentDebug.runEnd(cfg, action.args.summary, action.args.success);
|
|
367
|
+
return {
|
|
368
|
+
success: action.args.success,
|
|
369
|
+
summary: action.args.summary,
|
|
370
|
+
steps: this.history.length,
|
|
371
|
+
sessionId: this.sessionId
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
if (action.tool === 'ask_user') {
|
|
375
|
+
this.agent.log('info', this.message('runtime.waitForApp', {
|
|
376
|
+
request: action.args.question
|
|
377
|
+
}));
|
|
378
|
+
this.opts.onNarration?.(this.text('runtime.waitForApp', {
|
|
379
|
+
request: action.args.question
|
|
380
|
+
}));
|
|
381
|
+
const w = await this.waitForAppUserGateIfNeeded({
|
|
382
|
+
forceMessage: action.args.question,
|
|
383
|
+
minWaitMs: 1500
|
|
384
|
+
});
|
|
385
|
+
this.pushHistory(action, w === 'cleared' ? this.text('runtime.userContinued') : w === 'timeout' ? this.text('runtime.userTimeout') : this.text('runtime.cancelled'), w === 'cleared');
|
|
386
|
+
if (w === 'stopped' || w === 'timeout') {
|
|
387
|
+
const summary = w === 'stopped' ? this.text('runtime.cancelled') : this.text('runtime.userTimeout');
|
|
388
|
+
this.agent.finishTask(w === 'stopped' ? 'cancelled' : 'failed', summary);
|
|
389
|
+
return {
|
|
390
|
+
success: false,
|
|
391
|
+
summary,
|
|
392
|
+
steps: this.history.length,
|
|
393
|
+
sessionId: this.sessionId
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
if (isLooping(this.history)) {
|
|
397
|
+
this.agent.finishTask('failed', this.message('runtime.loopStopped'));
|
|
398
|
+
return {
|
|
399
|
+
success: false,
|
|
400
|
+
summary: this.text('runtime.loopStopped'),
|
|
401
|
+
steps: this.history.length,
|
|
402
|
+
sessionId: this.sessionId
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
userReply = this.text('runtime.userContinued');
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
const beforeSnap = tree ? screenSnapshotLine(tree) : '';
|
|
409
|
+
const webTap = action.tool === 'tap' && Boolean(action.args.nodeId?.startsWith('ocr:'));
|
|
410
|
+
const beforeWeb = webTap ? await this.webVisualLabels(tree) : null;
|
|
411
|
+
this.assertRunning();
|
|
412
|
+
const beforeLabels = affordanceLabels(tree);
|
|
413
|
+
if (this.operationReplayGuard.blocks(action, tree)) {
|
|
414
|
+
const summary = this.text('gate.replayStopped');
|
|
415
|
+
this.agent.log('info', summary);
|
|
416
|
+
this.agent.finishTask('failed', summary);
|
|
417
|
+
return {
|
|
418
|
+
success: false,
|
|
419
|
+
summary,
|
|
420
|
+
steps: this.history.length,
|
|
421
|
+
sessionId: this.sessionId || ''
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
const exec = await this.executeWithRetry(action);
|
|
425
|
+
this.assertRunning();
|
|
426
|
+
if (exec.ok) this.operationReplayGuard.record(action, tree);
|
|
427
|
+
// Let host animations / navigation commit before noop detection.
|
|
428
|
+
if (action.tool === 'tap' || action.tool === 'swipe' || action.tool === 'type') {
|
|
429
|
+
await sleep(280);
|
|
430
|
+
}
|
|
431
|
+
let after = await this.safeDump();
|
|
432
|
+
this.assertRunning();
|
|
433
|
+
let snap = after ? screenSnapshotLine(after) : '';
|
|
434
|
+
// Dump raced navigation / host async work — give UI one more beat.
|
|
435
|
+
if (action.tool === 'tap' && exec.ok && beforeSnap && snap && beforeSnap === snap) {
|
|
436
|
+
await sleep(550);
|
|
437
|
+
after = await this.safeDump();
|
|
438
|
+
this.assertRunning();
|
|
439
|
+
snap = after ? screenSnapshotLine(after) : '';
|
|
440
|
+
}
|
|
441
|
+
// Window subviews stack in the order they were added, so a host sheet
|
|
442
|
+
// that animates in after the action lands above our chrome and buries
|
|
443
|
+
// the progress pill and its stop button. Re-front once the screen has
|
|
444
|
+
// settled, which is the first moment that sheet actually exists.
|
|
445
|
+
TaskStore.liftChrome();
|
|
446
|
+
// Grow on-device exploration graph from successful taps.
|
|
447
|
+
if (action.tool === 'tap' && exec.ok && !sensitiveScreenKind(after)) {
|
|
448
|
+
const tapLabel = String(action.args.label || this.agent.lastTapViaHost?.label || '').trim();
|
|
449
|
+
if (tapLabel) {
|
|
450
|
+
ExplorationGraph.recordTransition(beforeLabels, tapLabel, affordanceLabels(after));
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
let ok = exec.ok;
|
|
454
|
+
if (action.tool === 'swipe' && exec.ok && tree && after && !sensitiveScreenKind(after)) {
|
|
455
|
+
const beforePosition = scrollPosition(tree, action.args.from);
|
|
456
|
+
const afterPosition = scrollPosition(after, action.args.from);
|
|
457
|
+
if (beforePosition && afterPosition) {
|
|
458
|
+
snap += ` scroll_position=${afterPosition}`;
|
|
459
|
+
if (beforePosition === afterPosition) {
|
|
460
|
+
ok = false;
|
|
461
|
+
exec.result = this.text('runtime.scrollNoop');
|
|
462
|
+
} else {
|
|
463
|
+
exec.result = this.text('runtime.scrollChanged');
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
let resultWithObs = snap ? `${exec.result} || ${snap}` : exec.result;
|
|
468
|
+
const changedWeb = webTap && exec.ok ? webVisualChanged(beforeWeb, await this.webVisualLabels(after)) : false;
|
|
469
|
+
this.assertRunning();
|
|
470
|
+
if (changedWeb) resultWithObs = `${exec.result} (web content changed; verify the new state) || ${snap}`;
|
|
471
|
+
// `lastTapViaHost` is only set once the agent has confirmed the host
|
|
472
|
+
// action moved the screen, so it annotates the trace but no longer
|
|
473
|
+
// exempts the step from noop detection.
|
|
474
|
+
const viaHost = Boolean(this.agent.lastTapViaHost);
|
|
475
|
+
if (viaHost && action.tool === 'tap' && exec.ok) {
|
|
476
|
+
resultWithObs = snap ? `${exec.result} (host run) || ${snap}` : `${exec.result} (host run)`;
|
|
477
|
+
}
|
|
478
|
+
if (
|
|
479
|
+
// Tap claimed success but UI fingerprint unchanged → treat as noop so
|
|
480
|
+
// loop detection / planner can escape instead of empty dumping.
|
|
481
|
+
// Skip when both sides are empty — that is dump failure, not a dead tap.
|
|
482
|
+
action.tool === 'tap' && exec.ok && !changedWeb && beforeSnap && snap && beforeSnap === snap && snap !== 'screen: (empty)') {
|
|
483
|
+
ok = false;
|
|
484
|
+
resultWithObs = `tap_noop (screen unchanged) || ${snap}`;
|
|
485
|
+
}
|
|
486
|
+
if (assist.walletChoices?.length) {
|
|
487
|
+
// Only allowlisted public names are kept; no raw OCR or account data.
|
|
488
|
+
resultWithObs += ` || visible wallet options: ${assist.walletChoices.join(', ')}`;
|
|
489
|
+
}
|
|
490
|
+
this.pushHistory(action, resultWithObs, ok);
|
|
491
|
+
if (isLooping(this.history)) {
|
|
492
|
+
const lastThree = this.history.slice(-3);
|
|
493
|
+
if (!awaitingObservationVerdict && lastThree.length === 3 && lastThree.every(h => h.tool === 'dump')) {
|
|
494
|
+
// The last observation may already prove the goal. Ask for one
|
|
495
|
+
// read-only verdict instead of treating a stall as evidence of failure.
|
|
496
|
+
awaitingObservationVerdict = true;
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
this.agent.finishTask('failed', this.message('runtime.loopStopped'));
|
|
500
|
+
AgentDebug.runEnd(cfg, this.text('runtime.loopStopped'), false);
|
|
501
|
+
return {
|
|
502
|
+
success: false,
|
|
503
|
+
summary: this.text('runtime.loopStopped'),
|
|
504
|
+
steps: this.history.length,
|
|
505
|
+
sessionId: this.sessionId || ''
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
await this.waitForAppUserGateIfNeeded();
|
|
509
|
+
}
|
|
510
|
+
this.agent.finishTask('failed', this.message('runtime.stepLimit'));
|
|
511
|
+
return {
|
|
512
|
+
success: false,
|
|
513
|
+
summary: this.text('runtime.stepLimit'),
|
|
514
|
+
steps: this.history.length,
|
|
515
|
+
sessionId: this.sessionId || ''
|
|
516
|
+
};
|
|
517
|
+
} catch (e) {
|
|
518
|
+
if (this.stopped) {
|
|
519
|
+
this.agent.finishTask('cancelled', this.message('runtime.cancelled'));
|
|
520
|
+
return {
|
|
521
|
+
success: false,
|
|
522
|
+
summary: this.text('runtime.cancelled'),
|
|
523
|
+
steps: this.history.length,
|
|
524
|
+
sessionId: this.sessionId || ''
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
const diagnostic = e instanceof Error ? e.message : String(e);
|
|
528
|
+
const copy = e instanceof ActionOutcomeUnknownError || e instanceof ActionValidationError ? e.localizedMessage : this.message('runtime.operationFailed');
|
|
529
|
+
const failureMessage = resolveText(copy);
|
|
530
|
+
if (e instanceof GatewayError && e.code === 'quota_exceeded') {
|
|
531
|
+
UsageBus.emit({
|
|
532
|
+
type: 'quota_exceeded',
|
|
533
|
+
message: failureMessage,
|
|
534
|
+
quota: e.quota,
|
|
535
|
+
at: Date.now()
|
|
536
|
+
});
|
|
537
|
+
if (this.opts.token) {
|
|
538
|
+
void AccountStore.refresh({
|
|
539
|
+
token: this.opts.token,
|
|
540
|
+
baseUrl: this.opts.baseUrl
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
AgentDebug.runIssue(cfg, diagnostic);
|
|
545
|
+
this.agent.log('error', copy);
|
|
546
|
+
this.agent.finishTask('failed', copy);
|
|
547
|
+
return {
|
|
548
|
+
success: false,
|
|
549
|
+
summary: failureMessage,
|
|
550
|
+
steps: this.history.length,
|
|
551
|
+
sessionId: this.sessionId || ''
|
|
552
|
+
};
|
|
553
|
+
} finally {
|
|
554
|
+
this.agent.activeGoal = undefined;
|
|
555
|
+
ExecutionGuard.clear();
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
pushHistory(action, result, ok) {
|
|
559
|
+
this.history.push({
|
|
560
|
+
tool: action.tool,
|
|
561
|
+
args: 'args' in action ? action.args : undefined,
|
|
562
|
+
result,
|
|
563
|
+
ok
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/** Retry transient upstream / network failures so a completed UI goal is not
|
|
568
|
+
* marked failed just because the next planning round could not reach the LLM. */
|
|
569
|
+
async nextWithRetry(body) {
|
|
570
|
+
const maxAttempts = 3;
|
|
571
|
+
let last;
|
|
572
|
+
for (let i = 0; i < maxAttempts; i++) {
|
|
573
|
+
this.assertRunning();
|
|
574
|
+
try {
|
|
575
|
+
const result = await this.gateway.next(body);
|
|
576
|
+
this.assertRunning();
|
|
577
|
+
return result;
|
|
578
|
+
} catch (e) {
|
|
579
|
+
this.assertRunning();
|
|
580
|
+
last = e;
|
|
581
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
582
|
+
const status = e instanceof GatewayError ? e.status : 0;
|
|
583
|
+
const retryable = status === 502 || status === 503 || status === 504 || /fetch failed|network request failed|ECONNRESET|ETIMEDOUT|upstream_failed|socket/i.test(msg);
|
|
584
|
+
if (!retryable || i === maxAttempts - 1) throw e;
|
|
585
|
+
AgentDebug.runIssue(this.agent.getConfig(), this.text('runtime.gatewayRetry', {
|
|
586
|
+
attempt: i + 1,
|
|
587
|
+
total: maxAttempts - 1
|
|
588
|
+
}));
|
|
589
|
+
await sleep(500 * (i + 1));
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
throw last;
|
|
593
|
+
}
|
|
594
|
+
async safeDump() {
|
|
595
|
+
try {
|
|
596
|
+
let tree = await this.agent.dump({
|
|
597
|
+
silent: true
|
|
598
|
+
});
|
|
599
|
+
if (sensitiveScreenKind(tree)) return tree;
|
|
600
|
+
// Loading / transition settle: empty screens often need a beat.
|
|
601
|
+
for (let i = 0; i < 3; i++) {
|
|
602
|
+
const items = tree ? extractAffordances(tree, 8) : [];
|
|
603
|
+
if (items.length > 0) break;
|
|
604
|
+
await sleep(350);
|
|
605
|
+
if (this.stopped) break;
|
|
606
|
+
tree = await this.agent.dump({
|
|
607
|
+
silent: true
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
return tree;
|
|
611
|
+
} catch {
|
|
612
|
+
return null;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
async webVisualLabels(tree) {
|
|
616
|
+
if (!tree || sensitiveScreenKind(tree) || !NativeBridge.isAvailable()) return null;
|
|
617
|
+
try {
|
|
618
|
+
const ocr = await NativeBridge.recognizeScreenText({
|
|
619
|
+
maxTokens: 64,
|
|
620
|
+
hideOverlays: true
|
|
621
|
+
});
|
|
622
|
+
return webVisualLabels(tree, ocr.texts || []);
|
|
623
|
+
} catch {
|
|
624
|
+
return null;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* When the App presents credentials or recovery material, wait locally.
|
|
630
|
+
* Koko does not collect secrets — user types in the App UI.
|
|
631
|
+
*/
|
|
632
|
+
async waitForAppUserGateIfNeeded(opts) {
|
|
633
|
+
const tree = await this.safeDump();
|
|
634
|
+
const gate = tree ? detectAppUserGate(tree) : detectAppUserGate(null);
|
|
635
|
+
if (!gate && !opts?.forceMessage) return 'none';
|
|
636
|
+
if (sensitiveScreenKind(tree)) {
|
|
637
|
+
this.operationReplayGuard.markHandoff();
|
|
638
|
+
this.history = [];
|
|
639
|
+
}
|
|
640
|
+
const msg = gate ? gateMessageValue(gate, this.opts.locale ?? this.agent.getConfig().locale) : opts?.forceMessage ? this.message('runtime.waitForApp', {
|
|
641
|
+
request: opts.forceMessage
|
|
642
|
+
}) : this.message('runtime.inputInApp');
|
|
643
|
+
this.agent.log('info', msg);
|
|
644
|
+
this.opts.onNarration?.(resolveText(msg));
|
|
645
|
+
TaskStore.setUserGateWaiting(msg);
|
|
646
|
+
const waitNode = TaskStore.appendNode({
|
|
647
|
+
kind: 'confirm',
|
|
648
|
+
title: msg,
|
|
649
|
+
status: 'running'
|
|
650
|
+
});
|
|
651
|
+
const timeout = this.opts.userGateTimeoutMs ?? 300_000;
|
|
652
|
+
const pollMs = 700;
|
|
653
|
+
const started = Date.now();
|
|
654
|
+
const minWait = opts?.minWaitMs ?? 0;
|
|
655
|
+
let checkedResumeAt = started;
|
|
656
|
+
let fingerprint = gate ? `${gate.kind}:${gate.nodeId}:${gate.label}` : `force:${opts?.forceMessage ?? ''}`;
|
|
657
|
+
try {
|
|
658
|
+
while (Date.now() - started < timeout) {
|
|
659
|
+
if (this.stopped) return 'stopped';
|
|
660
|
+
await sleep(pollMs);
|
|
661
|
+
if (this.stopped) return 'stopped';
|
|
662
|
+
|
|
663
|
+
// A status check is not permission to bypass a still-private page.
|
|
664
|
+
if (AppUserGateStore.wasManuallyResumedSince(checkedResumeAt)) {
|
|
665
|
+
checkedResumeAt = Date.now() + 1;
|
|
666
|
+
const current = await this.safeDump();
|
|
667
|
+
if (current && !sensitiveScreenKind(current) && !AppUserGateStore.getHostGate()) {
|
|
668
|
+
TaskStore.updateNode(waitNode.id, {
|
|
669
|
+
status: 'done',
|
|
670
|
+
title: this.message('runtime.gateConfirmed')
|
|
671
|
+
});
|
|
672
|
+
return 'cleared';
|
|
673
|
+
}
|
|
674
|
+
const feedback = this.message(current ? 'gate.stillPrivate' : 'gate.unreadable');
|
|
675
|
+
TaskStore.setUserGateWaiting(feedback);
|
|
676
|
+
TaskStore.updateNode(waitNode.id, {
|
|
677
|
+
title: feedback
|
|
678
|
+
});
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
const now = await this.safeDump();
|
|
682
|
+
if (!now) continue;
|
|
683
|
+
const g2 = detectAppUserGate(now);
|
|
684
|
+
if (!g2) {
|
|
685
|
+
if (Date.now() - started >= minWait) {
|
|
686
|
+
TaskStore.updateNode(waitNode.id, {
|
|
687
|
+
status: 'done',
|
|
688
|
+
title: this.message('runtime.gateCompleted')
|
|
689
|
+
});
|
|
690
|
+
return 'cleared';
|
|
691
|
+
}
|
|
692
|
+
continue;
|
|
693
|
+
}
|
|
694
|
+
const fp2 = `${g2.kind}:${g2.nodeId}:${g2.label}`;
|
|
695
|
+
if (fp2 !== fingerprint) {
|
|
696
|
+
fingerprint = fp2;
|
|
697
|
+
const nextMsg = gateMessageValue(g2, this.opts.locale ?? this.agent.getConfig().locale);
|
|
698
|
+
this.opts.onNarration?.(resolveText(nextMsg));
|
|
699
|
+
TaskStore.setUserGateWaiting(nextMsg);
|
|
700
|
+
TaskStore.updateNode(waitNode.id, {
|
|
701
|
+
title: nextMsg
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
TaskStore.updateNode(waitNode.id, {
|
|
706
|
+
status: 'failed',
|
|
707
|
+
title: this.message('runtime.gateInputTimeout')
|
|
708
|
+
});
|
|
709
|
+
return 'timeout';
|
|
710
|
+
} finally {
|
|
711
|
+
TaskStore.setUserGateWaiting(null);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
async executeWithRetry(action) {
|
|
715
|
+
// Only observations are safe to repeat after an exception. A rejected
|
|
716
|
+
// native promise or timed-out host callback can follow a committed action.
|
|
717
|
+
const readOnly = action.tool === 'dump' || action.tool === 'find';
|
|
718
|
+
const configured = this.opts.localRetries ?? 3;
|
|
719
|
+
const retries = readOnly && Number.isFinite(configured) ? Math.max(0, Math.min(3, Math.floor(configured))) : 0;
|
|
720
|
+
let last = '';
|
|
721
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
722
|
+
this.assertRunning();
|
|
723
|
+
try {
|
|
724
|
+
const result = await this.executeOnce(action);
|
|
725
|
+
this.assertRunning();
|
|
726
|
+
return {
|
|
727
|
+
ok: true,
|
|
728
|
+
result
|
|
729
|
+
};
|
|
730
|
+
} catch (e) {
|
|
731
|
+
this.assertRunning();
|
|
732
|
+
last = e instanceof Error ? e.message : String(e);
|
|
733
|
+
if (e instanceof ActionValidationError || e instanceof SensitiveScreenError) {
|
|
734
|
+
// The action was rejected before dispatch; let the planner observe
|
|
735
|
+
// and choose a different target without replaying a real touch.
|
|
736
|
+
return {
|
|
737
|
+
ok: false,
|
|
738
|
+
result: `pre_dispatch: ${last}`
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
if (!readOnly) throw e instanceof ActionOutcomeUnknownError ? e : new ActionOutcomeUnknownError(last);
|
|
742
|
+
if (attempt < retries) await sleep(200);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
return {
|
|
746
|
+
ok: false,
|
|
747
|
+
result: last || 'failed'
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
async executeOnce(action) {
|
|
751
|
+
switch (action.tool) {
|
|
752
|
+
case 'dump':
|
|
753
|
+
{
|
|
754
|
+
const tree = await this.agent.dump();
|
|
755
|
+
return `dumped || ${screenSnapshotLine(tree)}`;
|
|
756
|
+
}
|
|
757
|
+
case 'find':
|
|
758
|
+
{
|
|
759
|
+
const selector = {
|
|
760
|
+
match: action.args.match,
|
|
761
|
+
index: action.args.index
|
|
762
|
+
};
|
|
763
|
+
// A model lookup observes the current page; it must not secretly turn
|
|
764
|
+
// into a scroll search before the planner considers visible navigation.
|
|
765
|
+
const currentTree = await this.safeDump();
|
|
766
|
+
if (!currentTree) throw new Error(this.text('runtime.unreadable'));
|
|
767
|
+
const node = await this.agent.find(selector, currentTree);
|
|
768
|
+
if (!node) return 'null';
|
|
769
|
+
return JSON.stringify({
|
|
770
|
+
id: node.id,
|
|
771
|
+
text: node.text,
|
|
772
|
+
accessibilityLabel: node.accessibilityLabel,
|
|
773
|
+
clickable: node.clickable,
|
|
774
|
+
selected: node.selected,
|
|
775
|
+
enabled: node.enabled,
|
|
776
|
+
visible: node.visible,
|
|
777
|
+
secure: node.secure,
|
|
778
|
+
frame: node.frame
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
case 'tap':
|
|
782
|
+
{
|
|
783
|
+
await this.agent.tap({
|
|
784
|
+
selector: action.args.selector,
|
|
785
|
+
nodeId: action.args.nodeId,
|
|
786
|
+
point: action.args.point,
|
|
787
|
+
label: action.args.label,
|
|
788
|
+
options: {
|
|
789
|
+
revealIfNeeded: false
|
|
790
|
+
}
|
|
791
|
+
});
|
|
792
|
+
return `tapped ${action.args.label || action.args.nodeId || 'target'}`;
|
|
793
|
+
}
|
|
794
|
+
case 'swipe':
|
|
795
|
+
{
|
|
796
|
+
await this.agent.swipe(action.args.from, action.args.to);
|
|
797
|
+
return 'swiped';
|
|
798
|
+
}
|
|
799
|
+
case 'pinch':
|
|
800
|
+
{
|
|
801
|
+
await this.agent.pinch(action.args.center, action.args.scale);
|
|
802
|
+
return `pinched scale=${action.args.scale}`;
|
|
803
|
+
}
|
|
804
|
+
case 'type':
|
|
805
|
+
{
|
|
806
|
+
// Never type into secure fields — wait for user instead.
|
|
807
|
+
const root = await this.safeDump();
|
|
808
|
+
this.assertRunning();
|
|
809
|
+
if (root && detectAppUserGate(root)) {
|
|
810
|
+
await this.waitForAppUserGateIfNeeded();
|
|
811
|
+
return 'skipped type: waited for user secure input';
|
|
812
|
+
}
|
|
813
|
+
await this.agent.type(action.args.text, {
|
|
814
|
+
selector: action.args.selector,
|
|
815
|
+
nodeId: action.args.nodeId,
|
|
816
|
+
options: {
|
|
817
|
+
clear: action.args.clear
|
|
818
|
+
},
|
|
819
|
+
label: action.args.label
|
|
820
|
+
});
|
|
821
|
+
return `typed ${action.args.text.slice(0, 40)}`;
|
|
822
|
+
}
|
|
823
|
+
default:
|
|
824
|
+
return 'noop';
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
function actionDetail(action) {
|
|
829
|
+
switch (action.tool) {
|
|
830
|
+
case 'tap':
|
|
831
|
+
return action.args.label;
|
|
832
|
+
case 'type':
|
|
833
|
+
return action.args.label || action.args.text?.slice(0, 24);
|
|
834
|
+
case 'swipe':
|
|
835
|
+
return action.args.label;
|
|
836
|
+
case 'pinch':
|
|
837
|
+
return action.args.label || `×${action.args.scale}`;
|
|
838
|
+
case 'find':
|
|
839
|
+
{
|
|
840
|
+
const first = action.args.match?.[0];
|
|
841
|
+
return first?.text;
|
|
842
|
+
}
|
|
843
|
+
case 'ask_user':
|
|
844
|
+
return action.args.question?.slice(0, 60);
|
|
845
|
+
case 'done':
|
|
846
|
+
return action.args.summary?.slice(0, 80);
|
|
847
|
+
default:
|
|
848
|
+
return undefined;
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
function sleep(ms) {
|
|
852
|
+
return new Promise(r => setTimeout(r, ms));
|
|
853
|
+
}
|
|
854
|
+
//# sourceMappingURL=AgentSession.js.map
|