@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.
Files changed (622) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/CODE_OF_CONDUCT.md +3 -0
  3. package/CONTRIBUTING.md +9 -0
  4. package/LICENSE +21 -0
  5. package/README.md +65 -0
  6. package/README.zh-CN.md +50 -0
  7. package/SECURITY.md +5 -0
  8. package/android/build.gradle +40 -0
  9. package/android/src/main/AndroidManifest.xml +2 -0
  10. package/android/src/main/java/cn/intentcomputing/kokoagentsdk/KokoAgentSdkModule.java +1356 -0
  11. package/android/src/main/java/cn/intentcomputing/kokoagentsdk/KokoAgentSdkPackage.java +23 -0
  12. package/docs/INTEGRATION.md +168 -0
  13. package/docs/INTEGRATION.zh-CN.md +140 -0
  14. package/docs/PRIVACY.md +11 -0
  15. package/docs/PRIVACY.zh-CN.md +11 -0
  16. package/docs/PUBLISH.md +11 -0
  17. package/docs/PUBLISH.zh-CN.md +11 -0
  18. package/ios/KokoAgentSdk/KokoAgentSdk.h +5 -0
  19. package/ios/KokoAgentSdk/KokoAgentSdk.m +2464 -0
  20. package/ios/KokoAgentSdk/KokoOcrBounds.h +20 -0
  21. package/ios/KokoAgentSdk/KokoScrollBounds.h +21 -0
  22. package/koko-agent-sdk.podspec +23 -0
  23. package/lib/commonjs/KokoAgent.js +1427 -0
  24. package/lib/commonjs/KokoAgent.js.map +1 -0
  25. package/lib/commonjs/assist/OnDeviceAssist.js +94 -0
  26. package/lib/commonjs/assist/OnDeviceAssist.js.map +1 -0
  27. package/lib/commonjs/assist/intentClassify.js +100 -0
  28. package/lib/commonjs/assist/intentClassify.js.map +1 -0
  29. package/lib/commonjs/assist/nodeRank.js +120 -0
  30. package/lib/commonjs/assist/nodeRank.js.map +1 -0
  31. package/lib/commonjs/assist/ocrTarget.js +135 -0
  32. package/lib/commonjs/assist/ocrTarget.js.map +1 -0
  33. package/lib/commonjs/assist/webVisualChange.js +29 -0
  34. package/lib/commonjs/assist/webVisualChange.js.map +1 -0
  35. package/lib/commonjs/client/ActionOutcomeUnknownError.js +28 -0
  36. package/lib/commonjs/client/ActionOutcomeUnknownError.js.map +1 -0
  37. package/lib/commonjs/client/AgentSession.js +858 -0
  38. package/lib/commonjs/client/AgentSession.js.map +1 -0
  39. package/lib/commonjs/client/GatewayClient.js +302 -0
  40. package/lib/commonjs/client/GatewayClient.js.map +1 -0
  41. package/lib/commonjs/client/OperationReplayGuard.js +62 -0
  42. package/lib/commonjs/client/OperationReplayGuard.js.map +1 -0
  43. package/lib/commonjs/client/RunCheckpoint.js +139 -0
  44. package/lib/commonjs/client/RunCheckpoint.js.map +1 -0
  45. package/lib/commonjs/client/loopDetect.js +184 -0
  46. package/lib/commonjs/client/loopDetect.js.map +1 -0
  47. package/lib/commonjs/client/recentSearch.js +50 -0
  48. package/lib/commonjs/client/recentSearch.js.map +1 -0
  49. package/lib/commonjs/client/walletChoiceGuard.js +18 -0
  50. package/lib/commonjs/client/walletChoiceGuard.js.map +1 -0
  51. package/lib/commonjs/client/webResultCategory.js +38 -0
  52. package/lib/commonjs/client/webResultCategory.js.map +1 -0
  53. package/lib/commonjs/commercial/AccountStore.js +78 -0
  54. package/lib/commonjs/commercial/AccountStore.js.map +1 -0
  55. package/lib/commonjs/commercial/AgentDebug.js +104 -0
  56. package/lib/commonjs/commercial/AgentDebug.js.map +1 -0
  57. package/lib/commonjs/commercial/ExecutionGuard.js +53 -0
  58. package/lib/commonjs/commercial/ExecutionGuard.js.map +1 -0
  59. package/lib/commonjs/commercial/UsageBus.js +42 -0
  60. package/lib/commonjs/commercial/UsageBus.js.map +1 -0
  61. package/lib/commonjs/commercial/branding.js +69 -0
  62. package/lib/commonjs/commercial/branding.js.map +1 -0
  63. package/lib/commonjs/commercial/devMode.js +52 -0
  64. package/lib/commonjs/commercial/devMode.js.map +1 -0
  65. package/lib/commonjs/commercial/trust.js +69 -0
  66. package/lib/commonjs/commercial/trust.js.map +1 -0
  67. package/lib/commonjs/confirmation/gate.js +62 -0
  68. package/lib/commonjs/confirmation/gate.js.map +1 -0
  69. package/lib/commonjs/cursor/CursorOverlay.js +141 -0
  70. package/lib/commonjs/cursor/CursorOverlay.js.map +1 -0
  71. package/lib/commonjs/cursor/PointerHand.js +51 -0
  72. package/lib/commonjs/cursor/PointerHand.js.map +1 -0
  73. package/lib/commonjs/cursor/controller.js +91 -0
  74. package/lib/commonjs/cursor/controller.js.map +1 -0
  75. package/lib/commonjs/cursor/pointer.js +49 -0
  76. package/lib/commonjs/cursor/pointer.js.map +1 -0
  77. package/lib/commonjs/debug/KokoRemoteSmoke.js +611 -0
  78. package/lib/commonjs/debug/KokoRemoteSmoke.js.map +1 -0
  79. package/lib/commonjs/explore/ExplorationGraph.js +418 -0
  80. package/lib/commonjs/explore/ExplorationGraph.js.map +1 -0
  81. package/lib/commonjs/explore/bootstrapExplore.js +59 -0
  82. package/lib/commonjs/explore/bootstrapExplore.js.map +1 -0
  83. package/lib/commonjs/host/HostActions.js +266 -0
  84. package/lib/commonjs/host/HostActions.js.map +1 -0
  85. package/lib/commonjs/i18n/index.js +169 -0
  86. package/lib/commonjs/i18n/index.js.map +1 -0
  87. package/lib/commonjs/i18n/runtimeMessages.js +184 -0
  88. package/lib/commonjs/i18n/runtimeMessages.js.map +1 -0
  89. package/lib/commonjs/index.js +640 -0
  90. package/lib/commonjs/index.js.map +1 -0
  91. package/lib/commonjs/native/NativeBridge.js +132 -0
  92. package/lib/commonjs/native/NativeBridge.js.map +1 -0
  93. package/lib/commonjs/native/navigationLabel.js +16 -0
  94. package/lib/commonjs/native/navigationLabel.js.map +1 -0
  95. package/lib/commonjs/native/normalizeViewTree.js +28 -0
  96. package/lib/commonjs/native/normalizeViewTree.js.map +1 -0
  97. package/lib/commonjs/native/pruneOffscreen.js +76 -0
  98. package/lib/commonjs/native/pruneOffscreen.js.map +1 -0
  99. package/lib/commonjs/native/scrollViewport.js +69 -0
  100. package/lib/commonjs/native/scrollViewport.js.map +1 -0
  101. package/lib/commonjs/package.json +1 -0
  102. package/lib/commonjs/privacy/redact.js +108 -0
  103. package/lib/commonjs/privacy/redact.js.map +1 -0
  104. package/lib/commonjs/privacy/screenEvidence.js +59 -0
  105. package/lib/commonjs/privacy/screenEvidence.js.map +1 -0
  106. package/lib/commonjs/privacy/screenModel.js +404 -0
  107. package/lib/commonjs/privacy/screenModel.js.map +1 -0
  108. package/lib/commonjs/privacy/sensitiveScreen.js +58 -0
  109. package/lib/commonjs/privacy/sensitiveScreen.js.map +1 -0
  110. package/lib/commonjs/privacy/userGate.js +213 -0
  111. package/lib/commonjs/privacy/userGate.js.map +1 -0
  112. package/lib/commonjs/protocol/actions.js +112 -0
  113. package/lib/commonjs/protocol/actions.js.map +1 -0
  114. package/lib/commonjs/provider/HostAppearanceStore.js +111 -0
  115. package/lib/commonjs/provider/HostAppearanceStore.js.map +1 -0
  116. package/lib/commonjs/provider/KokoProvider.js +81 -0
  117. package/lib/commonjs/provider/KokoProvider.js.map +1 -0
  118. package/lib/commonjs/provider/KokoUiContext.js +102 -0
  119. package/lib/commonjs/provider/KokoUiContext.js.map +1 -0
  120. package/lib/commonjs/selector/match.js +378 -0
  121. package/lib/commonjs/selector/match.js.map +1 -0
  122. package/lib/commonjs/task/TaskStore.js +361 -0
  123. package/lib/commonjs/task/TaskStore.js.map +1 -0
  124. package/lib/commonjs/task/types.js +2 -0
  125. package/lib/commonjs/task/types.js.map +1 -0
  126. package/lib/commonjs/task/useTaskStore.js +14 -0
  127. package/lib/commonjs/task/useTaskStore.js.map +1 -0
  128. package/lib/commonjs/types.js +2 -0
  129. package/lib/commonjs/types.js.map +1 -0
  130. package/lib/commonjs/ui/KokoChatSheet.js +885 -0
  131. package/lib/commonjs/ui/KokoChatSheet.js.map +1 -0
  132. package/lib/commonjs/ui/KokoComposer.js +161 -0
  133. package/lib/commonjs/ui/KokoComposer.js.map +1 -0
  134. package/lib/commonjs/ui/KokoDialogHost.js +254 -0
  135. package/lib/commonjs/ui/KokoDialogHost.js.map +1 -0
  136. package/lib/commonjs/ui/KokoEntryButton.js +81 -0
  137. package/lib/commonjs/ui/KokoEntryButton.js.map +1 -0
  138. package/lib/commonjs/ui/KokoObserver.js +522 -0
  139. package/lib/commonjs/ui/KokoObserver.js.map +1 -0
  140. package/lib/commonjs/ui/KokoOverlayLayer.js +45 -0
  141. package/lib/commonjs/ui/KokoOverlayLayer.js.map +1 -0
  142. package/lib/commonjs/ui/KokoSubtitle.js +95 -0
  143. package/lib/commonjs/ui/KokoSubtitle.js.map +1 -0
  144. package/lib/commonjs/ui/KokoTaskPanel.js +322 -0
  145. package/lib/commonjs/ui/KokoTaskPanel.js.map +1 -0
  146. package/lib/commonjs/ui/hostOverlay.js +126 -0
  147. package/lib/commonjs/ui/hostOverlay.js.map +1 -0
  148. package/lib/commonjs/ui/icons.js +132 -0
  149. package/lib/commonjs/ui/icons.js.map +1 -0
  150. package/lib/commonjs/ui/progressChrome.js +66 -0
  151. package/lib/commonjs/ui/progressChrome.js.map +1 -0
  152. package/lib/commonjs/ui/safeArea.js +96 -0
  153. package/lib/commonjs/ui/safeArea.js.map +1 -0
  154. package/lib/commonjs/ui/useOverlayOrigin.js +40 -0
  155. package/lib/commonjs/ui/useOverlayOrigin.js.map +1 -0
  156. package/lib/module/KokoAgent.js +1418 -0
  157. package/lib/module/KokoAgent.js.map +1 -0
  158. package/lib/module/assist/OnDeviceAssist.js +89 -0
  159. package/lib/module/assist/OnDeviceAssist.js.map +1 -0
  160. package/lib/module/assist/intentClassify.js +95 -0
  161. package/lib/module/assist/intentClassify.js.map +1 -0
  162. package/lib/module/assist/nodeRank.js +115 -0
  163. package/lib/module/assist/nodeRank.js.map +1 -0
  164. package/lib/module/assist/ocrTarget.js +123 -0
  165. package/lib/module/assist/ocrTarget.js.map +1 -0
  166. package/lib/module/assist/webVisualChange.js +24 -0
  167. package/lib/module/assist/webVisualChange.js.map +1 -0
  168. package/lib/module/client/ActionOutcomeUnknownError.js +23 -0
  169. package/lib/module/client/ActionOutcomeUnknownError.js.map +1 -0
  170. package/lib/module/client/AgentSession.js +854 -0
  171. package/lib/module/client/AgentSession.js.map +1 -0
  172. package/lib/module/client/GatewayClient.js +293 -0
  173. package/lib/module/client/GatewayClient.js.map +1 -0
  174. package/lib/module/client/OperationReplayGuard.js +58 -0
  175. package/lib/module/client/OperationReplayGuard.js.map +1 -0
  176. package/lib/module/client/RunCheckpoint.js +135 -0
  177. package/lib/module/client/RunCheckpoint.js.map +1 -0
  178. package/lib/module/client/loopDetect.js +177 -0
  179. package/lib/module/client/loopDetect.js.map +1 -0
  180. package/lib/module/client/recentSearch.js +46 -0
  181. package/lib/module/client/recentSearch.js.map +1 -0
  182. package/lib/module/client/walletChoiceGuard.js +14 -0
  183. package/lib/module/client/walletChoiceGuard.js.map +1 -0
  184. package/lib/module/client/webResultCategory.js +34 -0
  185. package/lib/module/client/webResultCategory.js.map +1 -0
  186. package/lib/module/commercial/AccountStore.js +75 -0
  187. package/lib/module/commercial/AccountStore.js.map +1 -0
  188. package/lib/module/commercial/AgentDebug.js +99 -0
  189. package/lib/module/commercial/AgentDebug.js.map +1 -0
  190. package/lib/module/commercial/ExecutionGuard.js +49 -0
  191. package/lib/module/commercial/ExecutionGuard.js.map +1 -0
  192. package/lib/module/commercial/UsageBus.js +38 -0
  193. package/lib/module/commercial/UsageBus.js.map +1 -0
  194. package/lib/module/commercial/branding.js +63 -0
  195. package/lib/module/commercial/branding.js.map +1 -0
  196. package/lib/module/commercial/devMode.js +45 -0
  197. package/lib/module/commercial/devMode.js.map +1 -0
  198. package/lib/module/commercial/trust.js +62 -0
  199. package/lib/module/commercial/trust.js.map +1 -0
  200. package/lib/module/confirmation/gate.js +54 -0
  201. package/lib/module/confirmation/gate.js.map +1 -0
  202. package/lib/module/cursor/CursorOverlay.js +136 -0
  203. package/lib/module/cursor/CursorOverlay.js.map +1 -0
  204. package/lib/module/cursor/PointerHand.js +47 -0
  205. package/lib/module/cursor/PointerHand.js.map +1 -0
  206. package/lib/module/cursor/controller.js +87 -0
  207. package/lib/module/cursor/controller.js.map +1 -0
  208. package/lib/module/cursor/pointer.js +45 -0
  209. package/lib/module/cursor/pointer.js.map +1 -0
  210. package/lib/module/debug/KokoRemoteSmoke.js +608 -0
  211. package/lib/module/debug/KokoRemoteSmoke.js.map +1 -0
  212. package/lib/module/explore/ExplorationGraph.js +406 -0
  213. package/lib/module/explore/ExplorationGraph.js.map +1 -0
  214. package/lib/module/explore/bootstrapExplore.js +55 -0
  215. package/lib/module/explore/bootstrapExplore.js.map +1 -0
  216. package/lib/module/host/HostActions.js +255 -0
  217. package/lib/module/host/HostActions.js.map +1 -0
  218. package/lib/module/i18n/index.js +159 -0
  219. package/lib/module/i18n/index.js.map +1 -0
  220. package/lib/module/i18n/runtimeMessages.js +180 -0
  221. package/lib/module/i18n/runtimeMessages.js.map +1 -0
  222. package/lib/module/index.js +44 -0
  223. package/lib/module/index.js.map +1 -0
  224. package/lib/module/native/NativeBridge.js +128 -0
  225. package/lib/module/native/NativeBridge.js.map +1 -0
  226. package/lib/module/native/navigationLabel.js +12 -0
  227. package/lib/module/native/navigationLabel.js.map +1 -0
  228. package/lib/module/native/normalizeViewTree.js +25 -0
  229. package/lib/module/native/normalizeViewTree.js.map +1 -0
  230. package/lib/module/native/pruneOffscreen.js +72 -0
  231. package/lib/module/native/pruneOffscreen.js.map +1 -0
  232. package/lib/module/native/scrollViewport.js +63 -0
  233. package/lib/module/native/scrollViewport.js.map +1 -0
  234. package/lib/module/package.json +1 -0
  235. package/lib/module/privacy/redact.js +103 -0
  236. package/lib/module/privacy/redact.js.map +1 -0
  237. package/lib/module/privacy/screenEvidence.js +50 -0
  238. package/lib/module/privacy/screenEvidence.js.map +1 -0
  239. package/lib/module/privacy/screenModel.js +397 -0
  240. package/lib/module/privacy/screenModel.js.map +1 -0
  241. package/lib/module/privacy/sensitiveScreen.js +52 -0
  242. package/lib/module/privacy/sensitiveScreen.js.map +1 -0
  243. package/lib/module/privacy/userGate.js +202 -0
  244. package/lib/module/privacy/userGate.js.map +1 -0
  245. package/lib/module/protocol/actions.js +108 -0
  246. package/lib/module/protocol/actions.js.map +1 -0
  247. package/lib/module/provider/HostAppearanceStore.js +101 -0
  248. package/lib/module/provider/HostAppearanceStore.js.map +1 -0
  249. package/lib/module/provider/KokoProvider.js +74 -0
  250. package/lib/module/provider/KokoProvider.js.map +1 -0
  251. package/lib/module/provider/KokoUiContext.js +96 -0
  252. package/lib/module/provider/KokoUiContext.js.map +1 -0
  253. package/lib/module/selector/match.js +366 -0
  254. package/lib/module/selector/match.js.map +1 -0
  255. package/lib/module/task/TaskStore.js +356 -0
  256. package/lib/module/task/TaskStore.js.map +1 -0
  257. package/lib/module/task/types.js +2 -0
  258. package/lib/module/task/types.js.map +1 -0
  259. package/lib/module/task/useTaskStore.js +10 -0
  260. package/lib/module/task/useTaskStore.js.map +1 -0
  261. package/lib/module/types.js +2 -0
  262. package/lib/module/types.js.map +1 -0
  263. package/lib/module/ui/KokoChatSheet.js +879 -0
  264. package/lib/module/ui/KokoChatSheet.js.map +1 -0
  265. package/lib/module/ui/KokoComposer.js +155 -0
  266. package/lib/module/ui/KokoComposer.js.map +1 -0
  267. package/lib/module/ui/KokoDialogHost.js +247 -0
  268. package/lib/module/ui/KokoDialogHost.js.map +1 -0
  269. package/lib/module/ui/KokoEntryButton.js +74 -0
  270. package/lib/module/ui/KokoEntryButton.js.map +1 -0
  271. package/lib/module/ui/KokoObserver.js +516 -0
  272. package/lib/module/ui/KokoObserver.js.map +1 -0
  273. package/lib/module/ui/KokoOverlayLayer.js +39 -0
  274. package/lib/module/ui/KokoOverlayLayer.js.map +1 -0
  275. package/lib/module/ui/KokoSubtitle.js +90 -0
  276. package/lib/module/ui/KokoSubtitle.js.map +1 -0
  277. package/lib/module/ui/KokoTaskPanel.js +316 -0
  278. package/lib/module/ui/KokoTaskPanel.js.map +1 -0
  279. package/lib/module/ui/hostOverlay.js +120 -0
  280. package/lib/module/ui/hostOverlay.js.map +1 -0
  281. package/lib/module/ui/icons.js +124 -0
  282. package/lib/module/ui/icons.js.map +1 -0
  283. package/lib/module/ui/progressChrome.js +58 -0
  284. package/lib/module/ui/progressChrome.js.map +1 -0
  285. package/lib/module/ui/safeArea.js +92 -0
  286. package/lib/module/ui/safeArea.js.map +1 -0
  287. package/lib/module/ui/useOverlayOrigin.js +36 -0
  288. package/lib/module/ui/useOverlayOrigin.js.map +1 -0
  289. package/lib/typescript/commonjs/KokoAgent.d.ts +167 -0
  290. package/lib/typescript/commonjs/KokoAgent.d.ts.map +1 -0
  291. package/lib/typescript/commonjs/assist/OnDeviceAssist.d.ts +31 -0
  292. package/lib/typescript/commonjs/assist/OnDeviceAssist.d.ts.map +1 -0
  293. package/lib/typescript/commonjs/assist/intentClassify.d.ts +18 -0
  294. package/lib/typescript/commonjs/assist/intentClassify.d.ts.map +1 -0
  295. package/lib/typescript/commonjs/assist/nodeRank.d.ts +32 -0
  296. package/lib/typescript/commonjs/assist/nodeRank.d.ts.map +1 -0
  297. package/lib/typescript/commonjs/assist/ocrTarget.d.ts +25 -0
  298. package/lib/typescript/commonjs/assist/ocrTarget.d.ts.map +1 -0
  299. package/lib/typescript/commonjs/assist/webVisualChange.d.ts +6 -0
  300. package/lib/typescript/commonjs/assist/webVisualChange.d.ts.map +1 -0
  301. package/lib/typescript/commonjs/client/ActionOutcomeUnknownError.d.ts +13 -0
  302. package/lib/typescript/commonjs/client/ActionOutcomeUnknownError.d.ts.map +1 -0
  303. package/lib/typescript/commonjs/client/AgentSession.d.ts +56 -0
  304. package/lib/typescript/commonjs/client/AgentSession.d.ts.map +1 -0
  305. package/lib/typescript/commonjs/client/GatewayClient.d.ts +149 -0
  306. package/lib/typescript/commonjs/client/GatewayClient.d.ts.map +1 -0
  307. package/lib/typescript/commonjs/client/OperationReplayGuard.d.ts +13 -0
  308. package/lib/typescript/commonjs/client/OperationReplayGuard.d.ts.map +1 -0
  309. package/lib/typescript/commonjs/client/RunCheckpoint.d.ts +57 -0
  310. package/lib/typescript/commonjs/client/RunCheckpoint.d.ts.map +1 -0
  311. package/lib/typescript/commonjs/client/loopDetect.d.ts +15 -0
  312. package/lib/typescript/commonjs/client/loopDetect.d.ts.map +1 -0
  313. package/lib/typescript/commonjs/client/recentSearch.d.ts +5 -0
  314. package/lib/typescript/commonjs/client/recentSearch.d.ts.map +1 -0
  315. package/lib/typescript/commonjs/client/walletChoiceGuard.d.ts +4 -0
  316. package/lib/typescript/commonjs/client/walletChoiceGuard.d.ts.map +1 -0
  317. package/lib/typescript/commonjs/client/webResultCategory.d.ts +5 -0
  318. package/lib/typescript/commonjs/client/webResultCategory.d.ts.map +1 -0
  319. package/lib/typescript/commonjs/commercial/AccountStore.d.ts +17 -0
  320. package/lib/typescript/commonjs/commercial/AccountStore.d.ts.map +1 -0
  321. package/lib/typescript/commonjs/commercial/AgentDebug.d.ts +25 -0
  322. package/lib/typescript/commonjs/commercial/AgentDebug.d.ts.map +1 -0
  323. package/lib/typescript/commonjs/commercial/ExecutionGuard.d.ts +18 -0
  324. package/lib/typescript/commonjs/commercial/ExecutionGuard.d.ts.map +1 -0
  325. package/lib/typescript/commonjs/commercial/UsageBus.d.ts +18 -0
  326. package/lib/typescript/commonjs/commercial/UsageBus.d.ts.map +1 -0
  327. package/lib/typescript/commonjs/commercial/branding.d.ts +25 -0
  328. package/lib/typescript/commonjs/commercial/branding.d.ts.map +1 -0
  329. package/lib/typescript/commonjs/commercial/devMode.d.ts +26 -0
  330. package/lib/typescript/commonjs/commercial/devMode.d.ts.map +1 -0
  331. package/lib/typescript/commonjs/commercial/trust.d.ts +21 -0
  332. package/lib/typescript/commonjs/commercial/trust.d.ts.map +1 -0
  333. package/lib/typescript/commonjs/confirmation/gate.d.ts +18 -0
  334. package/lib/typescript/commonjs/confirmation/gate.d.ts.map +1 -0
  335. package/lib/typescript/commonjs/cursor/CursorOverlay.d.ts +13 -0
  336. package/lib/typescript/commonjs/cursor/CursorOverlay.d.ts.map +1 -0
  337. package/lib/typescript/commonjs/cursor/PointerHand.d.ts +16 -0
  338. package/lib/typescript/commonjs/cursor/PointerHand.d.ts.map +1 -0
  339. package/lib/typescript/commonjs/cursor/controller.d.ts +30 -0
  340. package/lib/typescript/commonjs/cursor/controller.d.ts.map +1 -0
  341. package/lib/typescript/commonjs/cursor/pointer.d.ts +23 -0
  342. package/lib/typescript/commonjs/cursor/pointer.d.ts.map +1 -0
  343. package/lib/typescript/commonjs/debug/KokoRemoteSmoke.d.ts +96 -0
  344. package/lib/typescript/commonjs/debug/KokoRemoteSmoke.d.ts.map +1 -0
  345. package/lib/typescript/commonjs/explore/ExplorationGraph.d.ts +96 -0
  346. package/lib/typescript/commonjs/explore/ExplorationGraph.d.ts.map +1 -0
  347. package/lib/typescript/commonjs/explore/bootstrapExplore.d.ts +40 -0
  348. package/lib/typescript/commonjs/explore/bootstrapExplore.d.ts.map +1 -0
  349. package/lib/typescript/commonjs/host/HostActions.d.ts +101 -0
  350. package/lib/typescript/commonjs/host/HostActions.d.ts.map +1 -0
  351. package/lib/typescript/commonjs/i18n/index.d.ts +20 -0
  352. package/lib/typescript/commonjs/i18n/index.d.ts.map +1 -0
  353. package/lib/typescript/commonjs/i18n/runtimeMessages.d.ts +178 -0
  354. package/lib/typescript/commonjs/i18n/runtimeMessages.d.ts.map +1 -0
  355. package/lib/typescript/commonjs/index.d.ts +66 -0
  356. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  357. package/lib/typescript/commonjs/native/NativeBridge.d.ts +70 -0
  358. package/lib/typescript/commonjs/native/NativeBridge.d.ts.map +1 -0
  359. package/lib/typescript/commonjs/native/navigationLabel.d.ts +4 -0
  360. package/lib/typescript/commonjs/native/navigationLabel.d.ts.map +1 -0
  361. package/lib/typescript/commonjs/native/normalizeViewTree.d.ts +4 -0
  362. package/lib/typescript/commonjs/native/normalizeViewTree.d.ts.map +1 -0
  363. package/lib/typescript/commonjs/native/pruneOffscreen.d.ts +3 -0
  364. package/lib/typescript/commonjs/native/pruneOffscreen.d.ts.map +1 -0
  365. package/lib/typescript/commonjs/native/scrollViewport.d.ts +13 -0
  366. package/lib/typescript/commonjs/native/scrollViewport.d.ts.map +1 -0
  367. package/lib/typescript/commonjs/package.json +1 -0
  368. package/lib/typescript/commonjs/privacy/redact.d.ts +9 -0
  369. package/lib/typescript/commonjs/privacy/redact.d.ts.map +1 -0
  370. package/lib/typescript/commonjs/privacy/screenEvidence.d.ts +14 -0
  371. package/lib/typescript/commonjs/privacy/screenEvidence.d.ts.map +1 -0
  372. package/lib/typescript/commonjs/privacy/screenModel.d.ts +26 -0
  373. package/lib/typescript/commonjs/privacy/screenModel.d.ts.map +1 -0
  374. package/lib/typescript/commonjs/privacy/sensitiveScreen.d.ts +8 -0
  375. package/lib/typescript/commonjs/privacy/sensitiveScreen.d.ts.map +1 -0
  376. package/lib/typescript/commonjs/privacy/userGate.d.ts +58 -0
  377. package/lib/typescript/commonjs/privacy/userGate.d.ts.map +1 -0
  378. package/lib/typescript/commonjs/protocol/actions.d.ts +7 -0
  379. package/lib/typescript/commonjs/protocol/actions.d.ts.map +1 -0
  380. package/lib/typescript/commonjs/provider/HostAppearanceStore.d.ts +64 -0
  381. package/lib/typescript/commonjs/provider/HostAppearanceStore.d.ts.map +1 -0
  382. package/lib/typescript/commonjs/provider/KokoProvider.d.ts +39 -0
  383. package/lib/typescript/commonjs/provider/KokoProvider.d.ts.map +1 -0
  384. package/lib/typescript/commonjs/provider/KokoUiContext.d.ts +22 -0
  385. package/lib/typescript/commonjs/provider/KokoUiContext.d.ts.map +1 -0
  386. package/lib/typescript/commonjs/selector/match.d.ts +27 -0
  387. package/lib/typescript/commonjs/selector/match.d.ts.map +1 -0
  388. package/lib/typescript/commonjs/task/TaskStore.d.ts +65 -0
  389. package/lib/typescript/commonjs/task/TaskStore.d.ts.map +1 -0
  390. package/lib/typescript/commonjs/task/types.d.ts +66 -0
  391. package/lib/typescript/commonjs/task/types.d.ts.map +1 -0
  392. package/lib/typescript/commonjs/task/useTaskStore.d.ts +3 -0
  393. package/lib/typescript/commonjs/task/useTaskStore.d.ts.map +1 -0
  394. package/lib/typescript/commonjs/types.d.ts +372 -0
  395. package/lib/typescript/commonjs/types.d.ts.map +1 -0
  396. package/lib/typescript/commonjs/ui/KokoChatSheet.d.ts +8 -0
  397. package/lib/typescript/commonjs/ui/KokoChatSheet.d.ts.map +1 -0
  398. package/lib/typescript/commonjs/ui/KokoComposer.d.ts +13 -0
  399. package/lib/typescript/commonjs/ui/KokoComposer.d.ts.map +1 -0
  400. package/lib/typescript/commonjs/ui/KokoDialogHost.d.ts +32 -0
  401. package/lib/typescript/commonjs/ui/KokoDialogHost.d.ts.map +1 -0
  402. package/lib/typescript/commonjs/ui/KokoEntryButton.d.ts +18 -0
  403. package/lib/typescript/commonjs/ui/KokoEntryButton.d.ts.map +1 -0
  404. package/lib/typescript/commonjs/ui/KokoObserver.d.ts +13 -0
  405. package/lib/typescript/commonjs/ui/KokoObserver.d.ts.map +1 -0
  406. package/lib/typescript/commonjs/ui/KokoOverlayLayer.d.ts +35 -0
  407. package/lib/typescript/commonjs/ui/KokoOverlayLayer.d.ts.map +1 -0
  408. package/lib/typescript/commonjs/ui/KokoSubtitle.d.ts +7 -0
  409. package/lib/typescript/commonjs/ui/KokoSubtitle.d.ts.map +1 -0
  410. package/lib/typescript/commonjs/ui/KokoTaskPanel.d.ts +7 -0
  411. package/lib/typescript/commonjs/ui/KokoTaskPanel.d.ts.map +1 -0
  412. package/lib/typescript/commonjs/ui/hostOverlay.d.ts +28 -0
  413. package/lib/typescript/commonjs/ui/hostOverlay.d.ts.map +1 -0
  414. package/lib/typescript/commonjs/ui/icons.d.ts +26 -0
  415. package/lib/typescript/commonjs/ui/icons.d.ts.map +1 -0
  416. package/lib/typescript/commonjs/ui/progressChrome.d.ts +21 -0
  417. package/lib/typescript/commonjs/ui/progressChrome.d.ts.map +1 -0
  418. package/lib/typescript/commonjs/ui/safeArea.d.ts +12 -0
  419. package/lib/typescript/commonjs/ui/safeArea.d.ts.map +1 -0
  420. package/lib/typescript/commonjs/ui/useOverlayOrigin.d.ts +22 -0
  421. package/lib/typescript/commonjs/ui/useOverlayOrigin.d.ts.map +1 -0
  422. package/lib/typescript/module/KokoAgent.d.ts +167 -0
  423. package/lib/typescript/module/KokoAgent.d.ts.map +1 -0
  424. package/lib/typescript/module/assist/OnDeviceAssist.d.ts +31 -0
  425. package/lib/typescript/module/assist/OnDeviceAssist.d.ts.map +1 -0
  426. package/lib/typescript/module/assist/intentClassify.d.ts +18 -0
  427. package/lib/typescript/module/assist/intentClassify.d.ts.map +1 -0
  428. package/lib/typescript/module/assist/nodeRank.d.ts +32 -0
  429. package/lib/typescript/module/assist/nodeRank.d.ts.map +1 -0
  430. package/lib/typescript/module/assist/ocrTarget.d.ts +25 -0
  431. package/lib/typescript/module/assist/ocrTarget.d.ts.map +1 -0
  432. package/lib/typescript/module/assist/webVisualChange.d.ts +6 -0
  433. package/lib/typescript/module/assist/webVisualChange.d.ts.map +1 -0
  434. package/lib/typescript/module/client/ActionOutcomeUnknownError.d.ts +13 -0
  435. package/lib/typescript/module/client/ActionOutcomeUnknownError.d.ts.map +1 -0
  436. package/lib/typescript/module/client/AgentSession.d.ts +56 -0
  437. package/lib/typescript/module/client/AgentSession.d.ts.map +1 -0
  438. package/lib/typescript/module/client/GatewayClient.d.ts +149 -0
  439. package/lib/typescript/module/client/GatewayClient.d.ts.map +1 -0
  440. package/lib/typescript/module/client/OperationReplayGuard.d.ts +13 -0
  441. package/lib/typescript/module/client/OperationReplayGuard.d.ts.map +1 -0
  442. package/lib/typescript/module/client/RunCheckpoint.d.ts +57 -0
  443. package/lib/typescript/module/client/RunCheckpoint.d.ts.map +1 -0
  444. package/lib/typescript/module/client/loopDetect.d.ts +15 -0
  445. package/lib/typescript/module/client/loopDetect.d.ts.map +1 -0
  446. package/lib/typescript/module/client/recentSearch.d.ts +5 -0
  447. package/lib/typescript/module/client/recentSearch.d.ts.map +1 -0
  448. package/lib/typescript/module/client/walletChoiceGuard.d.ts +4 -0
  449. package/lib/typescript/module/client/walletChoiceGuard.d.ts.map +1 -0
  450. package/lib/typescript/module/client/webResultCategory.d.ts +5 -0
  451. package/lib/typescript/module/client/webResultCategory.d.ts.map +1 -0
  452. package/lib/typescript/module/commercial/AccountStore.d.ts +17 -0
  453. package/lib/typescript/module/commercial/AccountStore.d.ts.map +1 -0
  454. package/lib/typescript/module/commercial/AgentDebug.d.ts +25 -0
  455. package/lib/typescript/module/commercial/AgentDebug.d.ts.map +1 -0
  456. package/lib/typescript/module/commercial/ExecutionGuard.d.ts +18 -0
  457. package/lib/typescript/module/commercial/ExecutionGuard.d.ts.map +1 -0
  458. package/lib/typescript/module/commercial/UsageBus.d.ts +18 -0
  459. package/lib/typescript/module/commercial/UsageBus.d.ts.map +1 -0
  460. package/lib/typescript/module/commercial/branding.d.ts +25 -0
  461. package/lib/typescript/module/commercial/branding.d.ts.map +1 -0
  462. package/lib/typescript/module/commercial/devMode.d.ts +26 -0
  463. package/lib/typescript/module/commercial/devMode.d.ts.map +1 -0
  464. package/lib/typescript/module/commercial/trust.d.ts +21 -0
  465. package/lib/typescript/module/commercial/trust.d.ts.map +1 -0
  466. package/lib/typescript/module/confirmation/gate.d.ts +18 -0
  467. package/lib/typescript/module/confirmation/gate.d.ts.map +1 -0
  468. package/lib/typescript/module/cursor/CursorOverlay.d.ts +13 -0
  469. package/lib/typescript/module/cursor/CursorOverlay.d.ts.map +1 -0
  470. package/lib/typescript/module/cursor/PointerHand.d.ts +16 -0
  471. package/lib/typescript/module/cursor/PointerHand.d.ts.map +1 -0
  472. package/lib/typescript/module/cursor/controller.d.ts +30 -0
  473. package/lib/typescript/module/cursor/controller.d.ts.map +1 -0
  474. package/lib/typescript/module/cursor/pointer.d.ts +23 -0
  475. package/lib/typescript/module/cursor/pointer.d.ts.map +1 -0
  476. package/lib/typescript/module/debug/KokoRemoteSmoke.d.ts +96 -0
  477. package/lib/typescript/module/debug/KokoRemoteSmoke.d.ts.map +1 -0
  478. package/lib/typescript/module/explore/ExplorationGraph.d.ts +96 -0
  479. package/lib/typescript/module/explore/ExplorationGraph.d.ts.map +1 -0
  480. package/lib/typescript/module/explore/bootstrapExplore.d.ts +40 -0
  481. package/lib/typescript/module/explore/bootstrapExplore.d.ts.map +1 -0
  482. package/lib/typescript/module/host/HostActions.d.ts +101 -0
  483. package/lib/typescript/module/host/HostActions.d.ts.map +1 -0
  484. package/lib/typescript/module/i18n/index.d.ts +20 -0
  485. package/lib/typescript/module/i18n/index.d.ts.map +1 -0
  486. package/lib/typescript/module/i18n/runtimeMessages.d.ts +178 -0
  487. package/lib/typescript/module/i18n/runtimeMessages.d.ts.map +1 -0
  488. package/lib/typescript/module/index.d.ts +66 -0
  489. package/lib/typescript/module/index.d.ts.map +1 -0
  490. package/lib/typescript/module/native/NativeBridge.d.ts +70 -0
  491. package/lib/typescript/module/native/NativeBridge.d.ts.map +1 -0
  492. package/lib/typescript/module/native/navigationLabel.d.ts +4 -0
  493. package/lib/typescript/module/native/navigationLabel.d.ts.map +1 -0
  494. package/lib/typescript/module/native/normalizeViewTree.d.ts +4 -0
  495. package/lib/typescript/module/native/normalizeViewTree.d.ts.map +1 -0
  496. package/lib/typescript/module/native/pruneOffscreen.d.ts +3 -0
  497. package/lib/typescript/module/native/pruneOffscreen.d.ts.map +1 -0
  498. package/lib/typescript/module/native/scrollViewport.d.ts +13 -0
  499. package/lib/typescript/module/native/scrollViewport.d.ts.map +1 -0
  500. package/lib/typescript/module/package.json +1 -0
  501. package/lib/typescript/module/privacy/redact.d.ts +9 -0
  502. package/lib/typescript/module/privacy/redact.d.ts.map +1 -0
  503. package/lib/typescript/module/privacy/screenEvidence.d.ts +14 -0
  504. package/lib/typescript/module/privacy/screenEvidence.d.ts.map +1 -0
  505. package/lib/typescript/module/privacy/screenModel.d.ts +26 -0
  506. package/lib/typescript/module/privacy/screenModel.d.ts.map +1 -0
  507. package/lib/typescript/module/privacy/sensitiveScreen.d.ts +8 -0
  508. package/lib/typescript/module/privacy/sensitiveScreen.d.ts.map +1 -0
  509. package/lib/typescript/module/privacy/userGate.d.ts +58 -0
  510. package/lib/typescript/module/privacy/userGate.d.ts.map +1 -0
  511. package/lib/typescript/module/protocol/actions.d.ts +7 -0
  512. package/lib/typescript/module/protocol/actions.d.ts.map +1 -0
  513. package/lib/typescript/module/provider/HostAppearanceStore.d.ts +64 -0
  514. package/lib/typescript/module/provider/HostAppearanceStore.d.ts.map +1 -0
  515. package/lib/typescript/module/provider/KokoProvider.d.ts +39 -0
  516. package/lib/typescript/module/provider/KokoProvider.d.ts.map +1 -0
  517. package/lib/typescript/module/provider/KokoUiContext.d.ts +22 -0
  518. package/lib/typescript/module/provider/KokoUiContext.d.ts.map +1 -0
  519. package/lib/typescript/module/selector/match.d.ts +27 -0
  520. package/lib/typescript/module/selector/match.d.ts.map +1 -0
  521. package/lib/typescript/module/task/TaskStore.d.ts +65 -0
  522. package/lib/typescript/module/task/TaskStore.d.ts.map +1 -0
  523. package/lib/typescript/module/task/types.d.ts +66 -0
  524. package/lib/typescript/module/task/types.d.ts.map +1 -0
  525. package/lib/typescript/module/task/useTaskStore.d.ts +3 -0
  526. package/lib/typescript/module/task/useTaskStore.d.ts.map +1 -0
  527. package/lib/typescript/module/types.d.ts +372 -0
  528. package/lib/typescript/module/types.d.ts.map +1 -0
  529. package/lib/typescript/module/ui/KokoChatSheet.d.ts +8 -0
  530. package/lib/typescript/module/ui/KokoChatSheet.d.ts.map +1 -0
  531. package/lib/typescript/module/ui/KokoComposer.d.ts +13 -0
  532. package/lib/typescript/module/ui/KokoComposer.d.ts.map +1 -0
  533. package/lib/typescript/module/ui/KokoDialogHost.d.ts +32 -0
  534. package/lib/typescript/module/ui/KokoDialogHost.d.ts.map +1 -0
  535. package/lib/typescript/module/ui/KokoEntryButton.d.ts +18 -0
  536. package/lib/typescript/module/ui/KokoEntryButton.d.ts.map +1 -0
  537. package/lib/typescript/module/ui/KokoObserver.d.ts +13 -0
  538. package/lib/typescript/module/ui/KokoObserver.d.ts.map +1 -0
  539. package/lib/typescript/module/ui/KokoOverlayLayer.d.ts +35 -0
  540. package/lib/typescript/module/ui/KokoOverlayLayer.d.ts.map +1 -0
  541. package/lib/typescript/module/ui/KokoSubtitle.d.ts +7 -0
  542. package/lib/typescript/module/ui/KokoSubtitle.d.ts.map +1 -0
  543. package/lib/typescript/module/ui/KokoTaskPanel.d.ts +7 -0
  544. package/lib/typescript/module/ui/KokoTaskPanel.d.ts.map +1 -0
  545. package/lib/typescript/module/ui/hostOverlay.d.ts +28 -0
  546. package/lib/typescript/module/ui/hostOverlay.d.ts.map +1 -0
  547. package/lib/typescript/module/ui/icons.d.ts +26 -0
  548. package/lib/typescript/module/ui/icons.d.ts.map +1 -0
  549. package/lib/typescript/module/ui/progressChrome.d.ts +21 -0
  550. package/lib/typescript/module/ui/progressChrome.d.ts.map +1 -0
  551. package/lib/typescript/module/ui/safeArea.d.ts +12 -0
  552. package/lib/typescript/module/ui/safeArea.d.ts.map +1 -0
  553. package/lib/typescript/module/ui/useOverlayOrigin.d.ts +22 -0
  554. package/lib/typescript/module/ui/useOverlayOrigin.d.ts.map +1 -0
  555. package/package.json +153 -0
  556. package/react-native.config.js +12 -0
  557. package/src/KokoAgent.ts +1415 -0
  558. package/src/assist/OnDeviceAssist.ts +133 -0
  559. package/src/assist/intentClassify.ts +122 -0
  560. package/src/assist/nodeRank.ts +167 -0
  561. package/src/assist/ocrTarget.ts +146 -0
  562. package/src/assist/webVisualChange.ts +24 -0
  563. package/src/client/ActionOutcomeUnknownError.ts +18 -0
  564. package/src/client/AgentSession.ts +952 -0
  565. package/src/client/GatewayClient.ts +439 -0
  566. package/src/client/OperationReplayGuard.ts +61 -0
  567. package/src/client/RunCheckpoint.ts +154 -0
  568. package/src/client/loopDetect.ts +213 -0
  569. package/src/client/recentSearch.ts +47 -0
  570. package/src/client/walletChoiceGuard.ts +15 -0
  571. package/src/client/webResultCategory.ts +28 -0
  572. package/src/commercial/AccountStore.ts +85 -0
  573. package/src/commercial/AgentDebug.ts +142 -0
  574. package/src/commercial/ExecutionGuard.ts +67 -0
  575. package/src/commercial/UsageBus.ts +44 -0
  576. package/src/commercial/branding.ts +97 -0
  577. package/src/commercial/devMode.ts +48 -0
  578. package/src/commercial/trust.ts +67 -0
  579. package/src/confirmation/gate.ts +82 -0
  580. package/src/cursor/CursorOverlay.tsx +138 -0
  581. package/src/cursor/PointerHand.tsx +49 -0
  582. package/src/cursor/controller.ts +98 -0
  583. package/src/cursor/pointer.ts +40 -0
  584. package/src/debug/KokoRemoteSmoke.tsx +561 -0
  585. package/src/explore/ExplorationGraph.ts +518 -0
  586. package/src/explore/bootstrapExplore.ts +89 -0
  587. package/src/host/HostActions.ts +349 -0
  588. package/src/i18n/index.ts +229 -0
  589. package/src/i18n/runtimeMessages.ts +180 -0
  590. package/src/index.ts +203 -0
  591. package/src/native/NativeBridge.ts +207 -0
  592. package/src/native/navigationLabel.ts +11 -0
  593. package/src/native/normalizeViewTree.ts +16 -0
  594. package/src/native/pruneOffscreen.ts +72 -0
  595. package/src/native/scrollViewport.ts +51 -0
  596. package/src/privacy/redact.ts +115 -0
  597. package/src/privacy/screenEvidence.ts +55 -0
  598. package/src/privacy/screenModel.ts +504 -0
  599. package/src/privacy/sensitiveScreen.ts +55 -0
  600. package/src/privacy/userGate.ts +233 -0
  601. package/src/protocol/actions.ts +66 -0
  602. package/src/provider/HostAppearanceStore.ts +148 -0
  603. package/src/provider/KokoProvider.tsx +118 -0
  604. package/src/provider/KokoUiContext.tsx +162 -0
  605. package/src/selector/match.ts +417 -0
  606. package/src/task/TaskStore.ts +387 -0
  607. package/src/task/types.ts +82 -0
  608. package/src/task/useTaskStore.ts +9 -0
  609. package/src/types.ts +318 -0
  610. package/src/ui/KokoChatSheet.tsx +930 -0
  611. package/src/ui/KokoComposer.tsx +174 -0
  612. package/src/ui/KokoDialogHost.tsx +249 -0
  613. package/src/ui/KokoEntryButton.tsx +74 -0
  614. package/src/ui/KokoObserver.tsx +587 -0
  615. package/src/ui/KokoOverlayLayer.tsx +53 -0
  616. package/src/ui/KokoSubtitle.tsx +80 -0
  617. package/src/ui/KokoTaskPanel.tsx +299 -0
  618. package/src/ui/hostOverlay.tsx +148 -0
  619. package/src/ui/icons.tsx +145 -0
  620. package/src/ui/progressChrome.ts +73 -0
  621. package/src/ui/safeArea.ts +95 -0
  622. package/src/ui/useOverlayOrigin.ts +29 -0
