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