@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,127 @@
1
+ package dev.croche
2
+
3
+ import com.google.gson.*
4
+
5
+ /**
6
+ * Debugger attachment and the capabilities Core reports. New capability values can appear.
7
+ *
8
+ * @property capabilities Capabilities that Core reports for the attached debugger.
9
+ * @property debuggerId Identifier returned for the attached debugger.
10
+ */
11
+ data class AttachedDebugger(val debuggerId: String, val capabilities: List<String>)
12
+ /**
13
+ * A scheduled wake for a user.
14
+ *
15
+ * @property at Scheduled wake time in epoch milliseconds.
16
+ * @property user User ID associated with the wake, if present.
17
+ */
18
+ data class Wake(val user: String?, val at: Long)
19
+ /**
20
+ * Page of scheduled wakes returned by the host query.
21
+ *
22
+ * @property next Continue the query using this epoch-millisecond value as the after bound, when present.
23
+ * @property wakes Scheduled wakes included in this result.
24
+ */
25
+ data class WakeTimes(val wakes: List<Wake>, val next: Long?)
26
+ /**
27
+ * One owner whose due background work could not be completed in this run.
28
+ *
29
+ * @property agent Agent ID for the deferred work.
30
+ * @property code Machine-readable reason work was deferred.
31
+ * @property instance Named instance for the deferred work, if any.
32
+ * @property message Human-readable deferral description.
33
+ * @property user User ID for the deferred work, if present.
34
+ */
35
+ data class DeliveryDeferred(val user: String?, val agent: String, val instance: String?, val code: String, val message: String)
36
+ /**
37
+ * Result of a background delivery run.
38
+ *
39
+ * @property deferred Agents and instances whose due work was deferred, with reasons.
40
+ * @property delivered Number of usage reports the runtime delivered in this run.
41
+ * @property ran Whether Core reports that the delivery pass ran.
42
+ */
43
+ data class DueDelivery(val ran: Boolean, val delivered: Int, val deferred: List<DeliveryDeferred>)
44
+ /**
45
+ * One saved memory item returned by the memory list.
46
+ *
47
+ * @property fields All fields from Core's JSON item, including fields the Kotlin wrapper does not project individually.
48
+ * @property id Item ID used to select the fact for deletion.
49
+ * @property text Saved text for this item.
50
+ */
51
+ data class MemoryItem(val id: String, val text: String, val fields: Map<String, JsonElement>)
52
+ /**
53
+ * The options of every paged public list: `listAttachments`, `memory.list` and `wiki.list`.
54
+ * `limit` is a positive integer; a page holds at most 128 items, which is also the default.
55
+ * `cursor` is the cursor of the previous page of the same list.
56
+ *
57
+ * @property cursor Cursor returned by the previous page of the same list.
58
+ * @property limit Requested number of items, capped at 128. Null uses 128.
59
+ */
60
+ data class ListOptions(val limit: Int? = null, val cursor: String? = null) {
61
+ internal fun json(): String = JsonObject().also { fields ->
62
+ limit?.let { fields.addProperty("limit", it) }
63
+ cursor?.let { fields.addProperty("cursor", it) }
64
+ }.toString()
65
+ }
66
+ /**
67
+ * One page of a public list, in the list's stable order. `cursor` is present only when more
68
+ * items follow: pass it back to the same list to continue strictly past this page.
69
+ *
70
+ * @property cursor Opaque cursor to pass back to this list when another page is available.
71
+ * @property items Items returned in this page.
72
+ */
73
+ data class Page<T>(val items: List<T>, val cursor: String? = null)
74
+
75
+ /**
76
+ * How Croche Cloud verified this installation (`croche.verification()`, founder 2026-11-22 02:31:47Z). Verification is
77
+ * not access: a withheld key leaves it unchanged. [status]: attested, server, development, unverified, or unknown (not
78
+ * registered yet, or Cloud did not say). [lastAttestation]: the device-side code of the last attestor attempt without a
79
+ * usable proof; null does not mean Cloud accepted a proof. Strings match TS/RN and Swift; the set is open.
80
+ *
81
+ * @property lastAttestation Device-side code from the last attestor attempt that did not produce usable proof, if present.
82
+ * @property status Open-ended installation verification status reported by Core.
83
+ */
84
+ data class Verification(val status: String, val lastAttestation: String?)
85
+
86
+ /** Known reply fields are projected; unknown fields never prevent a read. */
87
+ internal object PublicResults {
88
+ fun attachment(json: String): AppStreamContract.Attachment = Gson().fromJson(json, AppStreamContract.Attachment::class.java)
89
+ /** Core's `{items, cursor?}` reply, each item read by `item`. */
90
+ private fun <T> page(json: String, item: (JsonElement) -> T): Page<T> = objectValue(json).let { reply ->
91
+ Page(reply.getAsJsonArray("items").map(item), reply.get("cursor")?.takeUnless { it.isJsonNull }?.asString)
92
+ }
93
+ fun attachments(json: String): Page<AppStreamContract.Attachment> = page(json) { attachment(it.toString()) }
94
+ fun attachmentData(json: String): AttachmentData = Gson().fromJson(json, AttachmentData::class.java)
95
+ private fun objectValue(json: String) = JsonParser.parseString(json).asJsonObject
96
+ private fun JsonObject.optionalLong(key: String) = get(key)?.takeUnless { it.isJsonNull }?.asLong
97
+ fun verification(json: String): Verification = objectValue(json).let {
98
+ Verification(it.get("status").asString, it.get("lastAttestation")?.takeUnless { v -> v.isJsonNull }?.asString)
99
+ }
100
+ fun wakes(json: String): WakeTimes = objectValue(json).let { value ->
101
+ WakeTimes(value.getAsJsonArray("wakes").map { entry -> entry.asJsonObject.let {
102
+ Wake(it.get("user")?.takeUnless { user -> user.isJsonNull }?.asString, it.get("at").asLong)
103
+ } }, value.optionalLong("next"))
104
+ }
105
+ fun delivery(json: String): DueDelivery = objectValue(json).let { value ->
106
+ DueDelivery(value.get("ran").asBoolean, value.get("delivered").asInt,
107
+ value.getAsJsonArray("deferred").map { entry -> entry.asJsonObject.let {
108
+ DeliveryDeferred(it.get("user")?.takeUnless { user -> user.isJsonNull }?.asString, it.get("agent").asString,
109
+ it.get("instance")?.takeUnless { v -> v.isJsonNull }?.asString,
110
+ it.get("code").asString, it.get("message").asString)
111
+ } })
112
+ }
113
+ fun debug(json: String): AttachedDebugger = objectValue(json).let {
114
+ AttachedDebugger(it.get("debuggerId").asString, it.getAsJsonArray("capabilities").map { v -> v.asString })
115
+ }
116
+ fun memories(json: String): Page<MemoryItem> = page(json) { entry ->
117
+ val value = entry.asJsonObject
118
+ MemoryItem(value.get("id").asString, value.get("text").asString,
119
+ value.entrySet().associate { it.key to it.value.deepCopy() })
120
+ }
121
+ fun wiki(json: String): Page<WikiDoc> = page(json) { entry ->
122
+ val value = entry.asJsonObject
123
+ val path = value.get("path").asString; val description = value.get("description").asString
124
+ if (value.has("markdown")) WikiDoc.Markdown(path, description, value.get("markdown").asString)
125
+ else WikiDoc.File(path, description, value.get("file").asString)
126
+ }
127
+ }
@@ -0,0 +1,73 @@
1
+ package dev.croche
2
+
3
+ /** Reader values are open. Ignore values this app does not understand; never invent a default.
4
+ * The exact Core string is retained, including case. ErrorCategory is the sole closed reader set.
5
+ */
6
+ internal interface ReaderString { val value: String }
7
+
8
+ internal data class InputKind(override val value: String) : ReaderString {
9
+ companion object {
10
+ val USER = InputKind("user")
11
+ val APP_EVENT = InputKind("app_event")
12
+ val APP_STATE = InputKind("app_state")
13
+ val UNKNOWN = InputKind("unknown")
14
+ }
15
+ }
16
+
17
+ internal data class InputStatus(override val value: String) : ReaderString {
18
+ companion object {
19
+ val QUEUED = InputStatus("queued")
20
+ val SEEN = InputStatus("seen")
21
+ val ANSWERED = InputStatus("answered")
22
+ val NO_REPLY = InputStatus("no_reply")
23
+ val FAILED = InputStatus("failed")
24
+ val CANCELLED = InputStatus("cancelled")
25
+ val SETTLED_BEFORE_UPGRADE = InputStatus("settled_before_upgrade")
26
+ val UNKNOWN = InputStatus("unknown")
27
+ }
28
+ }
29
+
30
+ internal data class MessageStatus(override val value: String) : ReaderString {
31
+ companion object {
32
+ val COMPLETED = MessageStatus("completed")
33
+ val FAILED = MessageStatus("failed")
34
+ val CANCELLED = MessageStatus("cancelled")
35
+ val INTERRUPTED = MessageStatus("interrupted")
36
+ val UNKNOWN = MessageStatus("unknown")
37
+ }
38
+ }
39
+
40
+ internal data class AgentStatus(override val value: String) : ReaderString {
41
+ companion object {
42
+ val RUNNING = AgentStatus("running")
43
+ val WAITING = AgentStatus("waiting")
44
+ val IDLE = AgentStatus("idle")
45
+ val UNKNOWN = AgentStatus("unknown")
46
+ }
47
+ }
48
+
49
+ internal data class AgentActivity(override val value: String) : ReaderString {
50
+ companion object {
51
+ val MODEL = AgentActivity("model")
52
+ val SUMMARY = AgentActivity("summary")
53
+ val TOOL = AgentActivity("tool")
54
+ val UNKNOWN = AgentActivity("unknown")
55
+ }
56
+ }
57
+
58
+ internal data class CostStatus(override val value: String) : ReaderString {
59
+ companion object {
60
+ val REPORTED = CostStatus("reported")
61
+ val ESTIMATED = CostStatus("estimated")
62
+ val NONE = CostStatus("none")
63
+ val UNKNOWN = CostStatus("unknown")
64
+ }
65
+ }
66
+
67
+ internal data class GapReason(override val value: String) : ReaderString {
68
+ companion object {
69
+ val CLEARED = GapReason("cleared")
70
+ val LIMIT = GapReason("limit")
71
+ val UNKNOWN = GapReason("unknown")
72
+ }
73
+ }
@@ -0,0 +1,73 @@
1
+ package dev.croche
2
+
3
+ import com.google.gson.*
4
+ import dev.croche.ffi.CoreCrocheInterface
5
+ import dev.croche.s7.publicCall
6
+
7
+ /** The same envelope as TS; all outcomes and costs are supplied by Core. */
8
+ sealed interface RunToolResult {
9
+ /**
10
+ * A successful app tool result.
11
+ *
12
+ * @property attachments Descriptors for files produced by the tool.
13
+ * @property id ID used to correlate the result to the app call.
14
+ * @property output JSON value returned by the tool.
15
+ * @property costStatus Status of the cost observation for this run.
16
+ * @property cost Recorded cost in credits, or null when unavailable.
17
+ */
18
+ data class Ok(val id: String, val output: JsonElement, val attachments: List<AppStreamContract.Attachment>,
19
+ val cost: Double?, val costStatus: String) : RunToolResult
20
+ /**
21
+ * The tool ran to a failed result.
22
+ *
23
+ * @property category Group used to decide how the app should handle the error.
24
+ * @property code Machine-readable failure code.
25
+ * @property id ID used to correlate the result to the app call.
26
+ * @property message Human-readable failure description.
27
+ * @property costStatus Status of the cost observation for this run.
28
+ * @property cost Recorded cost in credits, or null when unavailable.
29
+ */
30
+ data class Failed(val id: String, val code: String, val category: ErrorCategory, val message: String,
31
+ val cost: Double?, val costStatus: String) : RunToolResult
32
+ /**
33
+ * An operation for which Core could not recover a result.
34
+ *
35
+ * @property category Group used to decide how the app should handle the failure.
36
+ * @property code Machine-readable reason the result could not be recovered.
37
+ * @property id ID used to correlate the result to the app call.
38
+ * @property message Human-readable reason the result could not be recovered.
39
+ */
40
+ data class Lost(val id: String, val code: String, val category: ErrorCategory, val message: String) : RunToolResult
41
+ /**
42
+ * A tool result whose status this SDK does not recognize.
43
+ *
44
+ * @property fields Original JSON result, preserved for inspection.
45
+ * @property status Original status string.
46
+ */
47
+ data class Unknown(val status: String, val fields: JsonElement) : RunToolResult
48
+ }
49
+
50
+ internal object RunToolJson {
51
+ private val gson = Gson()
52
+ private fun JsonObject.cost(): Double? = get("cost").takeUnless { it.isJsonNull }?.asDouble
53
+ private fun JsonObject.category() = ErrorCategory.entries.single { it.name.equals(get("category").asString, ignoreCase = true) }
54
+ fun result(json: String): RunToolResult {
55
+ val value = JsonParser.parseString(json).asJsonObject
56
+ return when (val status = value.get("status").asString) {
57
+ "ok" -> RunToolResult.Ok(value.get("id").asString, value.get("output").deepCopy(),
58
+ value.getAsJsonArray("attachments").map { gson.fromJson(it, AppStreamContract.Attachment::class.java) },
59
+ value.cost(), value.get("costStatus").asString)
60
+ "failed" -> RunToolResult.Failed(value.get("id").asString, value.get("code").asString,
61
+ value.category(), value.get("message").asString, value.cost(), value.get("costStatus").asString)
62
+ "lost" -> RunToolResult.Lost(value.get("id").asString, value.get("code").asString,
63
+ value.category(), value.get("message").asString)
64
+ else -> RunToolResult.Unknown(status, value.deepCopy())
65
+ }
66
+ }
67
+ }
68
+
69
+ internal suspend fun runTool(core: CoreCrocheInterface, name: String, args: JsonObject, id: String): RunToolResult {
70
+ val arguments = args.toString()
71
+ val options = JsonObject().apply { addProperty("id", id) }.toString()
72
+ return publicCall { cancel -> RunToolJson.result(core.runTool(name, arguments, options, cancel)) }
73
+ }
@@ -3,25 +3,27 @@ package dev.croche
3
3
  import com.google.gson.JsonArray
