@h1r-ai/croche-react-native 0.5.5 → 0.7.0

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 (248) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +90 -451
  3. package/THIRD-PARTY-NOTICES +906 -14
  4. package/android/build.gradle +6 -1
  5. package/android/src/androidTest/java/dev/croche/reactnative/WikiFileBridgeTest.kt +126 -0
  6. package/android/src/main/AndroidManifest.xml +0 -5
  7. package/android/src/main/java/dev/croche/reactnative/CoreDispatch.kt +106 -0
  8. package/android/src/main/java/dev/croche/reactnative/CoreWire.kt +217 -0
  9. package/android/src/main/java/dev/croche/reactnative/CrocheRuntimeModule.kt +48 -824
  10. package/android/src/main/java/dev/croche/reactnative/NativePal.kt +68 -0
  11. package/android/src/main/java/dev/croche/reactnative/RNHostPal.kt +9 -0
  12. package/android/src/test/java/dev/croche/reactnative/AgentMemoryTest.kt +64 -41
  13. package/android/src/test/java/dev/croche/reactnative/BackgroundDelegationTest.kt +64 -0
  14. package/android/src/test/java/dev/croche/reactnative/BlobFilesTest.kt +107 -0
  15. package/android/src/test/java/dev/croche/reactnative/ImageAdapterWireTest.kt +70 -0
  16. package/android/src/test/java/dev/croche/reactnative/OpenForwardingFixture.kt +44 -0
  17. package/android/src/test/java/dev/croche/reactnative/ProjectAttestationTest.kt +19 -32
  18. package/android/src/test/java/dev/croche/reactnative/ProjectHandlerStagesTest.kt +32 -0
  19. package/android/src/test/java/dev/croche/reactnative/ProjectRecoveryTest.kt +12 -0
  20. package/android/src/test/java/dev/croche/reactnative/ProjectTimeZoneTest.kt +11 -15
  21. package/android/src/test/java/dev/croche/reactnative/StorageVersionWireTest.kt +37 -0
  22. package/android/src/test/java/dev/croche/reactnative/VerificationDispatchTest.kt +24 -0
  23. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/AndroidEventSink.kt +27 -0
  24. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/AndroidPlatform.kt +10 -8
  25. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BackgroundRegistration.kt +16 -0
  26. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BackgroundWakeWorker.kt +55 -0
  27. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapDecodedImageCodec.kt +162 -0
  28. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapImageCodec.kt +1 -0
  29. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapImageInput.kt +15 -0
  30. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapOrientation.kt +40 -0
  31. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapPalCodec.kt +66 -0
  32. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidAssetPal.kt +30 -0
  33. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidCoreFactory.kt +35 -0
  34. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidCoreHost.kt +116 -0
  35. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidMainDispatcher.kt +17 -0
  36. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidPublicPlatform.kt +17 -0
  37. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidS2Pal.kt +14 -0
  38. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidStateStore.kt +216 -0
  39. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidStoragePal.kt +108 -0
  40. package/android/vendor/CrocheRuntimeSDK/consumer-rules.pro +8 -2
  41. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Adapters.kt +75 -0
  42. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/BindingFacts.kt +29 -0
  43. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ContextConfig.kt +31 -0
  44. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Core.kt +25 -1
  45. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Croche.kt +121 -103
  46. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheAgent.kt +89 -103
  47. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheRuntime.kt +20 -360
  48. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheTools.kt +136 -0
  49. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Decision.kt +170 -0
  50. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/DecodedImageCodec.kt +23 -0
  51. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Effects.kt +26 -21
  52. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/EncodedImageCodec.kt +51 -0
  53. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/GeneratedAppStream.kt +715 -0
  54. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Host.kt +9 -322
  55. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ImagePal.kt +183 -0
  56. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Images.kt +16 -28
  57. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/NativeEvent.kt +59 -0
  58. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/NativeHandleOwner.kt +118 -0
  59. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Platform.kt +10 -74
  60. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectTypes.kt +294 -37
  61. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/PublicResults.kt +127 -0
  62. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ReaderValues.kt +73 -0
  63. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/RunTool.kt +73 -0
  64. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/SendEncoding.kt +23 -21
  65. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/StateStore.kt +90 -0
  66. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/SubscriptionTypes.kt +88 -24
  67. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ffi/croche_ffi.kt +5723 -3088
  68. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/AppEventSink.kt +34 -0
  69. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/AppStoragePal.kt +96 -0
  70. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/BackgroundOsRegistration.kt +35 -0
  71. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/BackgroundSink.kt +37 -0
  72. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreDefinitionCalls.kt +35 -0
  73. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreFactoryCalls.kt +30 -0
  74. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreOptionsEncoding.kt +41 -0
  75. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreStreamCalls.kt +35 -0
  76. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/ForeignCallbacks.kt +127 -0
  77. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/ImageAdapterHost.kt +28 -0
  78. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/JvmCoreHost.kt +70 -0
  79. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/JvmStateStore.kt +125 -0
  80. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/JvmStoragePal.kt +64 -0
  81. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/LifecycleBinding.kt +18 -0
  82. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/NativeCoreInitialization.kt +21 -0
  83. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/NativePlatform.kt +60 -0
  84. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/PalCallbacks.kt +27 -0
  85. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/PlainToolJson.kt +56 -0
  86. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/PublicCalls.kt +43 -0
  87. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/ScopeJson.kt +29 -0
  88. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/StateStoreContract.kt +103 -0
  89. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/StorageVersionContract.kt +40 -0
  90. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/ToolCompletionEncoding.kt +29 -0
  91. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/AtomicKeyFiles.kt +100 -0
  92. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/BlobFiles.kt +157 -0
  93. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/DirectHttpPal.kt +223 -0
  94. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/InstancePayloadPurge.kt +79 -0
  95. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/VersionedKeyFiles.kt +71 -0
  96. package/android/vendor/jniLibs/arm64-v8a/libcroche_ffi.so +0 -0
  97. package/android/vendor/jniLibs/armeabi-v7a/libcroche_ffi.so +0 -0
  98. package/android/vendor/jniLibs/x86_64/libcroche_ffi.so +0 -0
  99. package/croche-react-native.podspec +1 -0
  100. package/dist/package.json +1 -0
  101. package/dist/react-native/src/NativeCrocheRuntime.d.ts +16 -0
  102. package/dist/react-native/src/NativeCrocheRuntime.js +2 -0
  103. package/dist/react-native/src/core-native.d.ts +6 -0
  104. package/dist/react-native/src/core-native.js +316 -0
  105. package/dist/react-native/src/core-wire.d.ts +55 -0
  106. package/dist/react-native/src/core-wire.js +1 -0
  107. package/dist/react-native/src/native-module.d.ts +8 -0
  108. package/dist/react-native/src/native-module.js +53 -0
  109. package/dist/rn-shared-build.json +16 -0
  110. package/dist/runtime/src/adapters.d.ts +8 -0
  111. package/dist/runtime/src/adapters.js +29 -0
  112. package/dist/runtime/src/agent.d.ts +91 -0
  113. package/dist/runtime/src/agent.js +137 -0
  114. package/dist/runtime/src/app-api.d.ts +572 -0
  115. package/dist/runtime/src/app-api.js +1 -0
  116. package/dist/runtime/src/cancel.d.ts +9 -0
  117. package/dist/runtime/src/cancel.js +27 -0
  118. package/dist/runtime/src/core/foreground.d.ts +3 -0
  119. package/dist/runtime/src/core/foreground.js +40 -0
  120. package/dist/runtime/src/core/port.d.ts +247 -0
  121. package/dist/runtime/src/core/port.js +1 -0
  122. package/dist/runtime/src/core/wasm-owner.d.ts +32 -0
  123. package/dist/runtime/src/core/wasm-owner.js +237 -0
  124. package/dist/runtime/src/core/wasm.d.ts +1 -0
  125. package/dist/runtime/src/core/wasm.js +2 -0
  126. package/dist/runtime/src/croche.d.ts +97 -0
  127. package/dist/runtime/src/croche.js +172 -0
  128. package/dist/runtime/src/errors.d.ts +33 -0
  129. package/dist/runtime/src/errors.js +63 -0
  130. package/dist/runtime/src/events.d.ts +5 -0
  131. package/dist/runtime/src/events.js +31 -0
  132. package/dist/runtime/src/generated/app-stream.d.ts +328 -0
  133. package/dist/runtime/src/generated/app-stream.js +127 -0
  134. package/dist/runtime/src/image-input.d.ts +5 -0
  135. package/dist/runtime/src/image-input.js +60 -0
  136. package/dist/runtime/src/index.d.ts +6 -0
  137. package/dist/runtime/src/index.js +5 -0
  138. package/dist/runtime/src/index.native.d.ts +1 -0
  139. package/dist/runtime/src/index.native.js +2 -0
  140. package/dist/runtime/src/json.d.ts +13 -0
  141. package/dist/runtime/src/json.js +120 -0
  142. package/dist/runtime/src/native-adapter.d.ts +3 -0
  143. package/dist/runtime/src/native-adapter.js +30 -0
  144. package/dist/runtime/src/pal/host.d.ts +5 -0
  145. package/dist/runtime/src/pal/host.js +60 -0
  146. package/dist/runtime/src/pal/platform.d.ts +21 -0
  147. package/dist/runtime/src/pal/platform.js +7 -0
  148. package/dist/runtime/src/pal/state-store-lock.d.ts +8 -0
  149. package/dist/runtime/src/pal/state-store-lock.js +2 -0
  150. package/dist/runtime/src/pal/state-store.d.ts +66 -0
  151. package/dist/runtime/src/pal/state-store.js +1 -0
  152. package/dist/runtime/src/pal/storage-version-contract.d.ts +19 -0
  153. package/dist/runtime/src/pal/storage-version-contract.js +68 -0
  154. package/dist/runtime/src/pal/transactional-storage.d.ts +3 -0
  155. package/dist/runtime/src/pal/transactional-storage.js +124 -0
  156. package/dist/runtime/src/rn-entry.d.ts +1 -0
  157. package/dist/runtime/src/rn-entry.js +4 -0
  158. package/dist/runtime/src/run-tool.d.ts +33 -0
  159. package/dist/runtime/src/run-tool.js +7 -0
  160. package/dist/runtime/src/tools.d.ts +35 -0
  161. package/dist/runtime/src/tools.js +94 -0
  162. package/ios/CoreAgentTransport.swift +14 -0
  163. package/ios/CoreDeliveryTransport.swift +58 -0
  164. package/ios/CoreNativePal.swift +98 -0
  165. package/ios/CorePlatformTransport.swift +44 -0
  166. package/ios/CoreWireDispatch.swift +122 -0
  167. package/ios/CoreWireSupport.swift +286 -0
  168. package/ios/CrocheRuntimeBridge.swift +34 -994
  169. package/ios/ProjectPal.swift +49 -0
  170. package/ios/RNCrocheRuntime.mm +18 -201
  171. package/ios/vendor/CrocheRuntimeSDK/AppBuildFacts.swift +112 -0
  172. package/ios/vendor/CrocheRuntimeSDK/BlobFiles.swift +124 -0
  173. package/ios/vendor/CrocheRuntimeSDK/ContextConfig.swift +60 -0
  174. package/ios/vendor/CrocheRuntimeSDK/DirectHTTP.swift +258 -0
  175. package/ios/vendor/CrocheRuntimeSDK/Effects.swift +17 -17
  176. package/ios/vendor/CrocheRuntimeSDK/EncodedImages.swift +85 -0
  177. package/ios/vendor/CrocheRuntimeSDK/FFIStreamPort.swift +26 -157
  178. package/ios/vendor/CrocheRuntimeSDK/GeneratedAppStream.swift +672 -0
  179. package/ios/vendor/CrocheRuntimeSDK/Host.swift +34 -371
  180. package/ios/vendor/CrocheRuntimeSDK/ImagePal.swift +410 -0
  181. package/ios/vendor/CrocheRuntimeSDK/Images.swift +10 -9
  182. package/ios/vendor/CrocheRuntimeSDK/InstancePayloadPurge.swift +88 -0
  183. package/ios/vendor/CrocheRuntimeSDK/JSON.swift +30 -14
  184. package/ios/vendor/CrocheRuntimeSDK/Offload.swift +24 -0
  185. package/ios/vendor/CrocheRuntimeSDK/OpenOptions.swift +1 -155
  186. package/ios/vendor/CrocheRuntimeSDK/Platform.swift +33 -59
  187. package/ios/vendor/CrocheRuntimeSDK/PlatformBackground.swift +289 -0
  188. package/ios/vendor/CrocheRuntimeSDK/PlatformPal.swift +302 -0
  189. package/ios/vendor/CrocheRuntimeSDK/PlatformStateStore.swift +253 -0
  190. package/ios/vendor/CrocheRuntimeSDK/PlatformStorage.swift +281 -0
  191. package/ios/vendor/CrocheRuntimeSDK/Project.swift +4 -269
  192. package/ios/vendor/CrocheRuntimeSDK/Runtime.swift +24 -461
  193. package/ios/vendor/CrocheRuntimeSDK/RuntimeHTTPAdapter.swift +42 -0
  194. package/ios/vendor/CrocheRuntimeSDK/S1/S1Adapters.swift +110 -0
  195. package/ios/vendor/CrocheRuntimeSDK/S1/S1Agent.swift +248 -0
  196. package/ios/vendor/CrocheRuntimeSDK/S1/S1Allowance.swift +20 -0
  197. package/ios/vendor/CrocheRuntimeSDK/S1/S1BindingFacts.swift +33 -0
  198. package/ios/vendor/CrocheRuntimeSDK/S1/S1Core.swift +170 -0
  199. package/ios/vendor/CrocheRuntimeSDK/S1/S1Croche.swift +313 -0
  200. package/ios/vendor/CrocheRuntimeSDK/S1/S1Decision.swift +146 -0
  201. package/ios/vendor/CrocheRuntimeSDK/S1/S1Events.swift +37 -0
  202. package/ios/vendor/CrocheRuntimeSDK/S1/S1HandleOwner.swift +58 -0
  203. package/ios/vendor/CrocheRuntimeSDK/S1/S1Options.swift +346 -0
  204. package/ios/vendor/CrocheRuntimeSDK/S1/S1RunTool.swift +89 -0
  205. package/ios/vendor/CrocheRuntimeSDK/S1/S1Storage.swift +165 -0
  206. package/ios/vendor/CrocheRuntimeSDK/S1/S1TestHooks.swift +100 -0
  207. package/ios/vendor/CrocheRuntimeSDK/S1/S1Tools.swift +278 -0
  208. package/ios/vendor/CrocheRuntimeSDK/S1/S1Verification.swift +27 -0
  209. package/ios/vendor/CrocheRuntimeSDK/S1/StateStoreContract.swift +189 -0
  210. package/ios/vendor/CrocheRuntimeSDK/S1/StorageVersionContract.swift +68 -0
  211. package/ios/vendor/CrocheRuntimeSDK/Storage.swift +23 -269
  212. package/ios/vendor/CrocheRuntimeSDK/SubscriptionTypes.swift +163 -116
  213. package/ios/vendor/CrocheRuntimeSDK/Truncate.swift +12 -0
  214. package/ios/vendor/CrocheRuntimeSDK/croche_ffi.swift +4712 -2469
  215. package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64/Headers/croche_ffiFFI.h +899 -608
  216. package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64/libcroche_ffi.a +0 -0
  217. package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64_x86_64-simulator/Headers/croche_ffiFFI.h +899 -608
  218. package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64_x86_64-simulator/libcroche_ffi.a +0 -0
  219. package/package.json +18 -8
  220. package/scripts/README.md +11 -0
  221. package/scripts/build-shared.mjs +46 -0
  222. package/scripts/build.mjs +11 -0
  223. package/scripts/check-swift-vendor-modules.sh +15 -0
  224. package/scripts/vendor-native.sh +8 -6
  225. package/src/NativeCrocheRuntime.ts +12 -159
  226. package/android/src/main/java/dev/croche/reactnative/AgentMemory.kt +0 -25
  227. package/android/src/main/java/dev/croche/reactnative/ProjectAttestation.kt +0 -17
  228. package/android/src/main/java/dev/croche/reactnative/ProjectTimeZone.kt +0 -14
  229. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/CrocheProjectRecordProvider.kt +0 -32
  230. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/WorkManagerScheduler.kt +0 -146
  231. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/AppStreamBranch.kt +0 -110
  232. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Control.kt +0 -178
  233. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/NativeCoreStreamPort.kt +0 -173
  234. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectBinding.kt +0 -79
  235. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectPalRouting.kt +0 -25
  236. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectPlatform.kt +0 -46
  237. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectRecords.kt +0 -87
  238. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Storage.kt +0 -181
  239. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/StreamHub.kt +0 -227
  240. package/ios/vendor/CrocheRuntimeSDK/Background.swift +0 -59
  241. package/ios/vendor/CrocheRuntimeSDK/Control.swift +0 -192
  242. package/ios/vendor/CrocheRuntimeSDK/StreamHub.swift +0 -453
  243. package/ios/vendor/CrocheRuntimeSDK/SubscriptionRuntime.swift +0 -38
  244. package/src/index.ts +0 -664
  245. package/src/project-types.ts +0 -35
  246. package/src/project.ts +0 -434
  247. package/src/protocol.ts +0 -28
  248. package/src/types.ts +0 -9
