@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,2 @@
1
+ import { TurboModuleRegistry } from 'react-native';
2
+ export default TurboModuleRegistry.getEnforcing('CrocheRuntime');
@@ -0,0 +1,6 @@
1
+ import type { CoreStoragePal, CoreModule } from '../../runtime/src/core/port';
2
+ import type { ImageAdapter } from '../../runtime/src/app-api';
3
+ import type { NativeCoreWire } from './core-wire';
4
+ /** Default native encoded-image effects use the same owned cancel handles as Core. */
5
+ export declare function createNativeImageAdapter(wire: NativeCoreWire): ImageAdapter | undefined;
6
+ export declare function createNativeCore(wire: NativeCoreWire, defaultStorage?: CoreStoragePal): CoreModule;
@@ -0,0 +1,316 @@
1
+ import { captureReadVersioned, captureWriteIf } from '../../runtime/src/pal/storage-version-contract.js';
2
+ import { owned } from '../../runtime/src/core/wasm-owner';
3
+ import { CrocheError, thrownFacts } from '../../runtime/src/errors';
4
+ function answer(json) {
5
+ const result = JSON.parse(json);
6
+ if ('error' in result) {
7
+ const { code, message, category, path, retryAfter } = result.error;
8
+ const error = new CrocheError(code, message, category, retryAfter);
9
+ if (path !== undefined)
10
+ Object.assign(error, { path });
11
+ throw error;
12
+ }
13
+ return result.value;
14
+ }
15
+ /** Default native encoded-image effects use the same owned cancel handles as Core. */
16
+ export function createNativeImageAdapter(wire) {
17
+ const sync = (method, args = []) => answer(wire.callSync('', method, JSON.stringify(args)));
18
+ const support = sync('platformImageSupport');
19
+ if (!support)
20
+ return undefined;
21
+ async function operation(method, bytes, options, signal) {
22
+ const token = sync('newCancel');
23
+ const abort = () => { answer(wire.callSync(token, 'cancel', '[]')); };
24
+ signal.addEventListener('abort', abort, { once: true });
25
+ try {
26
+ if (signal.aborted)
27
+ abort();
28
+ return answer(await wire.call('', 'platformImageOperation', JSON.stringify([method, Array.from(bytes), options, token])));
29
+ }
30
+ finally {
31
+ signal.removeEventListener('abort', abort);
32
+ wire.callSync(token, 'release', '[]');
33
+ }
34
+ }
35
+ return { kind: 'image', support,
36
+ info: async (bytes, { signal }) => (await operation('info', bytes, {}, signal)).info,
37
+ resize: async (bytes, limits, { signal }) => new Uint8Array((await operation('resize', bytes, limits, signal)).bytes),
38
+ };
39
+ }
40
+ export function createNativeCore(wire, defaultStorage) {
41
+ let next = 0;
42
+ const hosts = new Map(), storages = new Map(), sinks = new Map();
43
+ const executors = new Map(), tokens = new Map();
44
+ const ids = new WeakMap();
45
+ const toolFactories = new WeakMap();
46
+ const references = new Map();
47
+ let sweeping = false;
48
+ const release = (id) => { try {
49
+ wire.callSync(id, 'release', '[]');
50
+ }
51
+ catch { /* module teardown */ } };
52
+ function sweep() {
53
+ if (sweeping)
54
+ return;
55
+ sweeping = true;
56
+ try {
57
+ for (const [id, record] of references) {
58
+ if (record.ref.deref())
59
+ continue;
60
+ references.delete(id);
61
+ tokens.delete(id);
62
+ if (!record.mode) {
63
+ release(id);
64
+ continue;
65
+ }
66
+ if (record.mode === 'sync') {
67
+ try {
68
+ wire.callSync(id, 'shutdown', '[]');
69
+ }
70
+ finally {
71
+ release(id);
72
+ }
73
+ }
74
+ else
75
+ void wire.call(id, 'shutdown', '[]').then(() => release(id), () => release(id));
76
+ }
77
+ }
78
+ finally {
79
+ sweeping = false;
80
+ }
81
+ }
82
+ const name = (kind) => `${kind}:${++next}`;
83
+ const sync = (id, method, args = []) => { sweep(); const value = answer(wire.callSync(id, method, JSON.stringify(args))); return value; };
84
+ const call = async (id, method, args = [], images) => { sweep(); const value = answer(await wire.call(id, method, JSON.stringify(args), images)); return value; };
85
+ const remember = (id, object, mode) => {
86
+ Object.defineProperty(object, 'free', { value: () => { references.delete(id); tokens.delete(id); release(id); } });
87
+ ids.set(object, id);
88
+ references.set(id, { ref: new WeakRef(object), mode });
89
+ return object;
90
+ };
91
+ const handle = (object) => {
92
+ const id = ids.get(object);
93
+ if (id === undefined)
94
+ throw Error('Foreign native Core handle');
95
+ return id;
96
+ };
97
+ class NativeCancel {
98
+ id;
99
+ listeners = [];
100
+ constructor(id) {
101
+ this.id = id;
102
+ tokens.set(id, new WeakRef(this));
103
+ ids.set(this, id);
104
+ references.set(id, { ref: new WeakRef(this) });
105
+ }
106
+ free() { references.delete(this.id); tokens.delete(this.id); release(this.id); }
107
+ cancel() { sync(this.id, 'cancel'); }
108
+ isCancelled() { return sync(this.id, 'isCancelled'); }
109
+ onCancel(callback) { this.listeners.push(callback); }
110
+ }
111
+ const attachmentReader = (id) => remember(id, { attachment: key => call(id, 'attachment', [key]) }, 'async');
112
+ const token = (id) => tokens.get(id)?.deref() ?? new NativeCancel(id);
113
+ const sinkId = (sink) => { const id = name('sink'); sinks.set(id, sink); return id; };
114
+ const hostId = (host) => { const id = name('host'); hosts.set(id, host); return id; };
115
+ const storageId = (storage) => { const id = name('storage'); storages.set(id, storage); return id; };
116
+ const registrations = (tools, temporary) => tools.map(({ tool, optionsJson }) => {
117
+ const make = toolFactories.get(tool), id = make ? make() : handle(tool);
118
+ if (make)
119
+ temporary.push(id);
120
+ return { tool: id, ...(optionsJson === undefined ? {} : { optionsJson }) };
121
+ });
122
+ const subscription = (id) => remember(id, {
123
+ history: options => call(id, 'history', [options]),
124
+ shutdown: () => { sync(id, 'shutdown'); }, get ended() { return sync(id, 'ended'); },
125
+ }, 'sync');
126
+ const agent = (id) => remember(id, {
127
+ attachment: key => call(id, 'attachment', [key]), deleteAttachment: key => call(id, 'deleteAttachment', [key]),
128
+ listAttachments: options => call(id, 'listAttachments', [options]), copyAttachment: source => call(id, 'copyAttachment', [source]), releaseAttachment: key => call(id, 'releaseAttachment', [key]),
129
+ get id() { return sync(id, 'id'); }, get instance() { return sync(id, 'instance'); },
130
+ decide: (input, options, cancel) => call(id, 'decide', [input, options, handle(cancel)]),
131
+ send: (input, images, options, cancel) => call(id, 'send', [input, options, handle(cancel)], images),
132
+ request: (input, images, options, cancel) => call(id, 'request', [input, options, handle(cancel)], images),
133
+ subscribe: (selection, sink) => subscription(sync(id, 'subscribe', [selection, sinkId(sink)])),
134
+ cancel: input => call(id, 'cancel', [input]), clearHistory: options => call(id, 'clearHistory', [options]),
135
+ memoryList: options => call(id, 'memoryList', [options]), memoryDelete: key => call(id, 'memoryDelete', [key]),
136
+ memoryClear: () => call(id, 'memoryClear'), memoryEnabled: on => call(id, 'memoryEnabled', [on]),
137
+ setTools: scope => call(id, 'setTools', [scope]), resetTools: () => call(id, 'resetTools'),
138
+ setWiki: scope => call(id, 'setWiki', [scope]), resetWiki: () => call(id, 'resetWiki'),
139
+ shutdown: () => call(id, 'shutdown'),
140
+ }, 'async');
141
+ const croche = (id) => remember(id, {
142
+ runTool: (name, args, options, cancel) => call(id, 'runTool', [name, args, options, handle(cancel)]),
143
+ deleteData: scope => call(id, 'deleteData', [scope]),
144
+ attachment: key => call(id, 'attachment', [key]), deleteAttachment: key => call(id, 'deleteAttachment', [key]), listAttachments: options => call(id, 'listAttachments', [options]),
145
+ allowanceSet: limit => call(id, 'allowanceSet', [limit]), verification: () => call(id, 'verification'),
146
+ agent: async (key, options) => agent(await call(id, 'agent', [key, options])),
147
+ deliverDue: (options, cancel) => call(id, 'deliverDue', [options, handle(cancel)]),
148
+ wikiPut: doc => call(id, 'wikiPut', [doc]), wikiRemove: path => call(id, 'wikiRemove', [path]),
149
+ wikiList: options => call(id, 'wikiList', [options]),
150
+ debugAttach: options => call(id, 'debugAttach', [options]),
151
+ debugDetach: () => call(id, 'debugDetach'),
152
+ shutdown: () => call(id, 'shutdown'),
153
+ }, 'async');
154
+ const definition = (make) => {
155
+ const id = make();
156
+ let name;
157
+ try {
158
+ name = sync(id, 'name');
159
+ }
160
+ finally {
161
+ release(id);
162
+ }
163
+ const value = { name };
164
+ toolFactories.set(value, make);
165
+ return value;
166
+ };
167
+ // No SDK event queue: this runs on the JS invocation stack. The SAME shared
168
+ // sink checks entry immediately before the app call and completes after finish.
169
+ function receive(packet) {
170
+ switch (packet.type) {
171
+ case 'event': {
172
+ const delivery = { tryEnter: () => sync(packet.delivery, 'tryEnter'), complete: json => { sync(packet.delivery, 'complete', [json]); } };
173
+ const sink = sinks.get(packet.sink);
174
+ if (sink)
175
+ sink(packet.id, packet.eventJson, delivery);
176
+ else
177
+ delivery.complete('{"outcome":"unavailable"}');
178
+ return;
179
+ }
180
+ case 'execute': {
181
+ const execute = executors.get(packet.execute);
182
+ if (!execute) {
183
+ sync(packet.attachments, 'release');
184
+ wire.reply(packet.call, '{"type":"unavailable"}');
185
+ return;
186
+ }
187
+ // CoreExecute already yields the exact completion JSON. No re-mapping,
188
+ // JSON wrapping, error codes or result inference at this boundary.
189
+ void execute(packet.callJson, packet.contextJson, token(packet.cancel), attachmentReader(packet.attachments)).then(json => wire.reply(packet.call, json), () => wire.reply(packet.call, '{"type":"unavailable"}'));
190
+ return;
191
+ }
192
+ case 'cancel':
193
+ for (const listener of tokens.get(packet.token)?.deref()?.listeners ?? [])
194
+ listener();
195
+ return;
196
+ case 'image': {
197
+ const host = hosts.get(packet.host);
198
+ if (!host) {
199
+ wire.reply(packet.call, '{"unavailable":true}');
200
+ return;
201
+ }
202
+ void host.imageOperation(packet.operation, new Uint8Array(packet.bytes), packet.options, token(packet.cancel)).then(value => wire.reply(packet.call, JSON.stringify({ value: { ...value, ...(value.bytes ? { bytes: Array.from(value.bytes) } : {}) } })), error => wire.reply(packet.call, JSON.stringify({ error: thrownFacts(error) })));
203
+ return;
204
+ }
205
+ case 'blob': {
206
+ const host = hosts.get(packet.host);
207
+ if (!host?.blobGet || !host.blobPut || !host.blobDelete || !host.blobList) {
208
+ wire.reply(packet.call, '{"unavailable":true}');
209
+ return;
210
+ }
211
+ const { blobGet, blobPut, blobDelete, blobList, blobPurgeStaging } = host;
212
+ const { operation, key, cursor, bytes: rawBytes } = packet;
213
+ async function blob() {
214
+ switch (operation) {
215
+ case 'get': {
216
+ const bytes = await blobGet(key);
217
+ return { bytes: bytes === null ? null : Array.from(bytes) };
218
+ }
219
+ case 'put': {
220
+ const bytes = rawBytes;
221
+ if (!bytes?.every(byte => Number.isInteger(byte) && byte >= 0 && byte <= 255))
222
+ throw Error('Invalid blob bytes');
223
+ await blobPut(key, new Uint8Array(bytes));
224
+ return {};
225
+ }
226
+ case 'delete':
227
+ await blobDelete(key);
228
+ return {};
229
+ case 'list': {
230
+ const page = await blobList(key, cursor ?? undefined);
231
+ if (!Array.isArray(page.entries) || page.entries.some(({ key, size }) => typeof key !== 'string' || !Number.isSafeInteger(size) || size < 0) ||
232
+ (page.nextCursor !== undefined && typeof page.nextCursor !== 'string'))
233
+ throw Error('Invalid blob page');
234
+ return page;
235
+ }
236
+ case 'purgeStaging':
237
+ await blobPurgeStaging?.(key);
238
+ return {};
239
+ }
240
+ }
241
+ void blob().then(value => wire.reply(packet.call, JSON.stringify({ value })), error => wire.reply(packet.call, JSON.stringify({ error: { detail: thrownFacts(error).message ?? '' } })));
242
+ return;
243
+ }
244
+ case 'storage': {
245
+ const storage = storages.get(packet.storage);
246
+ if (!storage) {
247
+ wire.reply(packet.call, '{"unavailable":true}');
248
+ return;
249
+ }
250
+ const secrets = { readSecret: 'read', writeSecret: 'write', removeSecret: 'remove' };
251
+ const owner = packet.method in secrets ? storage.secrets : storage;
252
+ const key = packet.method in secrets ? secrets[packet.method] : packet.method;
253
+ const method = owner[key];
254
+ void Promise.resolve().then(() => {
255
+ if (packet.method === 'readVersioned') {
256
+ const r = captureReadVersioned(packet.args[0]);
257
+ return storage.readVersioned(r.key).then(r.decode);
258
+ }
259
+ if (packet.method === 'writeIf') {
260
+ const r = captureWriteIf(...packet.args.slice(0, 3));
261
+ return storage.writeIf(r.key, r.value, r.expect).then(r.decode);
262
+ }
263
+ return method.apply(owner, packet.args);
264
+ }).then(value => wire.reply(packet.call, JSON.stringify({ value: value ?? null })),
265
+ // Storage carries detail only. Core assigns storage_error; codes and categories never cross.
266
+ error => wire.reply(packet.call, JSON.stringify({ error: { detail: thrownFacts(error).message ?? '' } })));
267
+ return;
268
+ }
269
+ case 'retired':
270
+ for (const id of packet.hosts)
271
+ hosts.delete(id);
272
+ for (const id of packet.storages)
273
+ storages.delete(id);
274
+ for (const id of packet.sinks)
275
+ sinks.delete(id);
276
+ for (const id of packet.executors)
277
+ executors.delete(id);
278
+ for (const id of packet.tokens)
279
+ tokens.delete(id);
280
+ }
281
+ }
282
+ wire.listen(receive);
283
+ return {
284
+ decisions: { decide: (agent, input, options, cancel) => agent.decide(input, options, cancel) },
285
+ newCancel: () => owned(token(sync('', 'newCancel')), 'token', error => error),
286
+ open: async (json, tools, storage, host, recovery) => {
287
+ const temporary = [];
288
+ try {
289
+ return owned(croche(await call('', 'open', [json, registrations(tools, temporary), storageId(storage), hostId(host), recovery, host.imageSupport() ?? null, ...(host.blobGet ? [true] : [])])), 'croche', error => error);
290
+ }
291
+ finally {
292
+ for (const id of temporary)
293
+ release(id);
294
+ }
295
+ },
296
+ wakeTimes: (json, query, storage, host) => call('', 'wakeTimes', [json, query, storageId(storage), hostId(host), host.imageSupport() ?? null, ...(host.blobGet ? [true] : [])]),
297
+ registerBackground: (json, sink, storage, platformStorage, host) => {
298
+ const markerStorage = platformStorage ?? (storage === defaultStorage ? undefined : defaultStorage);
299
+ sync('', 'registerBackground', [json, sink && sinkId(sink), storageId(storage), hostId(host), markerStorage && storageId(markerStorage),
300
+ ...(host.blobGet ? [host.imageSupport() ?? null, true] : [])]);
301
+ },
302
+ defineTool: (manifest, execute) => definition(() => {
303
+ const id = name('execute');
304
+ executors.set(id, execute);
305
+ try {
306
+ return sync('', 'defineTool', [manifest, id]);
307
+ }
308
+ catch (error) {
309
+ executors.delete(id);
310
+ throw error;
311
+ }
312
+ }),
313
+ webSearch: () => definition(() => sync('', 'webSearch')),
314
+ image: () => definition(() => sync('', 'image')),
315
+ };
316
+ }
@@ -0,0 +1,55 @@
1
+ import type { CoreAttachmentInput } from '../../runtime/src/core/port';
2
+ export interface NativeCoreWire {
3
+ call(handle: string, method: string, argsJson: string, images?: readonly CoreAttachmentInput[]): Promise<string>;
4
+ callSync(handle: string, method: string, argsJson: string): string;
5
+ reply(call: string, completionJson: string): void;
6
+ listen(receive: (packet: NativeCorePacket) => void): () => void;
7
+ }
8
+ export type NativeCorePacket = {
9
+ type: 'event';
10
+ sink: string;
11
+ id: string;
12
+ eventJson: string;
13
+ delivery: string;
14
+ } | {
15
+ type: 'execute';
16
+ execute: string;
17
+ call: string;
18
+ callJson: string;
19
+ contextJson: string;
20
+ cancel: string;
21
+ attachments: string;
22
+ } | {
23
+ type: 'cancel';
24
+ token: string;
25
+ } | {
26
+ type: 'image';
27
+ host: string;
28
+ call: string;
29
+ operation: string;
30
+ bytes: number[];
31
+ options: Record<string, unknown>;
32
+ cancel: string;
33
+ } | {
34
+ type: 'blob';
35
+ host: string;
36
+ call: string;
37
+ operation: 'put' | 'get' | 'delete' | 'list' | 'purgeStaging';
38
+ key: string;
39
+ cursor?: string | null;
40
+ bytes?: number[] | null;
41
+ } | {
42
+ type: 'storage';
43
+ storage: string;
44
+ call: string;
45
+ method: StorageMethod;
46
+ args: unknown[];
47
+ } | {
48
+ type: 'retired';
49
+ hosts: string[];
50
+ storages: string[];
51
+ sinks: string[];
52
+ executors: string[];
53
+ tokens: string[];
54
+ };
55
+ export type StorageMethod = 'listState' | 'commit' | 'readVersioned' | 'writeIf' | 'read' | 'write' | 'remove' | 'purgeInstance' | 'list' | 'lock' | 'unlock' | 'readSecret' | 'writeSecret' | 'removeSecret';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { CoreHttpRequest, CoreBodySink, CoreCancel } from '../../runtime/src/core/port.js';
2
+ import type { NativeCoreWire } from './core-wire.js';
3
+ export declare const nativeWire: NativeCoreWire;
4
+ export declare function unpack<T>(json: string): T;
5
+ export declare const nativeCall: <T>(method: string, args?: unknown[]) => Promise<T>;
6
+ export declare const nativeSync: <T>(method: string, args?: unknown[]) => T;
7
+ export declare function nativeHTTP(request: CoreHttpRequest, sink: CoreBodySink, cancel: CoreCancel): Promise<void>;
8
+ export declare const nativeStorageCall: <T>(method: string, args?: unknown[]) => Promise<T>;
@@ -0,0 +1,53 @@
1
+ // The native module forwards only the private Core wire; no legacy runtime API.
2
+ import { NativeEventEmitter } from 'react-native';
3
+ import Native from './NativeCrocheRuntime.js';
4
+ const emitter = new NativeEventEmitter(Native);
5
+ export const nativeWire = {
6
+ call: (handle, method, args, images) => Native.coreCall(handle, method, args, (images ?? []).map(image => ({ element: image.element, bytes: Array.from(image.bytes) }))),
7
+ callSync: (handle, method, args) => Native.coreCallSync(handle, method, args),
8
+ reply: (call, completion) => Native.coreReply(call, completion),
9
+ listen(receive) { const sub = emitter.addListener('CrocheCoreEvent', (json) => receive(JSON.parse(json))); return () => sub.remove(); },
10
+ };
11
+ // PAL replies carry data or the exact native fact/error envelope. Storage failures
12
+ // remain plain Errors: Core assigns storage_error; no SDK mapping or fallback.
13
+ export function unpack(json) {
14
+ const result = JSON.parse(json);
15
+ if ('error' in result) {
16
+ const error = new Error(result.error.detail);
17
+ if (result.error.code !== undefined)
18
+ Object.assign(error, { code: result.error.code });
19
+ throw error;
20
+ }
21
+ return result.value;
22
+ }
23
+ export const nativeCall = async (method, args = []) => unpack(await Native.platformCall(method, JSON.stringify(args)));
24
+ export const nativeSync = (method, args = []) => unpack(Native.platformCallSync(method, JSON.stringify(args)));
25
+ let nextHttp = 0;
26
+ export async function nativeHTTP(request, sink, cancel) {
27
+ const id = `http:${++nextHttp}`;
28
+ let active = true;
29
+ const listener = emitter.addListener('CrochePalEvent', (json) => {
30
+ const packet = JSON.parse(json);
31
+ if (packet.id !== id)
32
+ return;
33
+ if (packet.type === 'head')
34
+ sink.head(packet.status, packet.headers);
35
+ else if (packet.type === 'chunk' && !sink.chunk(new Uint8Array(packet.bytes)))
36
+ nativeSync('cancelHttp', [id]);
37
+ });
38
+ cancel.onCancel(() => { if (active)
39
+ nativeSync('cancelHttp', [id]); });
40
+ try {
41
+ await nativeCall('http', [id, request]);
42
+ }
43
+ finally {
44
+ active = false;
45
+ listener.remove();
46
+ }
47
+ }
48
+ export const nativeStorageCall = async (method, args = []) => {
49
+ const result = JSON.parse(await Native.platformCall(method, JSON.stringify(args)));
50
+ if ('error' in result)
51
+ throw new Error(result.error.detail);
52
+ return result.value;
53
+ };
@@ -0,0 +1,16 @@
1
+ {
2
+ "entry": "runtime/src/rn-entry.js",
3
+ "adapter": "packages/react-native/src/shared-adapter.ts",
4
+ "sharedSources": {
5
+ "index.native.ts": "fd49a25a980261999953af3751957beaab10ba50fb0ff4e2337a48de28223190",
6
+ "croche.ts": "82fecd1846a74db9670cc99b9531c53624a92250798feb85a6deeb2ef1fa21d6",
7
+ "agent.ts": "841d7186955bea267deb5036de573a3fe5dbf5f1feddc1318084da790c744462",
8
+ "tools.ts": "0a986ed325134af30d32bf2e7f88808e8e8ae10e7ab56945346f01d7b3a2a85d",
9
+ "app-api.ts": "c6b331da01222f449513e97f9feeb7464b14b53ba73be769fc2d8c510878741d",
10
+ "json.ts": "b46f716b14c7db7945e6e9291736f1594e7bd141dcb48dd0823bc34e0500255c",
11
+ "errors.ts": "4700c124cddcd35572654e994e52e1aad77bc41bf08cad6956a422cb48007a51",
12
+ "cancel.ts": "56d985e387b6f7364546779d89b55e3b8388473c31ed6ecc37d052624896a169",
13
+ "core/port.ts": "90a7155ba0cb2ff9005e6f89c130f37c590d9d5238753a1f14cc306c996f5d03"
14
+ },
15
+ "wasm": false
16
+ }
@@ -0,0 +1,8 @@
1
+ import type { Adapter, BlobStore, ImageAdapter, StateStore } from './app-api.js';
2
+ type SelectedAdapters = {
3
+ blob?: BlobStore;
4
+ image?: ImageAdapter;
5
+ storage?: StateStore;
6
+ };
7
+ export declare function adaptersFor(adapters: readonly Adapter[] | undefined): SelectedAdapters;
8
+ export {};
@@ -0,0 +1,29 @@
1
+ import { CrocheError } from './errors.js';
2
+ export function adaptersFor(adapters) {
3
+ const selected = {};
4
+ if (adapters === undefined)
5
+ return selected;
6
+ if (!Array.isArray(adapters))
7
+ throw new CrocheError('invalid_configuration', 'adapters must be an array.', 'setup');
8
+ for (const adapter of adapters) {
9
+ const kind = adapter?.kind;
10
+ if (kind !== 'blob' && kind !== 'image' && kind !== 'state')
11
+ throw new CrocheError('invalid_configuration', 'Unknown adapter kind.', 'setup');
12
+ const slot = kind === 'state' ? 'storage' : kind;
13
+ if (selected[slot] !== undefined)
14
+ throw new CrocheError('invalid_configuration', `Duplicate adapter kind: ${kind}.`, 'setup');
15
+ if (kind === 'image')
16
+ selected.image = adapter;
17
+ else if (kind === 'state')
18
+ selected.storage = adapter;
19
+ else {
20
+ const blobs = adapter;
21
+ const missing = ['put', 'get', 'delete', 'list'].filter(name => typeof blobs[name] !== 'function');
22
+ if (missing.length) {
23
+ throw new CrocheError('invalid_configuration', `BlobStore is missing required methods: ${missing.join(', ')}.`, 'setup');
24
+ }
25
+ selected.blob = blobs;
26
+ }
27
+ }
28
+ return selected;
29
+ }
@@ -0,0 +1,91 @@
1
+ import type { DecideInput, DecisionResult, MemoryItem, RequestResult, SendInput, SendOptions, SendReceipt, SubscribeOptions, Subscription, ToolScope, WikiScope, ListOptions, Page } from './app-api.js';
2
+ import type { CoreAgent, CoreModule } from './core/port.js';
3
+ /** Core's handle for an Agent (the debugger takes it); undefined for anything else. */
4
+ export declare function coreAgent(agent: unknown): CoreAgent | undefined;
5
+ /**
6
+ * The one way to make an Agent: `croche.agent()` wraps the handle Core returned. Reflect.construct
7
+ * keeps the constructor private to TypeScript without an ES2022 static initialization block, which the React
8
+ * Native 0.87 Babel preset cannot parse in an app's Metro bundle (0.6.1 P12).
9
+ */
10
+ export declare const wrapAgent: (module: CoreModule, core: CoreAgent) => Agent;
11
+ /** Available through the web/Node entry; RN omits it until the native bridge is proven. */
12
+ export interface Agent {
13
+ /** Classify app data for a workflow, such as routing a support ticket without starting a chat. */
14
+ decide(input: DecideInput, options?: {
15
+ signal?: AbortSignal;
16
+ }): Promise<DecisionResult>;
17
+ }
18
+ /** One agent conversation with requests, transcript subscription and instance controls. */
19
+ export declare class Agent {
20
+ #private;
21
+ private constructor();
22
+ /** Load an attachment when someone opens it from this conversation. */
23
+ attachment(id: string): Promise<{
24
+ mediaType: string;
25
+ data: string;
26
+ }>;
27
+ /** Let a user remove a file they no longer want kept with this conversation. */
28
+ deleteAttachment(id: string): Promise<void>;
29
+ /** Show the files a user can revisit from this conversation. */
30
+ listAttachments(options?: ListOptions): Promise<Page<import('./app-api.js').Attachment>>;
31
+ /** Bring a file from another conversation into this one before sharing it here. */
32
+ copyAttachment(source: {
33
+ agent: string;
34
+ instance?: string;
35
+ id: string;
36
+ }): Promise<import('./app-api.js').Attachment>;
37
+ /** Let the app drop its hold on a file when the user removes it from a draft. */
38
+ releaseAttachment(id: string): Promise<void>;
39
+ /** Let an app associate a reply with the configured agent that produced it. */
40
+ get id(): string;
41
+ /** Let an app distinguish two conversations that use the same agent definition. */
42
+ get instance(): string | null;
43
+ /**
44
+ * Accept input from chat without making the UI wait for the reply.
45
+ *
46
+ * Resolves when Core accepts the input. Aborting before acceptance prevents it from being queued.
47
+ */
48
+ send(input: SendInput, options?: SendOptions): Promise<SendReceipt>;
49
+ /**
50
+ * Wait for an outcome when an app workflow needs to decide what happens next.
51
+ *
52
+ * Resolves when the input is final; with wait: 'idle', when the agent is idle too.
53
+ * After acceptance, aborting the signal rejects the wait with `aborted` and the input continues.
54
+ */
55
+ request(input: SendInput, options?: SendOptions & {
56
+ wait?: 'idle';
57
+ }): Promise<RequestResult>;
58
+ /**
59
+ * Keep a chat screen in step with the agent as messages and tool activity arrive.
60
+ *
61
+ * Events arrive in Core's order; an unknown type passes through unchanged.
62
+ */
63
+ subscribe(options: SubscribeOptions): Subscription;
64
+ /** Let the user stop a reply or withdraw input they no longer want processed. */
65
+ cancel(id?: string): Promise<void>;
66
+ /** Let a user clear the conversation they see while keeping the agent available. Clears
67
+ * the whole conversation; it takes no options (partial clear was removed in 0.7). An
68
+ * untyped caller's argument still reaches Core, which refuses it rather than clear all. */
69
+ clearHistory(): Promise<void>;
70
+ /** Access controls for this conversation's memory. */
71
+ readonly memory: {
72
+ /** Show the user what the agent remembers so they can review it. */
73
+ list: (options?: ListOptions) => Promise<Page<MemoryItem>>;
74
+ /** Let the user remove one remembered fact without clearing the rest. */
75
+ delete: (id: string) => Promise<void>;
76
+ /** Let the user start over with a clean memory while keeping their conversation. */
77
+ clear: () => Promise<void>;
78
+ /** Let the user choose whether the agent uses memory in this conversation. */
79
+ enabled: (on: boolean) => Promise<void>;
80
+ };
81
+ /** Limit an agent to the actions appropriate for the user’s current workflow. */
82
+ setTools(scope: ToolScope | 'all'): Promise<void>;
83
+ /** Restore the usual actions after the user leaves a restricted workflow. */
84
+ resetTools(): Promise<void>;
85
+ /** Give an agent help material relevant to the screen or workspace the user is in. */
86
+ setWiki(scope: WikiScope | 'all'): Promise<void>;
87
+ /** Restore the usual help material after the user leaves a specialized workspace. */
88
+ resetWiki(): Promise<void>;
89
+ /** Release an agent when the app leaves its conversation and no longer needs the handle. */
90
+ close(): Promise<void>;
91
+ }