@@ -0,0 +1,439 @@
1
+ import { AppUserGateStore } from '../privacy/userGate';
2
+ import type { AgentAction, Point, Selector } from '../types';
3
+ import type { KokoAccountSnapshot, KokoEntitlements, KokoPlanId } from '../types';
4
+ import { isAllowedGatewayUrl } from '../commercial/trust';
5
+ import { allowLocalGatewayForDebugClient } from '../commercial/devMode';
6
+ import { NativeBridge } from '../native/NativeBridge';
7
+ import { sensitiveScreenKind, SensitiveScreenError } from '../privacy/sensitiveScreen';
8
+ import { redactOutbound, redactViewTreeClient, viewTreeOutline } from '../privacy/redact';
9
+ import { extractAffordances, screenModelText } from '../privacy/screenModel';
10
+ import { buildOnDeviceAssistSync } from '../assist/OnDeviceAssist';
11
+ import { HostActionsStore, filterVisibleHostActions, hostActionsModelText } from '../host/HostActions';
12
+ import { ExplorationGraph, exploreHintsModelText, goalExploreQuery } from '../explore/ExplorationGraph';
13
+ import { findNodeById } from '../selector/match';
14
+ import { goalOcrCandidates, visibleWebViewFrames, PUBLIC_WALLET_CHOICES, walletConnectionAllowed } from '../assist/ocrTarget';
15
+ import type { ViewNode } from '../types';
16
+
17
+ export type GatewayConfig = {
18
+ /**
19
+ * Official gateway origin. Defaults to https://sdk.intentcomputing.net
20
+ * Localhost only in Metro debug clients (lab dogfood), not customer self-host.
21
+ */
22
+ baseUrl?: string;
23
+ /**
24
+ * App / member token from your product backend or dashboard.
25
+ * Never an LLM API key — users never see model keys.
26
+ */
27
+ token: string;
28
+ /**
29
+ * Host App ID (iOS bundle id / Android package name).
30
+ * Defaults to the native module's hostAppId. Must match the App ID bound to the token.
31
+ */
32
+ appId?: string;
33
+ };
34
+
35
+ const DEFAULT_GATEWAY = 'https://sdk.intentcomputing.net';
36
+
37
+ export function resolveGatewayBaseUrl(cfg: GatewayConfig): string {
38
+ const raw = (cfg.baseUrl?.trim() || DEFAULT_GATEWAY).replace(/\/$/, '');
39
+ const check = isAllowedGatewayUrl(raw, allowLocalGatewayForDebugClient());
40
+ if (!check.ok) {
41
+ throw new Error(`KokoAgent: ${check.reason}`);
42
+ }
43
+ return raw;
44
+ }
45
+
46
+ export type AgentHistoryItem = {
47
+ tool: string;
48
+ args?: Record<string, unknown>;
49
+ result: string;
50
+ ok?: boolean;
51
+ };
52
+
53
+ export type GatewayNextRequest = {
54
+ session_id?: string;
55
+ goal: string;
56
+ ui_tree?: unknown;
57
+ ui_outline?: string;
58
+ ui_screen_model?: string;
59
+ /** Local-only evidence; gateway serializes only labels derived from goal. */
60
+ local_ocr_goal_labels?: string[];
61
+ local_ocr_wallet_choices?: string[];
62
+ local_web_wallet_aliases?: string[];
63
+ history: AgentHistoryItem[];
64
+ locale?: string;
65
+ user_reply?: string;
66
+ platform?: 'ios' | 'android' | 'unknown';
67
+ };
68
+
69
+ /** Build hints from the same redacted tree that crosses the upload boundary. */
70
+ export function safePlannerModel(tree: ViewNode, goal: string, localOcrGoalLabels: string[] = [], localWalletChoices: string[] = [], hostWalletAliases: string[] = []): string {
71
+ const affordances = extractAffordances(tree, 80);
72
+ const labels = affordances.map(a => a.label);
73
+ const hosts = filterVisibleHostActions(HostActionsStore.getActions(), tree).flatMap(action => {
74
+ const visible = affordances.find(a => {
75
+ if (action.testID) return findNodeById(tree, a.nodeId)?.testID === action.testID;
76
+ return [action.label, action.text, ...(action.aliases || [])].some(label => label === a.label);
77
+ });
78
+ if (!visible) return [];
79
+ const kind = ['button', 'tab', 'nav', 'field', 'sheet', 'other'].includes(action.kind || '') ? action.kind : 'button';
80
+ return [{ ...action, kind, label: visible.label, text: visible.label, testID: findNodeById(tree, visible.nodeId)?.testID, aliases: [] }];
81
+ });
82
+ const possibleHints = ExplorationGraph.hintLabelsTowardGoal(labels, goalExploreQuery(goal).targetTokens, 6);
83
+ // Historical pages may contain data no longer visible. Only the current
84
+ // screen's exact public labels may be carried into the request.
85
+ const hints = possibleHints.filter(hint => labels.includes(hint));
86
+ const assist = buildOnDeviceAssistSync(goal, tree);
87
+ const allowedLabels = new Set(goalOcrCandidates(goal));
88
+ const verified = visibleWebViewFrames(tree).length && Array.isArray(localOcrGoalLabels)
89
+ ? [...new Set(localOcrGoalLabels)].filter(label => typeof label === 'string' && allowedLabels.has(label)).slice(0, 6) : [];
90
+ const ocrHints = verified.map(label =>
91
+ `- [local-ocr] A visible web text matched the goal-derived label 「${label}」 on this device. ` +
92
+ 'Use find with one text rule to confirm it. When the user requested an action, its returned nodeId can be used to tap. No raw OCR text is included.',
93
+ ).join('\n');
94
+ const allowedChoices = new Set<string>(PUBLIC_WALLET_CHOICES);
95
+ const choices = visibleWebViewFrames(tree).length && walletConnectionAllowed(goal) && Array.isArray(localWalletChoices)
96
+ ? [...new Set(localWalletChoices)].filter(label => allowedChoices.has(label)).slice(0, 8) : [];
97
+ const choiceHint = choices.length >= 2
98
+ ? `- [local-wallet-choices] Visible public wallet options verified on-device: ${choices.join(', ')}. Use find with the exact option label; actual authorization stays with the user.`
99
+ : '';
100
+ const aliases = Array.isArray(hostWalletAliases) ? hostWalletAliases.filter(label => choices.includes(label)) : [];
101
+ const aliasHint = aliases.length ? `- [host-wallet-alias] Host confirms its injected wallet appears as: ${aliases.join(', ')}. Select that visible option for the host wallet.` : '';
102
+ const unavailableHint = choices.length >= 2 && hostWalletAliases.length && !aliases.length
103
+ ? '- [host-wallet-unavailable] None of the visible options matches the host wallet. Do not select a different wallet. If the host browser offers a desktop-site mode, try it and recheck the wallet chooser; otherwise report the unavailable option.' : '';
104
+ const extras = [hostActionsModelText(hosts), exploreHintsModelText(hints), assist.modelText, ocrHints, choiceHint, aliasHint, unavailableHint].filter(Boolean).join('\n');
105
+ return screenModelText(tree, 40, extras || undefined);
106
+ }
107
+
108
+ export type GatewayAction =
109
+ | { tool: 'dump'; args?: { reason?: string } }
110
+ | { tool: 'find'; args: { match: Array<Record<string, unknown>>; index?: number } }
111
+ | {
112
+ tool: 'tap';
113
+ args: {
114
+ selector?: Selector;
115
+ nodeId?: string;
116
+ /** Last-resort window point when the control is visible but not in the tree. */
117
+ point?: Point;
118
+ label?: string;
119
+ };
120
+ }
121
+ | {
122
+ tool: 'swipe';
123
+ args: { from: Point; to: Point; label?: string };
124
+ }
125
+ | {
126
+ tool: 'pinch';
127
+ args: { center: Point; scale: number; label?: string };
128
+ }
129
+ | {
130
+ tool: 'type';
131
+ args: {
132
+ text: string;
133
+ selector?: Selector;
134
+ nodeId?: string;
135
+ clear?: boolean;
136
+ label?: string;
137
+ };
138
+ }
139
+ | { tool: 'ask_user'; args: { question: string } }
140
+ | { tool: 'done'; args: { success: boolean; summary: string } };
141
+
142
+ export type GatewayNextResponse = {
143
+ ok: true;
144
+ session_id: string;
145
+ narration: string | null;
146
+ action: GatewayAction;
147
+ provider: string;
148
+ model: string;
149
+ step: number;
150
+ region: string;
151
+ execution_permit: string;
152
+ };
153
+
154
+ export type GatewaySessionResponse = {
155
+ ok: true;
156
+ session_id: string;
157
+ execution_permit: string;
158
+ };
159
+
160
+ export class GatewayError extends Error {
161
+ readonly code: string;
162
+ readonly status: number;
163
+ readonly quota?: KokoAccountSnapshot['quota'];
164
+ readonly plan?: KokoPlanId;
165
+
166
+ constructor(
167
+ message: string,
168
+ opts: {
169
+ code: string;
170
+ status: number;
171
+ quota?: KokoAccountSnapshot['quota'];
172
+ plan?: KokoPlanId;
173
+ },
174
+ ) {
175
+ super(message);
176
+ this.name = 'GatewayError';
177
+ this.code = opts.code;
178
+ this.status = opts.status;
179
+ this.quota = opts.quota;
180
+ this.plan = opts.plan;
181
+ }
182
+ }
183
+
184
+ export class GatewayClient {
185
+ private readonly baseUrl: string;
186
+ private readonly token: string;
187
+ private readonly appId: string;
188
+
189
+ constructor(cfg: GatewayConfig) {
190
+ this.baseUrl = resolveGatewayBaseUrl(cfg);
191
+ this.token = cfg.token;
192
+ this.appId = (cfg.appId?.trim() || NativeBridge.hostAppId() || '').trim();
193
+ }
194
+
195
+ getBaseUrl(): string {
196
+ return this.baseUrl;
197
+ }
198
+
199
+ getAppId(): string {
200
+ return this.appId;
201
+ }
202
+
203
+ private authHeaders(): Record<string, string> {
204
+ const headers: Record<string, string> = {
205
+ Authorization: `Bearer ${this.token}`,
206
+ 'Content-Type': 'application/json',
207
+ };
208
+ if (this.appId) headers['X-Koko-App-Id'] = this.appId;
209
+ return headers;
210
+ }
211
+
212
+ private async parseError(res: Response, fallback: string): Promise<never> {
213
+ let json: {
214
+ error?: string;
215
+ message?: string;
216
+ quota?: KokoAccountSnapshot['quota'];
217
+ plan?: KokoPlanId;
218
+ } = {};
219
+ try {
220
+ json = (await res.json()) as typeof json;
221
+ } catch {
222
+ // ignore
223
+ }
224
+ throw new GatewayError(json.message || json.error || fallback, {
225
+ code: json.error || 'error',
226
+ status: res.status,
227
+ quota: json.quota,
228
+ plan: json.plan,
229
+ });
230
+ }
231
+
232
+ async health(): Promise<Record<string, unknown>> {
233
+ const res = await fetch(`${this.baseUrl}/v1/health`);
234
+ if (!res.ok) throw new Error(`health ${res.status}`);
235
+ return (await res.json()) as Record<string, unknown>;
236
+ }
237
+
238
+ /** Open session + initial execution permit (before first dump). */
239
+ async beginSession(sessionId?: string): Promise<GatewaySessionResponse> {
240
+ const res = await fetch(`${this.baseUrl}/v1/agent/session`, {
241
+ method: 'POST',
242
+ headers: this.authHeaders(),
243
+ body: JSON.stringify(sessionId ? { session_id: sessionId } : {}),
244
+ });
245
+ if (!res.ok) await this.parseError(res, `session ${res.status}`);
246
+ const json = (await res.json()) as GatewaySessionResponse;
247
+ if (!json.session_id || !json.execution_permit) {
248
+ throw new GatewayError('invalid session response', {
249
+ code: 'invalid_response',
250
+ status: res.status,
251
+ });
252
+ }
253
+ return {
254
+ ok: true,
255
+ session_id: json.session_id,
256
+ execution_permit: json.execution_permit,
257
+ };
258
+ }
259
+
260
+ async me(): Promise<KokoAccountSnapshot> {
261
+ const res = await fetch(`${this.baseUrl}/v1/me`, {
262
+ headers: this.authHeaders(),
263
+ });
264
+ const json = (await res.json()) as {
265
+ ok?: boolean;
266
+ plan?: string;
267
+ region?: string;
268
+ provider?: string;
269
+ entitlements?: Partial<KokoEntitlements>;
270
+ quota?: { daily?: number; used_today?: number; remaining?: number };
271
+ error?: string;
272
+ message?: string;
273
+ };
274
+ if (!res.ok) {
275
+ throw new GatewayError(json.message || json.error || `me ${res.status}`, {
276
+ code: json.error || 'unauthorized',
277
+ status: res.status,
278
+ });
279
+ }
280
+ const plan = (json.plan as KokoPlanId) || 'free';
281
+ const entitlements: KokoEntitlements = {
282
+ custom_branding: json.entitlements?.custom_branding === true,
283
+ locale: json.entitlements?.locale !== false,
284
+ };
285
+ const daily = json.quota?.daily ?? 0;
286
+ const used = json.quota?.used_today ?? 0;
287
+ return {
288
+ plan,
289
+ region: json.region,
290
+ provider: json.provider,
291
+ entitlements,
292
+ quota: {
293
+ daily,
294
+ used_today: used,
295
+ remaining: json.quota?.remaining ?? Math.max(0, daily - used),
296
+ },
297
+ };
298
+ }
299
+
300
+ async usage(limit = 50): Promise<{
301
+ quota: KokoAccountSnapshot['quota'];
302
+ plan: KokoPlanId;
303
+ events: unknown[];
304
+ }> {
305
+ const res = await fetch(`${this.baseUrl}/v1/usage?limit=${limit}`, {
306
+ headers: this.authHeaders(),
307
+ });
308
+ const json = (await res.json()) as {
309
+ ok?: boolean;
310
+ plan?: KokoPlanId;
311
+ quota?: KokoAccountSnapshot['quota'];
312
+ events?: unknown[];
313
+ error?: string;
314
+ message?: string;
315
+ };
316
+ if (!res.ok) {
317
+ throw new GatewayError(json.message || json.error || `usage ${res.status}`, {
318
+ code: json.error || 'error',
319
+ status: res.status,
320
+ });
321
+ }
322
+ return {
323
+ plan: json.plan || 'free',
324
+ quota: json.quota || { daily: 0, used_today: 0, remaining: 0 },
325
+ events: json.events || [],
326
+ };
327
+ }
328
+
329
+ async next(body: GatewayNextRequest): Promise<GatewayNextResponse> {
330
+ const supplied = body.ui_tree as ViewNode | undefined;
331
+ let live: ViewNode | undefined;
332
+ if (NativeBridge.isAvailable()) {
333
+ // Fail closed if the current screen cannot be checked. Never send a
334
+ // cached safe screen while a newly presented secret page is visible.
335
+ live = await NativeBridge.dump({ maxDepth: 100 });
336
+ }
337
+ const gate = AppUserGateStore.getHostGate();
338
+ if ((gate && ['recovery_phrase', 'private_key', 'password', 'pin', 'otp', 'secure_input'].includes(gate.kind)) ||
339
+ sensitiveScreenKind(live) || sensitiveScreenKind(supplied)) throw new SensitiveScreenError();
340
+ const safeTree = supplied ? redactViewTreeClient(supplied) : undefined;
341
+ const safeBody = redactOutbound({
342
+ session_id: body.session_id,
343
+ goal: body.goal,
344
+ history: body.history,
345
+ locale: body.locale,
346
+ user_reply: body.user_reply,
347
+ platform: body.platform,
348
+ ui_tree: safeTree,
349
+ // Build every visual hint from the redacted tree, never caller-provided
350
+ // model strings, unverified OCR text or historical off-screen labels.
351
+ ui_outline: safeTree ? viewTreeOutline(safeTree) : undefined,
352
+ ui_screen_model: safeTree ? safePlannerModel(safeTree, body.goal, body.local_ocr_goal_labels, body.local_ocr_wallet_choices, body.local_web_wallet_aliases) : undefined,
353
+ }, [live, supplied]);
354
+ const res = await fetch(`${this.baseUrl}/v1/agent/next`, {
355
+ method: 'POST',
356
+ headers: this.authHeaders(),
357
+ body: JSON.stringify(safeBody),
358
+ });
359
+ const json = (await res.json()) as
360
+ | GatewayNextResponse
361
+ | {
362
+ ok: false;
363
+ error: string;
364
+ message?: string;
365
+ quota?: KokoAccountSnapshot['quota'];
366
+ plan?: KokoPlanId;
367
+ };
368
+ if (!res.ok || !('ok' in json) || json.ok !== true) {
369
+ const err = json as {
370
+ error?: string;
371
+ message?: string;
372
+ quota?: KokoAccountSnapshot['quota'];
373
+ plan?: KokoPlanId;
374
+ };
375
+ throw new GatewayError(err.message || err.error || `gateway ${res.status}`, {
376
+ code: err.error || 'error',
377
+ status: res.status,
378
+ quota: err.quota,
379
+ plan: err.plan,
380
+ });
381
+ }
382
+ if (!json.execution_permit) {
383
+ throw new GatewayError('invalid agent response', {
384
+ code: 'invalid_response',
385
+ status: res.status,
386
+ });
387
+ }
388
+ return json;
389
+ }
390
+ }
391
+
392
+ export function toLocalAgentAction(action: GatewayAction): AgentAction | null {
393
+ switch (action.tool) {
394
+ case 'dump':
395
+ return { tool: 'dump' };
396
+ case 'find':
397
+ return {
398
+ tool: 'find',
399
+ args: {
400
+ selector: {
401
+ match: action.args.match as Selector['match'],
402
+ index: action.args.index,
403
+ },
404
+ },
405
+ };
406
+ case 'tap':
407
+ return {
408
+ tool: 'tap',
409
+ args: {
410
+ selector: action.args.selector,
411
+ nodeId: action.args.nodeId,
412
+ point: action.args.point,
413
+ options: undefined,
414
+ },
415
+ };
416
+ case 'swipe':
417
+ return {
418
+ tool: 'swipe',
419
+ args: { from: action.args.from, to: action.args.to },
420
+ };
421
+ case 'pinch':
422
+ return {
423
+ tool: 'pinch',
424
+ args: { center: action.args.center, scale: action.args.scale },
425
+ };
426
+ case 'type':
427
+ return {
428
+ tool: 'type',
429
+ args: {
430
+ text: action.args.text,
431
+ selector: action.args.selector,
432
+ nodeId: action.args.nodeId,
433
+ options: { clear: action.args.clear },
434
+ },
435
+ };
436
+ default:
437
+ return null;
438
+ }
439
+ }
@@ -0,0 +1,61 @@
1
+ import type { GatewayAction } from './GatewayClient';
2
+ import type { ViewNode } from '../types';
3
+ import { find, findNodeById } from '../selector/match';
4
+ import { sensitiveScreenKind } from '../privacy/sensitiveScreen';
5
+
6
+ // Operation entries, not ordinary Next/Continue controls reused by wizards.
7
+ const OPERATION = /创建|新建|添加|导入|备份|导出|提交|支付|转账|购买|删除|注销|\b(create|add|import|backup|back\s+up|export|submit|pay|transfer|buy|delete)\b/i;
8
+
9
+ function hash(text: string): string {
10
+ let h = 2166136261;
11
+ for (const c of text) h = Math.imul(h ^ c.charCodeAt(0), 16777619);
12
+ return (h >>> 0).toString(16);
13
+ }
14
+
15
+ /** Keep only hashes of prior public operation entries across privacy purges. */
16
+ export class OperationReplayGuard {
17
+ private attempts = new Set<string>();
18
+ hasHandoff = false;
19
+
20
+ reset() { this.attempts.clear(); this.hasHandoff = false; }
21
+ markHandoff() { this.hasHandoff = true; }
22
+
23
+ private key(action: GatewayAction, tree: ViewNode | null): string | null {
24
+ if (action.tool !== 'tap' || !tree || sensitiveScreenKind(tree)) return null;
25
+ const node = action.args.nodeId ? findNodeById(tree, action.args.nodeId) :
26
+ action.args.selector ? find(tree, action.args.selector) : null;
27
+ const selectorText = action.args.selector?.match.map(rule =>
28
+ 'text' in rule ? rule.text : 'accessibilityLabel' in rule ? rule.accessibilityLabel : '',
29
+ ).filter(Boolean).join(' ');
30
+ const label = (node?.text || node?.accessibilityLabel || selectorText ||
31
+ action.args.label?.match(/[「“"]([^」”"]+)[」”"]/)?.[1] || action.args.label || '').trim();
32
+ if (!OPERATION.test(label)) return null;
33
+ // Public banners, prices and loading copy can change while the operation
34
+ // remains the same. Only an explicit host identity separates operations;
35
+ // native path IDs are snapshot-local and must not reset replay protection.
36
+ let identity = node?.testID || '';
37
+ if (node && !identity) {
38
+ const locate = (parent: ViewNode): boolean => {
39
+ for (const child of parent.children) {
40
+ if (child.id === node.id || locate(child)) {
41
+ if (!identity && parent.testID) identity = parent.testID;
42
+ return true;
43
+ }
44
+ }
45
+ return false;
46
+ };
47
+ locate(tree);
48
+ }
49
+ return hash(`${label.replace(/\s+/g, ' ').toLocaleLowerCase()}\n${identity}`);
50
+ }
51
+
52
+ record(action: GatewayAction, tree: ViewNode | null) {
53
+ const key = this.key(action, tree);
54
+ if (key) this.attempts.add(key);
55
+ }
56
+
57
+ blocks(action: GatewayAction, tree: ViewNode | null): boolean {
58
+ const key = this.key(action, tree);
59
+ return this.hasHandoff && !!key && this.attempts.has(key);
60
+ }
61
+ }
@@ -0,0 +1,154 @@
1
+ /**
2
+ * Survive a JS-context restart mid-run.
3
+ *
4
+ * Some actions destroy the runtime that is performing them: changing locale or
5
+ * theme, toggling RTL, flipping a feature flag, anything the host answers with
6
+ * a root remount or `reloadAsync`. The tap succeeds, the App comes back — but
7
+ * the `runGoal` promise, its session and the whole TaskStore died with the old
8
+ * context, so the caller can never learn the outcome.
9
+ *
10
+ * So checkpoint the goal to disk while it runs. On the next SDK init a fresh
11
+ * checkpoint means "we were interrupted", and the run can be picked up again
12
+ * from whatever screen the App came back on.
13
+ *
14
+ * Storage is best-effort: without AsyncStorage this degrades to memory, which
15
+ * cannot survive a reload. That is the same tradeoff ExplorationGraph makes —
16
+ * a missing optional peer must not break a run, only reduce it.
17
+ */
18
+
19
+ type AsyncStorageLike = {
20
+ getItem(key: string): Promise<string | null>;
21
+ setItem(key: string, value: string): Promise<void>;
22
+ removeItem(key: string): Promise<void>;
23
+ };
24
+
25
+ function tryAsyncStorage(): AsyncStorageLike | null {
26
+ try {
27
+ // Optional peer — many RN hosts already ship it.
28
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
29
+ const mod = require('@react-native-async-storage/async-storage');
30
+ const store = mod?.default ?? mod;
31
+ if (store && typeof store.getItem === 'function') return store;
32
+ } catch {
33
+ // optional
34
+ }
35
+ return null;
36
+ }
37
+
38
+ const KEY = 'koko.run.checkpoint.v1';
39
+
40
+ /**
41
+ * A reload takes a second or two. Anything older than this was not an
42
+ * interruption — it is a run that died for some other reason (force quit,
43
+ * crash, the user walking away), and silently driving the UI on next launch
44
+ * would be surprising rather than helpful.
45
+ */
46
+ export const RESUME_MAX_AGE_MS = 90_000;
47
+
48
+ /**
49
+ * One resume per goal. If the goal itself is what reloads the App, resuming it
50
+ * reloads again; without a cap that is an infinite loop across launches.
51
+ */
52
+ export const RESUME_MAX_ATTEMPTS = 1;
53
+
54
+ export type RunCheckpointData = {
55
+ goal: string;
56
+ startedAt: number;
57
+ /** Bumped per step, so age reflects liveness rather than run length. */
58
+ updatedAt: number;
59
+ /** Resumes already spent on this goal. */
60
+ resumes: number;
61
+ };
62
+
63
+ let memory: RunCheckpointData | null = null;
64
+ // Storage implementations need not complete writes in invocation order. Keep
65
+ // read/claim/write in one queue so an older clear cannot erase a newer run.
66
+ let storageQueue: Promise<unknown> = Promise.resolve();
67
+ function serialized<T>(operation: () => Promise<T>): Promise<T> {
68
+ const result = storageQueue.then(operation);
69
+ storageQueue = result.catch(() => {});
70
+ return result;
71
+ }
72
+
73
+ async function write(data: RunCheckpointData | null) {
74
+ memory = data;
75
+ const storage = tryAsyncStorage();
76
+ if (!storage) return;
77
+ try {
78
+ if (data) await storage.setItem(KEY, JSON.stringify(data));
79
+ else await storage.removeItem(KEY);
80
+ } catch {
81
+ // best-effort
82
+ }
83
+ }
84
+
85
+ async function read(): Promise<RunCheckpointData | null> {
86
+ const storage = tryAsyncStorage();
87
+ if (!storage) return memory;
88
+ try {
89
+ const raw = await storage.getItem(KEY);
90
+ if (!raw) return null;
91
+ const parsed = JSON.parse(raw) as RunCheckpointData;
92
+ if (!parsed || typeof parsed.goal !== 'string' || !parsed.goal) return null;
93
+ return {
94
+ goal: parsed.goal,
95
+ startedAt: Number(parsed.startedAt) || 0,
96
+ updatedAt: Number(parsed.updatedAt) || Number(parsed.startedAt) || 0,
97
+ resumes: Number(parsed.resumes) || 0,
98
+ };
99
+ } catch {
100
+ return null;
101
+ }
102
+ }
103
+
104
+ export const RunCheckpoint = {
105
+ /** Mark a goal as in flight. `resumes` carries over when resuming. */
106
+ begin(goal: string, resumes = 0) {
107
+ return serialized(async () => {
108
+ const now = Date.now();
109
+ await write({ goal, startedAt: now, updatedAt: now, resumes });
110
+ });
111
+ },
112
+
113
+ /** Keep the checkpoint fresh while the loop makes progress. */
114
+ touch() {
115
+ return serialized(async () => {
116
+ if (!memory) return;
117
+ await write({ ...memory, updatedAt: Date.now() });
118
+ });
119
+ },
120
+
121
+ /** The run reached a verdict — nothing left to resume. */
122
+ clear() {
123
+ return serialized(async () => {
124
+ if (!memory && !tryAsyncStorage()) return;
125
+ await write(null);
126
+ });
127
+ },
128
+
129
+ /**
130
+ * Claim an interrupted run, if there is one worth resuming.
131
+ *
132
+ * Clears before returning: a resume that dies the same way must not be
133
+ * claimed again on the next launch.
134
+ */
135
+ async claimResumable(opts?: {
136
+ maxAgeMs?: number;
137
+ maxAttempts?: number;
138
+ now?: number;
139
+ }): Promise<RunCheckpointData | null> {
140
+ return serialized(async () => {
141
+ const maxAgeMs = opts?.maxAgeMs ?? RESUME_MAX_AGE_MS;
142
+ const maxAttempts = opts?.maxAttempts ?? RESUME_MAX_ATTEMPTS;
143
+ const now = opts?.now ?? Date.now();
144
+ const found = await read();
145
+ await write(null);
146
+ if (!found) return null;
147
+ if (found.resumes >= maxAttempts) return null;
148
+ if (!Number.isFinite(found.updatedAt) || !found.updatedAt ||
149
+ now < found.updatedAt || now - found.updatedAt > maxAgeMs ||
150
+ !Number.isFinite(found.resumes) || found.resumes < 0) return null;
151
+ return found;
152
+ });
153
+ },
154
+ };