@@ -0,0 +1,247 @@
1
+ import type { StateCommitResult, StateCondition, StateListOptions, StateOp, StatePage } from '../pal/state-store.js';
2
+ import type { VersionedValue, WriteOutcome, StorageVersion } from '../pal/storage-version-contract.js';
3
+ import type { Json, PlatformHandle, ImageSupport, ImageInfo, ImageResizeLimits } from '../app-api.js';
4
+ /** JSON text, produced by `jsonText` on the way in (non-JSON text when the value has none; Core refuses it) and by Core on the way out. */
5
+ export type JsonText = string;
6
+ /** Core's cancellation token (WasmCancel). Core decides what a cancel means at each point. */
7
+ export interface CoreCancel {
8
+ cancel(): void;
9
+ isCancelled(): boolean;
10
+ onCancel(callback: () => void): void;
11
+ /** Adapter ownership cleanup, absent on transports without an exported pointer. */
12
+ onDispose?(callback: () => void): void;
13
+ }
14
+ /** The module-level entry points: factories and the statics of `Croche`. */
15
+ export interface CoreModule {
16
+ /** Optional web/Node decision capability; absent on native until its bridge is proven. */
17
+ readonly decisions?: CoreDecisions;
18
+ newCancel(): CoreCancel;
19
+ /** The JSON is the app's WHOLE options object: each opaque reference (a tool definition, the storage, the platform
20
+ * handle) is a null marker there and travels in its own argument. `registrations` keeps the app's order. The
21
+ * storage argument is always a PAL: the app's (then `storage: null` is in the JSON) or the platform default (then
22
+ * the key is absent; Core records custom storage by its presence, #829). */
23
+ open(openJson: JsonText, registrations: CoreToolRegistration[], storage: CoreStoragePal, host: CoreHost, recoveryJson?: JsonText): Promise<CoreCroche>;
24
+ /** `optionsJson` is the app's whole BackgroundOptions, sink and storage as null markers. `platformStorage` is
25
+ * INTERNAL (no app option): the platform-default backend, given only when the selected storage is custom and the
26
+ * platform has a separate OS default store. Node and web have none, so the SDK passes undefined (Atlas #830
27
+ * 1e28b27e: custom storage + no platform store writes no marker and keeps an internal fact, not an error). */
28
+ registerBackground(optionsJson: JsonText, sink: CoreEventSink | undefined, storage: CoreStoragePal, platformStorage: CoreStoragePal | undefined, host: CoreHost): void;
29
+ wakeTimes(openJson: JsonText, queryJson: JsonText | undefined, storage: CoreStoragePal, host: CoreHost): Promise<JsonText>;
30
+ /** A tool definition (WASM: `new CoreToolDefinition(manifestJson, execute)`): Core validates the manifest. */
31
+ defineTool(manifestJson: JsonText, execute: CoreExecute): CoreToolDefinition;
32
+ /** The Core-owned webSearch definition (`coreWebSearch()`), registered by the name `webSearch`. */
33
+ webSearch(): CoreToolDefinition;
34
+ /** The opaque Core-created image tool, shared by registration and runTool. */
35
+ image(): CoreToolDefinition;
36
+ }
37
+ export interface CoreToolDefinition {
38
+ readonly name: string;
39
+ }
40
+ /** One entry of `tools` (WASM: a fresh `new CoreToolRegistration(tool, optionsJson)` per open). `optionsJson` is
41
+ * absent for a bare definition; otherwise the app's WHOLE wrapper object with `tool` as null: bind, commands, guide
42
+ * and unknown keys reach Core, which refuses what it does not take. */
43
+ export interface CoreToolRegistration {
44
+ tool: CoreToolDefinition;
45
+ optionsJson?: JsonText;
46
+ }
47
+ /** The private storage operations Core invokes through the binding.
48
+ * A failing primitive just throws (Core reports storage_error and ignores any
49
+ * code on it); contention is `lock` returning `held` (#837). */
50
+ export interface CoreStoragePal {
51
+ /** The app StateStore's `list`, unchanged: one page of a prefix with values (HLD storage, "Range reads"). */
52
+ listState?(prefix: string, options: StateListOptions): Promise<StatePage>;
53
+ commit?(ops: readonly StateOp[], condition: StateCondition): Promise<StateCommitResult>;
54
+ readVersioned(key: string): Promise<VersionedValue>;
55
+ writeIf(key: string, value: string | null, expect: StorageVersion | null): Promise<WriteOutcome>;
56
+ read(key: string): Promise<string | null>;
57
+ write(key: string, value: string): Promise<void>;
58
+ remove(key: string): Promise<void>;
59
+ /** Core calls under exact instance lifetime custody; erases every payload file of one instance. */
60
+ purgeInstance(prefix: string, credentialKey?: string): Promise<void>;
61
+ list(prefix: string): Promise<string[]>;
62
+ lock(name: string): Promise<'acquired' | 'held'>;
63
+ unlock(name: string): Promise<void>;
64
+ secrets: {
65
+ read(key: string): Promise<string | null>;
66
+ write(key: string, value: string): Promise<void>;
67
+ remove(key: string): Promise<void>;
68
+ };
69
+ }
70
+ /** Owned image bytes for a send, indexing `input.input` (S1). The 0.6 TS App API has no bytes input (an image is
71
+ * `data` or `uri` in the input JSON, read by Core), so the wrapper passes an empty list. */
72
+ export interface CoreAttachmentInput {
73
+ element: number;
74
+ bytes: Uint8Array;
75
+ }
76
+ /** Core calls a tool: the call `{key, args}` and context `{agentId, instance, user, causedBy}` as JSON, plus its token.
77
+ * It answers ONE ToolCompletion as JSON text, the transport Core reads unchanged (no adapter mapping). */
78
+ export interface CoreAttachmentReader {
79
+ attachment(id: string): Promise<JsonText>;
80
+ }
81
+ export type CoreExecute = (callJson: JsonText, contextJson: JsonText, cancel: CoreCancel, attachments: CoreAttachmentReader) => Promise<JsonText>;
82
+ /**
83
+ * What one execute did, as facts, discriminated by `type` (Atlas's S1 pin, Keel 10-30; the same on every SDK). Core
84
+ * picks the model text, the codes (`tool_failed`, `invalid_tool_result`), the timeout and the settlement. The SDK maps
85
+ * no codes.
86
+ */
87
+ export type ToolCompletion = {
88
+ type: 'json';
89
+ value: Json;
90
+ } | {
91
+ type: 'result';
92
+ content: Json;
93
+ } | {
94
+ type: 'empty';
95
+ } | {
96
+ type: 'invalid_result';
97
+ } | {
98
+ type: 'tool_error';
99
+ message: string;
100
+ } | {
101
+ type: 'handler_error';
102
+ error?: ThrownError;
103
+ } | {
104
+ type: 'cancelled';
105
+ } | {
106
+ type: 'unavailable';
107
+ };
108
+ /** A thrown value as the transport carries it: its own `name` (as type) and `message`, both strings. */
109
+ export interface ThrownError {
110
+ type: string;
111
+ message: string;
112
+ }
113
+ /** A thrown value's own string fields, read once (event delivery); anything else reads as absent. */
114
+ export interface ThrownFacts {
115
+ name?: string;
116
+ message?: string;
117
+ code?: string;
118
+ }
119
+ /**
120
+ * Delivers Core's events, one JSON object each, in Core's order (S1 checkpoint: `eventSink(deliveryId, eventJson,
121
+ * delivery)`). The SDK calls `tryEnter()` synchronously right before entering the app's handler (false = do not
122
+ * enter, do not complete), then `complete(outcomeJson)` once the handler has FINISHED: returned, or its thenable
123
+ * settled. Core assigns the codes (`handler_failed`) and holds the next event until then; the SDK keeps no queue.
124
+ */
125
+ export type CoreEventSink = (deliveryId: string, eventJson: JsonText, delivery: CoreDelivery) => void;
126
+ export interface CoreDelivery {
127
+ tryEnter(): boolean;
128
+ complete(outcomeJson: JsonText): void;
129
+ }
130
+ /** `unavailable` = the handler could not be reached (a post failure, a teardown): a transport fact on ANY binding. */
131
+ export type DeliveryOutcome = {
132
+ outcome: 'returned';
133
+ } | {
134
+ outcome: 'threw';
135
+ error?: ThrownFacts;
136
+ } | {
137
+ outcome: 'unavailable';
138
+ };
139
+ export interface CoreCroche {
140
+ runTool(name: string, argsJson: JsonText, optionsJson: JsonText, cancel: CoreCancel): Promise<JsonText>;
141
+ allowanceSet(limitJson: JsonText): Promise<unknown>;
142
+ verification(): Promise<JsonText>;
143
+ deleteData(scopeJson: JsonText | undefined): Promise<void>;
144
+ attachment(id: string): Promise<JsonText>;
145
+ deleteAttachment(id: string): Promise<void>;
146
+ /** JSON `{items, cursor?}`; `optionsJson` is `{limit?, cursor?}`. The same for every list below. */
147
+ listAttachments(optionsJson: JsonText | undefined): Promise<JsonText>;
148
+ agent(id: string, optionsJson: JsonText | undefined): Promise<CoreAgent>;
149
+ deliverDue(optionsJson: JsonText | undefined, cancel: CoreCancel): Promise<JsonText>;
150
+ wikiPut(docJson: JsonText): Promise<void>;
151
+ wikiRemove(path: string): Promise<void>;
152
+ wikiList(optionsJson: JsonText | undefined): Promise<JsonText>;
153
+ debugAttach(optionsJson: JsonText): Promise<JsonText>;
154
+ debugDetach(): Promise<void>;
155
+ shutdown(): Promise<void>;
156
+ }
157
+ export interface CoreAgent {
158
+ attachment(id: string): Promise<JsonText>;
159
+ deleteAttachment(id: string): Promise<void>;
160
+ listAttachments(optionsJson: JsonText | undefined): Promise<JsonText>;
161
+ copyAttachment(sourceJson: JsonText): Promise<JsonText>;
162
+ releaseAttachment(id: string): Promise<void>;
163
+ /** Immutable identity, readable after close (Atlas S1 pin). */
164
+ readonly id: string;
165
+ readonly instance: string | null;
166
+ /** A fresh token on every call, signal or not (S1: WASM borrows it). It stays bridged to the app's signal:
167
+ * cancelled before acceptance = never queued; after = cancel(id). */
168
+ send(inputJson: JsonText, images: CoreAttachmentInput[], optionsJson: JsonText | undefined, cancel: CoreCancel): Promise<JsonText>;
169
+ request(inputJson: JsonText, images: CoreAttachmentInput[], optionsJson: JsonText | undefined, cancel: CoreCancel): Promise<JsonText>;
170
+ subscribe(selectionJson: JsonText, sink: CoreEventSink): CoreSubscription;
171
+ cancel(id: string | undefined): Promise<void>;
172
+ clearHistory(options?: string): Promise<void>;
173
+ memoryList(optionsJson: JsonText | undefined): Promise<JsonText>;
174
+ memoryDelete(id: string): Promise<void>;
175
+ memoryClear(): Promise<void>;
176
+ memoryEnabled(on: boolean): Promise<void>;
177
+ setTools(scopeJson: JsonText): Promise<void>;
178
+ resetTools(): Promise<void>;
179
+ setWiki(scopeJson: JsonText): Promise<void>;
180
+ resetWiki(): Promise<void>;
181
+ shutdown(): Promise<void>;
182
+ }
183
+ /** Separate capability: no shared CoreAgent method is required of an unbridged native transport. */
184
+ export interface CoreDecisions {
185
+ decide(agent: CoreAgent, inputJson: JsonText, optionsJson: JsonText | undefined, cancel: CoreCancel): Promise<JsonText>;
186
+ }
187
+ export interface CoreSubscription {
188
+ history(optionsJson: JsonText): Promise<void>;
189
+ shutdown(): void;
190
+ readonly ended: boolean;
191
+ }
192
+ /** One HTTP request as Core built it. `connectTo` = the checked address Core pinned (SSRF: Core decides). */
193
+ export interface CoreHttpRequest {
194
+ url: string;
195
+ method: string;
196
+ headers: [string, string][];
197
+ body?: string;
198
+ timeoutMs: number;
199
+ maxResponseBytes: number;
200
+ connectTo?: string;
201
+ }
202
+ export interface CoreBodySink {
203
+ head(status: number, headers: [string, string][]): void;
204
+ chunk(bytes: Uint8Array): boolean;
205
+ }
206
+ export interface PlatformFacts {
207
+ targetKind?: 'ios-device' | 'ios-simulator' | 'android' | 'other';
208
+ debuggable?: boolean;
209
+ locale?: string;
210
+ attestationPlatform?: string;
211
+ }
212
+ /** The platform's effects and facts. Storage is NOT here: it is its own argument (CoreStoragePal). */
213
+ export interface CoreHost {
214
+ blobGet?(key: string): Promise<Uint8Array | null>;
215
+ blobPut?(key: string, bytes: Uint8Array): Promise<void>;
216
+ blobDelete?(key: string): Promise<void>;
217
+ blobList?(prefix: string, cursor?: string): Promise<import('../app-api.js').BlobListPage>;
218
+ blobPurgeStaging?(prefix: string): Promise<void>;
219
+ /** An app asset (a wiki `file`), resolved by the platform rule; null = absent. */
220
+ readAsset(path: string): Promise<Uint8Array | null>;
221
+ http(request: CoreHttpRequest, sink: CoreBodySink, cancel: CoreCancel): Promise<void>;
222
+ /** Every A/AAAA answer, unfiltered; Core checks them and chooses `connectTo`. */
223
+ resolve(host: string, cancel: CoreCancel): Promise<string[]>;
224
+ nowMs(): number;
225
+ utcOffsetMinutes(atMs: number): number;
226
+ sleep(ms: number): Promise<void>;
227
+ /** Optional platform wake hint (null = none). Core's per-Runtime owned loop drives timed upkeep
228
+ * through PAL sleep; post-reply upkeep starts directly. No shared SDK timer decides upkeep. */
229
+ wake(atMs: number | null, onWake?: () => void): void;
230
+ random(): string;
231
+ /** Sampled at open (Core's CrocheHost). Absent = unknown; the SDK never fills a default. */
232
+ platformFacts(): PlatformFacts;
233
+ readonly platform: PlatformHandle | undefined;
234
+ readImage(request: {
235
+ source: {
236
+ kind: 'local';
237
+ uri: string;
238
+ };
239
+ maxBytes: number;
240
+ }, cancel: CoreCancel): Promise<Uint8Array>;
241
+ imageSupport(): ImageSupport | undefined;
242
+ /** Extensible transport dispatch; later operations do not require a new callback. */
243
+ imageOperation(operation: string, bytes: Uint8Array, options: ImageResizeLimits | Record<string, never>, cancel: CoreCancel): Promise<{
244
+ info?: ImageInfo;
245
+ bytes?: Uint8Array;
246
+ }>;
247
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,32 @@
1
+ type Kind = 'croche' | 'agent' | 'subscription' | 'token' | 'callback' | 'delivery';
2
+ type Handle = Record<PropertyKey, any> & {
3
+ free?: () => void;
4
+ };
5
+ declare class Owner {
6
+ readonly target: Handle;
7
+ readonly kind: Kind;
8
+ readonly mapError: (error: unknown) => unknown;
9
+ parent?: Owner | undefined;
10
+ readonly children: Set<Owner>;
11
+ readonly listeners: Set<() => void>;
12
+ readonly snapshots: Map<PropertyKey, unknown>;
13
+ closing?: Promise<void>;
14
+ disposed: boolean;
15
+ readonly proxy: object;
16
+ constructor(target: Handle, kind: Kind, mapError: (error: unknown) => unknown, parent?: Owner | undefined);
17
+ isAsync(key: PropertyKey): boolean;
18
+ refuse(key: PropertyKey, args: unknown[]): never | Promise<never>;
19
+ snapshot(): void;
20
+ shutdown(): Promise<void> | void;
21
+ dispose(): void;
22
+ }
23
+ export declare function owned<T>(target: T, kind: Kind, mapError: (error: unknown) => unknown): T;
24
+ export declare function unwrapOwned(value: unknown): unknown;
25
+ /** Callback-owned carriers end when their host callback does, not at a later GC. */
26
+ export declare function releaseOwned(value: unknown): void;
27
+ /** Delivery completion may outlive the synchronous event-sink call. */
28
+ export declare function managedSink(sink: (...args: any[]) => unknown, mapError: (error: unknown) => unknown, parent?: Owner): (id: string, event: string, delivery: Handle) => unknown;
29
+ /** WASM host callbacks receive exported owners too (cancel tokens and HTTP sinks). */
30
+ export declare function managedHost<T extends object>(host: T, mapError: (error: unknown) => unknown): T;
31
+ export declare function callbackOwners<T>(run: (args: unknown[]) => T, args: unknown[], mapError: (error: unknown) => unknown): T;
32
+ export {};
@@ -0,0 +1,237 @@
1
+ // Owns WASM pointers only: shutdown/drain remains Core's decision. No pointer is read after disposal.
2
+ import { CrocheError } from '../errors.js';
3
+ import { foreground } from './foreground.js';
4
+ const owners = new WeakMap();
5
+ const originals = new WeakMap();
6
+ const asyncMethods = new Set(['send', 'request', 'decide', 'cancel', 'clearHistory', 'memoryList', 'memoryDelete', 'memoryClear',
7
+ 'attachment', 'deleteAttachment', 'listAttachments', 'copyAttachment', 'releaseAttachment', 'memoryEnabled', 'setTools', 'resetTools', 'setWiki', 'resetWiki', 'agent', 'deleteData', 'deliverDue', 'runTool', 'wikiPut', 'wikiRemove', 'wikiList', 'verification', 'debugAttach', 'debugDetach', 'history']);
8
+ const closed = () => new CrocheError('closed', 'This handle is closed.', 'closed');
9
+ class Owner {
10
+ target;
11
+ kind;
12
+ mapError;
13
+ parent;
14
+ children = new Set();
15
+ listeners = new Set();
16
+ snapshots = new Map();
17
+ closing;
18
+ disposed = false;
19
+ proxy;
20
+ constructor(target, kind, mapError, parent) {
21
+ this.target = target;
22
+ this.kind = kind;
23
+ this.mapError = mapError;
24
+ this.parent = parent;
25
+ parent?.children.add(this);
26
+ this.proxy = new Proxy(target, { get: (_, key) => {
27
+ if (key === 'shutdown')
28
+ return () => this.shutdown();
29
+ if (kind === 'token' && key === 'onDispose')
30
+ return (listener) => this.listeners.add(listener);
31
+ if (this.disposed || this.closing) {
32
+ if (kind === 'delivery' && key === 'tryEnter')
33
+ return () => false;
34
+ if (kind === 'delivery' && key === 'complete')
35
+ return () => { };
36
+ if (kind === 'subscription' && key === 'ended')
37
+ return true;
38
+ if (this.snapshots.has(key))
39
+ return this.snapshots.get(key);
40
+ if (this.isAsync(key))
41
+ return (...args) => this.refuse(key, args);
42
+ throw closed();
43
+ }
44
+ const member = Reflect.get(target, key, target);
45
+ if (typeof member !== 'function')
46
+ return member;
47
+ return (...args) => {
48
+ // Saved methods must check ownership again, not only at property access.
49
+ if (this.disposed || this.closing) {
50
+ if (this.isAsync(key))
51
+ return this.refuse(key, args);
52
+ throw closed();
53
+ }
54
+ // send's token remains live after its receipt (abort still means cancel(id)).
55
+ // A request token has no borrower after its terminal result settles.
56
+ const terminalTokens = [];
57
+ const settled = () => { for (const token of terminalTokens)
58
+ token.dispose(); };
59
+ try {
60
+ const invoke = () => member.apply(target, args.map(arg => {
61
+ if (key === 'subscribe' && typeof arg === 'function')
62
+ return managedSink(arg, mapError, this);
63
+ const child = typeof arg === 'object' && arg !== null ? owners.get(arg) : undefined;
64
+ if (child?.kind === 'token') {
65
+ this.children.add(child);
66
+ child.parent ??= this;
67
+ if (key === 'request')
68
+ terminalTokens.push(child);
69
+ }
70
+ return unwrapOwned(arg);
71
+ }));
72
+ const result = kind === 'croche' || kind === 'agent' || kind === 'subscription'
73
+ ? foreground(invoke) : invoke();
74
+ if (kind === 'delivery' && (key === 'complete' || (key === 'tryEnter' && result === false)))
75
+ this.dispose();
76
+ const wrap = (value) => {
77
+ if (key === 'agent' || key === 'subscribe') {
78
+ const child = new Owner(value, key === 'agent' ? 'agent' : 'subscription', mapError, this);
79
+ if (this.disposed) {
80
+ child.dispose();
81
+ throw closed();
82
+ }
83
+ return child.proxy;
84
+ }
85
+ return value;
86
+ };
87
+ if (result instanceof Promise) {
88
+ const answer = result.then(wrap, error => { throw mapError(error); });
89
+ return terminalTokens.length ? answer.finally(settled) : answer;
90
+ }
91
+ const answer = wrap(result);
92
+ settled();
93
+ return answer;
94
+ }
95
+ catch (error) {
96
+ settled();
97
+ throw mapError(error);
98
+ }
99
+ };
100
+ } });
101
+ owners.set(this.proxy, this);
102
+ originals.set(this.proxy, target);
103
+ }
104
+ isAsync(key) {
105
+ return !['token', 'callback', 'delivery'].includes(this.kind) && asyncMethods.has(String(key));
106
+ }
107
+ refuse(key, args) {
108
+ // A token created for a call refused before entry has no Core borrower or owner scope.
109
+ for (const arg of args) {
110
+ const token = typeof arg === 'object' && arg !== null ? owners.get(arg) : undefined;
111
+ if (token?.kind === 'token' && !token.parent)
112
+ token.dispose();
113
+ }
114
+ if (this.isAsync(key))
115
+ return Promise.reject(closed());
116
+ throw closed();
117
+ }
118
+ snapshot() {
119
+ for (const key of this.kind === 'agent' ? ['id', 'instance'] : []) {
120
+ try {
121
+ this.snapshots.set(key, this.target[key]);
122
+ }
123
+ catch { /* recovery */ }
124
+ }
125
+ }
126
+ shutdown() {
127
+ if (this.closing)
128
+ return this.closing;
129
+ if (this.disposed)
130
+ return this.kind === 'subscription' ? undefined : Promise.resolve();
131
+ this.snapshot();
132
+ if (this.kind === 'subscription') {
133
+ this.target.shutdown();
134
+ this.dispose();
135
+ return;
136
+ }
137
+ let resolve, reject;
138
+ const closing = this.closing = new Promise((accept, refuse) => { resolve = accept; reject = refuse; });
139
+ const failed = (error) => {
140
+ this.closing = undefined; // No completed drain: retain ownership for retry.
141
+ reject(this.mapError(error));
142
+ };
143
+ try {
144
+ // Enter Core synchronously, preserving its existing close fence before the first await.
145
+ foreground(() => Promise.resolve(this.target.shutdown())).then(async () => {
146
+ this.dispose();
147
+ resolve();
148
+ }).catch(failed);
149
+ }
150
+ catch (error) {
151
+ failed(error);
152
+ }
153
+ return closing;
154
+ }
155
+ dispose() {
156
+ if (this.disposed)
157
+ return;
158
+ this.snapshot();
159
+ for (const child of this.children) {
160
+ // Their own drain/completion owns release; closing a parent must not free them early or wait on app code.
161
+ if (child.closing || child.kind === 'delivery')
162
+ continue;
163
+ if (child.kind === 'subscription' && !child.disposed)
164
+ child.target.shutdown();
165
+ child.dispose();
166
+ }
167
+ this.children.clear();
168
+ this.disposed = true;
169
+ for (const listener of this.listeners)
170
+ listener();
171
+ this.listeners.clear();
172
+ this.target.free?.();
173
+ this.parent?.children.delete(this);
174
+ originals.delete(this.proxy);
175
+ }
176
+ }
177
+ export function owned(target, kind, mapError) {
178
+ return new Owner(target, kind, mapError).proxy;
179
+ }
180
+ export function unwrapOwned(value) {
181
+ return typeof value === 'object' && value !== null ? originals.get(value) ?? value : value;
182
+ }
183
+ /** Callback-owned carriers end when their host callback does, not at a later GC. */
184
+ export function releaseOwned(value) {
185
+ if (typeof value === 'object' && value !== null)
186
+ owners.get(value)?.dispose();
187
+ }
188
+ /** Delivery completion may outlive the synchronous event-sink call. */
189
+ export function managedSink(sink, mapError, parent) {
190
+ return (id, event, delivery) => {
191
+ // Native delivery IDs are retired by the bridge on completion; only WASM exports carry free().
192
+ if (typeof delivery.free !== 'function')
193
+ return sink(id, event, delivery);
194
+ const owner = new Owner(delivery, 'delivery', mapError, parent);
195
+ if (parent?.disposed)
196
+ owner.dispose();
197
+ try {
198
+ return sink(id, event, owner.proxy);
199
+ }
200
+ catch (error) {
201
+ owner.dispose();
202
+ throw error;
203
+ }
204
+ };
205
+ }
206
+ /** WASM host callbacks receive exported owners too (cancel tokens and HTTP sinks). */
207
+ export function managedHost(host, mapError) {
208
+ return new Proxy(host, { get(target, key) {
209
+ const member = Reflect.get(target, key, target);
210
+ if (typeof member !== 'function')
211
+ return member;
212
+ return (...args) => callbackOwners(values => member.apply(target, values), args, mapError);
213
+ } });
214
+ }
215
+ export function callbackOwners(run, args, mapError) {
216
+ const temporary = [];
217
+ const values = args.map(value => {
218
+ if (typeof value !== 'object' || value === null || typeof value.free !== 'function')
219
+ return value;
220
+ const owner = new Owner(value, 'callback', mapError);
221
+ temporary.push(owner);
222
+ return owner.proxy;
223
+ });
224
+ const dispose = () => { for (const owner of temporary)
225
+ owner.dispose(); };
226
+ try {
227
+ const result = run(values);
228
+ if (result instanceof Promise)
229
+ return result.finally(dispose);
230
+ dispose();
231
+ return result;
232
+ }
233
+ catch (error) {
234
+ dispose();
235
+ throw error;
236
+ }
237
+ }
@@ -0,0 +1 @@
1
+ export { coreModule } from '../native-adapter.js';
@@ -0,0 +1,2 @@
1
+ // Native Core transport selected at RN build time.
2
+ export { coreModule } from '../native-adapter.js';
@@ -0,0 +1,97 @@
1
+ import { type Agent } from './agent.js';
2
+ import type { Verification, AgentOptions, BackgroundOptions, CrocheDebugger, DeleteScope, DeliverDueResult, OpenOptions, WakeTimes, WikiDoc, ListOptions, Page } from './app-api.js';
3
+ import { type RunToolResult } from './run-tool.js';
4
+ import type { Json } from './app-api.js';
5
+ /** A user's Croche session for opening agents, running tools and accessing shared resources. */
6
+ export declare class Croche {
7
+ #private;
8
+ private constructor();
9
+ /** Open the app’s user session before letting that user talk to an agent or run a tool. */
10
+ static open(options: OpenOptions, recovery?: {
11
+ recover: 'delete';
12
+ }): Promise<Croche>;
13
+ /**
14
+ * Honor a user’s request to erase one workspace or all their local Croche data.
15
+ *
16
+ * Deletes this user's local data in the scope. Core closes selected agents first.
17
+ */
18
+ deleteData(scope?: DeleteScope): Promise<void>;
19
+ /**
20
+ * Let the app keep up with due work when its UI is no longer in the foreground.
21
+ *
22
+ * Once at app start. Core keeps BackgroundEvents durably and delivers each at least once to the sink. Use the same
23
+ * adapters as open() (the platform defaults when omitted).
24
+ */
25
+ static registerBackground(options?: BackgroundOptions): void;
26
+ /**
27
+ * Let a server schedule just the users whose background work is due.
28
+ *
29
+ * Read delivery deadlines without opening a project. before/after are epoch milliseconds; after is inclusive.
30
+ */
31
+ static wakeTimes(options: OpenOptions, query?: {
32
+ before?: number;
33
+ after?: number;
34
+ limit?: number;
35
+ }): Promise<WakeTimes>;
36
+ /** Let a host deliver scheduled work when its timer or alarm fires. */
37
+ deliverDue(options?: {
38
+ signal?: AbortSignal;
39
+ }): Promise<DeliverDueResult>;
40
+ /** Give each chat, case, or workspace its own conversation while reusing the app’s agent definition. */
41
+ agent(id: string, options?: AgentOptions): Promise<Agent>;
42
+ /**
43
+ * Let an app button run a tool outside chat, such as generating an image for a form.
44
+ *
45
+ * App tools run outside every conversation. Recovery uses the same required id.
46
+ */
47
+ runTool(name: string, args: Record<string, Json>, options: {
48
+ id: string;
49
+ signal?: AbortSignal;
50
+ }): Promise<RunToolResult>;
51
+ /**
52
+ * Load a shared attachment when the user opens its preview.
53
+ *
54
+ * Read from Core at every access.
55
+ */
56
+ attachment(id: string): Promise<{
57
+ mediaType: string;
58
+ data: string;
59
+ }>;
60
+ /** Let the user remove a shared attachment they no longer want to keep. */
61
+ deleteAttachment(id: string): Promise<void>;
62
+ /** Populate a picker of attachments shared by this user’s agents, newest first, one page at a time. */
63
+ listAttachments(options?: ListOptions): Promise<Page<import('./app-api.js').Attachment>>;
64
+ /**
65
+ * Set this user's allowance: the most credits the runtime lets this user spend per UTC day.
66
+ * Absolute, it replaces the earlier value; `null` returns the user to Studio's default. The runtime
67
+ * counts and enforces it from its own storage; Croche Cloud keeps no per-user ledger
68
+ * (founder 2026-11-21: «사용자 한도 안에서는 런타임이 보호하고.. (클라우드x»).
69
+ */
70
+ readonly allowance: {
71
+ /** Set the user's absolute UTC-day limit in credits. Pass null to use Studio's default. */
72
+ set: (limit: number | null) => Promise<void>;
73
+ };
74
+ /**
75
+ * Let the app show how Croche Cloud verified this installation, or explain a withheld key.
76
+ *
77
+ * Read-only, from stored registration state; it never calls Cloud.
78
+ */
79
+ verification(): Promise<Verification>;
80
+ /** Access the project's wiki documents available to this user. */
81
+ readonly wiki: {
82
+ /** Make an updated help article available to agents in the current app session. */
83
+ put: (doc: WikiDoc) => Promise<void>;
84
+ /** Stop agents from using a help article the app has withdrawn. */
85
+ remove: (path: string) => Promise<void>;
86
+ /** Show which help articles the app has made available to its agents. */
87
+ list: (options?: ListOptions) => Promise<Page<WikiDoc>>;
88
+ };
89
+ /** Access debugger controls for this session. */
90
+ readonly debugger: CrocheDebugger;
91
+ /**
92
+ * Release the user’s session when they sign out or the app switches accounts.
93
+ *
94
+ * Resolves once new work has stopped; Core continues the bounded final delivery.
95
+ */
96
+ close(): Promise<void>;
97
+ }