4
4
  import com.google.gson.JsonObject
5
5
 
6
- /** One encoding boundary for send and request; Core owns normalization and stack limits. */
7
- internal fun SendInput.encoded(options: SendOptions = SendOptions()): JsonObject {
8
- val out = JsonObject().apply { addProperty("id", id) }
9
- if (inputs.isNotEmpty()) {
10
- if (text.isNotEmpty() || images.isNotEmpty() || kind != InputKind.USER) {
11
- throw CrocheException("invalid_input", "Send either text and kind (one input) or inputs (a stack), not both")
12
- }
13
- out.add("inputs", JsonArray().apply {
14
- inputs.forEach { part -> add(JsonObject().apply {
15
- addProperty("kind", part.kind.name.lowercase())
16
- part.text?.let { addProperty("text", it) }
17
- if (part.images.isNotEmpty()) add("images", JsonArray().apply { part.images.forEach { add(it.json.deepCopy()) } })
18
- }) }
19
- })
20
- } else {
21
- out.addProperty("text", text)
22
- out.addProperty("kind", kind.name.lowercase())
23
- if (images.isNotEmpty()) out.add("images", JsonArray().apply { images.forEach { add(it.json.deepCopy()) } })
24
- }
25
- context?.let { out.add("context", it.deepCopy()) }
26
- return CrocheImages.prepareInput(out, options.imageResolution)
6
+ /** One encoding boundary; Core owns kinds, defaults, limits, source support and admission. */
7
+ internal fun SendInput.encoded(options: SendOptions = SendOptions()): JsonObject = JsonObject().apply {
8
+ id?.let { addProperty("id", it) }
9
+ add("input", JsonArray().apply {
10
+ input.forEach { element -> add(JsonObject().apply {
11
+ when (element) {
12
+ is TextInput -> {
13
+ addProperty("type", "text"); addProperty("text", element.text)
14
+ element.kind?.let { addProperty("kind", it.rawValue) }
15
+ }
16
+ is ImageInput -> {
17
+ // Bytes never enter JSON: only the image type/alt, bytes in CoreAttachmentInput.
18
+ addProperty("type", "image")
19
+ if (element.uri != null) addProperty("uri", element.uri)
20
+ element.alt?.let { addProperty("alt", it) }
21
+ }
22
+ }
23
+ }) }
24
+ })
27
25
  }
26
+
27
+ /** Byte images by element index, for Core's reserved entry. */
28
+ internal fun SendInput.imageCaptures(): List<Pair<Int, ByteArray>> =
29
+ input.withIndex().mapNotNull { (index, element) -> (element as? ImageInput)?.image?.let { index to it } }
@@ -0,0 +1,90 @@
1
+ package dev.croche
2
+
3
+ /** Atomic state for an app. The condition and every write share one transaction. */
4
+ interface StateStore : Adapter {
5
+ /** Host adapter tag for state storage. */
6
+ override val kind: String get() = "state"
7
+ /** Read saved state so a user can continue where they left off. */
8
+ suspend fun get(key: String): StateValue?
9
+ /** Load just the relevant records so a long conversation still opens promptly. */
10
+ suspend fun list(prefix: String, options: StateListOptions = StateListOptions()): StatePage
11
+ /** Keep a saved reply and its related progress consistent if the app stops mid-write. */
12
+ suspend fun commit(ops: List<StateOp>, condition: StateCondition): StateCommitResult
13
+ }
14
+
15
+ /**
16
+ * Stored value together with the version used for a conditional commit.
17
+ *
18
+ * @property value String value returned for the key.
19
+ * @property version Opaque version for the observed value.
20
+ */
21
+ data class StateValue(val value: String, val version: String)
22
+
23
+ internal data class VersionedValue(val value: String?, val version: String?)
24
+ internal sealed interface WriteOutcome {
25
+ data class Written(val version: String?) : WriteOutcome
26
+ data class Conflict(val version: String?) : WriteOutcome
27
+ }
28
+
29
+
30
+ /** One put or delete in a conditional state batch. */
31
+ sealed interface StateOp {
32
+ /** Full key addressed by this operation. */
33
+ val key: String
34
+ /**
35
+ * Write a value at a key in the store.
36
+ *
37
+ * @property key Full key to write.
38
+ * @property value String value to save.
39
+ */
40
+ data class Put(override val key: String, val value: String) : StateOp
41
+ /**
42
+ * Remove a key from the store.
43
+ *
44
+ * @property key Full key to remove.
45
+ */
46
+ data class Delete(override val key: String) : StateOp
47
+ }
48
+ /**
49
+ * Version check that guards an atomic state commit.
50
+ *
51
+ * @property key Key checked before committing the batch.
52
+ * @property version Expected version, or null to require the key to be absent.
53
+ */
54
+ data class StateCondition(val key: String, val version: String?)
55
+ /** Outcome of comparing a state version and applying a write batch. */
56
+ sealed interface StateCommitResult {
57
+ /**
58
+ * The condition matched and the batch was applied.
59
+ *
60
+ * @property version Version of the condition key after the batch, or null if it is absent.
61
+ */
62
+ data class Committed(val version: String?) : StateCommitResult
63
+ /** The condition did not match. The batch made no writes. */
64
+ data object Conflict : StateCommitResult
65
+ }
66
+ /** Bounds and continuation for a StateStore prefix read. */
67
+ data class StateListOptions(
68
+ /** Inclusive lower bound on full keys within the prefix. */
69
+ val start: String? = null,
70
+ /** Use descending UTF-8 key order. The start bound is still a lower bound. */
71
+ val reverse: Boolean = false,
72
+ /** Positive page limit up to 128. Null uses the default of 128. */
73
+ val limit: UInt? = null,
74
+ /** Opaque continuation from a page for the same prefix, start and direction. */
75
+ val cursor: String? = null,
76
+ )
77
+ /**
78
+ * Key and value returned by a state range read.
79
+ *
80
+ * @property key Full stored key.
81
+ * @property value String value associated with this key.
82
+ */
83
+ data class StateEntry(val key: String, val value: String)
84
+ /**
85
+ * One bounded page of stored entries.
86
+ *
87
+ * @property entries Entries in the order requested for the range.
88
+ * @property nextCursor Opaque continuation if another page is available. A short page may still have a cursor.
89
+ */
90
+ data class StatePage(val entries: List<StateEntry>, val nextCursor: String? = null)
@@ -4,36 +4,98 @@ import com.google.gson.JsonElement
4
4
  import com.google.gson.JsonObject
5
5
  import java.time.Instant
6
6
 
7
- /** Subscription API preview; native binding is deliberately not installed in Phase 1. */
8
- data class StackedInput(val kind: InputKind = InputKind.USER, val text: String? = null,
9
- val images: List<InputImage> = emptyList())
10
- data class SendInput(val id: String, val text: String = "", val kind: InputKind = InputKind.USER,
11
- val images: List<InputImage> = emptyList(), val context: JsonElement? = null,
12
- val inputs: List<StackedInput> = emptyList())
13
- data class SendOptions(val responseFormat: JsonObject? = null, val imageResolution: ImageResolution? = null)
14
- data class Receipt(val id: String, val status: InputStatus, val seq: Long?)
7
+ /** Ordered request elements; normalization and admission belong to Core. */
8
+ sealed interface SendElement
9
+ /**
10
+ * Text supplied to the agent. Null [kind] means user input.
11
+ *
12
+ * @property kind Input source sent to Core. Null uses user input.
13
+ * @property text Text supplied to the agent.
14
+ */
15
+ data class TextInput(val text: String, val kind: AppStreamContract.InputKind? = null) : SendElement
16
+ /**
17
+ * One image element, supplied by URI or encoded bytes.
18
+ *
19
+ * @property alt Optional description supplied with the image.
20
+ */
21
+ class ImageInput private constructor(internal val uri: String?, internal val image: ByteArray?,
22
+ val alt: String?) : SendElement {
23
+ /** Create an image element from a URI and optional description. */
24
+ constructor(uri: String, alt: String? = null) : this(uri, null, alt)
25
+ /** Create an image element from a private copy of encoded bytes and an optional description. */
26
+ constructor(image: ByteArray, alt: String? = null) : this(null, image.copyOf(), alt)
27
+ internal fun owned(): ImageInput = uri?.let { ImageInput(it, alt) } ?: ImageInput(image!!, alt)
28
+ }
29
+ /**
30
+ * An ordered group of elements submitted together to the agent.
31
+ *
32
+ * @property id Optional app-supplied input identifier used to correlate stream events.
33
+ * @property input Text and image elements in input order.
34
+ */
35
+ data class SendInput(val id: String? = null, val input: List<SendElement>)
36
+ /**
37
+ * Response options that accompany an accepted send.
38
+ *
39
+ * @property responseFormat Optional format supplied to Core for structured output.
40
+ */
41
+ data class SendOptions(val responseFormat: JsonObject? = null)
42
+ internal data class Receipt(val requestId: String, val status: InputStatus, val seq: Long?)
15
43
  // OPEN(§18.24.D): No pending field until Atlas approves the consuming-unit contract.
16
- enum class RequestWait { IDLE }
17
- data class RequestResult(val id: String, val status: InputStatus, val messages: List<RuntimeEvent.MessageEnd>,
44
+ /** Extra condition the request waits for after input completion. */
45
+ enum class RequestWait {
46
+ /** Wait until the agent is idle as well as the input being terminal. */
47
+ IDLE
48
+ }
49
+ internal data class LegacyRequestResult(val id: String, val status: InputStatus, val messages: List<RuntimeEvent.MessageEnd>,
18
50
  val gap: Boolean, val legacy: Boolean)
51
+ /**
52
+ * Resume coordinate for an agent subscription.
53
+ *
54
+ * @property logId Identifies the stream log the sequence belongs to.
55
+ * @property seq Last stream sequence the app has seen.
56
+ */
19
57
  data class Cursor(val logId: String, val seq: Long)
20
- data class RuntimeError(val code: String, val message: String)
58
+ internal data class RuntimeError(val code: String, val message: String)
59
+ /**
60
+ * Streaming reply preview used in the runtime event view.
61
+ *
62
+ * @property firstSeq First stream sequence assigned to the reply.
63
+ * @property messageId Identifier of the reply in progress.
64
+ * @property text Text accumulated so far for this reply.
65
+ */
21
66
  data class Streaming(val messageId: String, val firstSeq: Long, val text: String)
67
+ /**
68
+ * Metadata about an input image, without the image contents.
69
+ *
70
+ * @property alt Alternative text, when supplied.
71
+ * @property bytes Encoded size in bytes, when available.
72
+ * @property mime Media type, when available.
73
+ */
22
74
  data class ImageSummary(val alt: String?, val mime: String?, val bytes: Long?)
75
+ /**
76
+ * Tool command and call identity associated with an app event.
77
+ *
78
+ * @property callId Tool call ID recorded for the event.
79
+ * @property command Command recorded as the event source.
80
+ */
23
81
  data class ToolSource(val command: String, val callId: String)
24
- enum class InputKind { USER, EVENT, UNKNOWN }
25
- enum class InputStatus { QUEUED, SEEN, ANSWERED, NO_REPLY, FAILED, CANCELLED, SETTLED_BEFORE_UPGRADE, UNKNOWN }
26
- enum class MessageStatus { COMPLETED, FAILED, CANCELLED, INTERRUPTED, UNKNOWN }
27
- enum class AgentStatus { RUNNING, WAITING, IDLE, UNKNOWN }
28
- /** The stream `state`'s `activity`: a model call, a summary call (held before the reply), or a
29
- * tool round. A value this SDK does not know yet is UNKNOWN, never a stream error. */
30
- enum class AgentActivity { MODEL, SUMMARY, TOOL, UNKNOWN }
31
- enum class CostStatus { REPORTED, ESTIMATED, NONE, UNKNOWN }
32
- enum class GapReason { CLEARED, LIMIT, UNKNOWN }
33
- enum class ImageMime { PNG, JPEG, WEBP, GIF }
34
82
 
83
+ /** Supported MIME choices for encoded tool-result image bytes. */
84
+ enum class ImageMime {
85
+ /** Encodes the media type image/png. */
86
+ PNG,
87
+ /** Encodes the media type image/jpeg. */
88
+ JPEG,
89
+ /** Encodes the media type image/webp. */
90
+ WEBP,
91
+ /** Encodes the media type image/gif. */
92
+ GIF
93
+ }
94
+
95
+ /** Tool-result image attachment. Send requests use ImageInput. */
35
96
  class InputImage {
36
97
  internal val json: JsonObject
98
+ /** Create a tool-result image from encoded bytes and the given media type. */
37
99
  constructor(data: ByteArray, mime: ImageMime, alt: String? = null, resolution: ImageResolution? = null) {
38
100
  json = JsonObject().apply {
39
101
  addProperty("data", java.util.Base64.getEncoder().encodeToString(data))
@@ -42,12 +104,13 @@ class InputImage {
42
104
  resolution?.let { addProperty("resolution", it.name.lowercase()) }
43
105
  }
44
106
  }
107
+ /** Create a tool-result image that refers to a URL. */
45
108
  constructor(url: String, alt: String? = null) {
46
109
  json = JsonObject().apply { addProperty("url", url); alt?.let { addProperty("alt", it) } }
47
110
  }
48
111
  }
49
112
 
50
- sealed class RuntimeEvent {
113
+ internal sealed class RuntimeEvent {
51
114
  open val seq: Long? get() = null
52
115
  data class Input(override val seq: Long, val firstSeq: Long, val id: String, val kind: InputKind, val text: String?,
53
116
  val images: List<ImageSummary>, val status: InputStatus, val error: RuntimeError?, val at: Instant) : RuntimeEvent()
@@ -57,7 +120,7 @@ sealed class RuntimeEvent {
57
120
  val error: RuntimeError?, val at: Instant) : RuntimeEvent()
58
121
  data class Cleared(override val seq: Long, val id: String, val at: Instant) : RuntimeEvent()
59
122
  data class App(override val seq: Long, val id: String, val name: String, val data: JsonElement, val source: ToolSource, val at: Instant) : RuntimeEvent()
60
- data class Turn(override val seq: Long, val id: String, val causedBy: List<String>, val inputs: List<String>, val purpose: String, val usage: Map<String, Long>, val costUsd: Double,
123
+ data class Turn(override val seq: Long, val id: String, val causedBy: List<String>, val inputs: List<String>, val purpose: String, val usage: Map<String, Long>, val cost: Double,
61
124
  val costStatus: CostStatus, val model: String, val imagesOmitted: Int?, val at: Instant) : RuntimeEvent()
62
125
  data class Error(override val seq: Long, val id: String, val code: String, val message: String, val inputs: List<String>, val at: Instant) : RuntimeEvent()
63
126
  data class MessageDelta(val id: String, val text: String) : RuntimeEvent()
@@ -70,5 +133,6 @@ sealed class RuntimeEvent {
70
133
  data class Snapshot(val logId: String, val state: State, val streaming: Streaming?) : RuntimeEvent()
71
134
  data class StreamError(val code: String, val message: String, val poisoned: Boolean) : RuntimeEvent()
72
135
  data object Replaced : RuntimeEvent()
73
- data class Unknown(val type: String) : RuntimeEvent()
136
+ /** Ignore unknown types and fields. The complete unknown payload is retained. */
137
+ data class Unknown(val type: String, val fields: JsonObject = JsonObject()) : RuntimeEvent()
74
138
  }