@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,715 @@
1
+ // GENERATED by scripts/generate-app-stream.mjs from the Rust app contract. Do not edit.
2
+ package dev.croche
3
+
4
+ import com.google.gson.*
5
+ import com.google.gson.annotations.JsonAdapter
6
+ import com.google.gson.stream.*
7
+
8
+ /** The app-stream reader types, generated from Core's Rust contract, and their decoder. */
9
+ object AppStreamContract {
10
+ /** Status of an accepted input: `queued` or `seen`, then one terminal status. */
11
+ sealed interface InputDisposition {
12
+ /** The wire string for this value. */
13
+ val rawValue: String
14
+ /** Accepted and waiting for a turn. */
15
+ object QUEUED: InputDisposition {
16
+ /** The wire string for this value. */
17
+ override val rawValue = "queued"
18
+ }
19
+ /** Taken up by a turn for the agent to work on. */
20
+ object SEEN: InputDisposition {
21
+ /** The wire string for this value. */
22
+ override val rawValue = "seen"
23
+ }
24
+ /** A completed reply answered the input. */
25
+ object ANSWERED: InputDisposition {
26
+ /** The wire string for this value. */
27
+ override val rawValue = "answered"
28
+ }
29
+ /** The work finished without a reply answering the input. */
30
+ object NO_REPLY: InputDisposition {
31
+ /** The wire string for this value. */
32
+ override val rawValue = "no_reply"
33
+ }
34
+ /** The input failed; its error says why. */
35
+ object FAILED: InputDisposition {
36
+ /** The wire string for this value. */
37
+ override val rawValue = "failed"
38
+ }
39
+ /** The input was cancelled. */
40
+ object CANCELLED: InputDisposition {
41
+ /** The wire string for this value. */
42
+ override val rawValue = "cancelled"
43
+ }
44
+ /**
45
+ * A wire value this SDK does not recognize.
46
+ *
47
+ * @property type The original wire string.
48
+ * @property fields The original wire value as JSON.
49
+ */
50
+ data class Unknown(val type: String, val fields: JsonElement): InputDisposition {
51
+ /** The wire string for this value. */
52
+ override val rawValue = type
53
+ }
54
+ }
55
+ /** Kind of an input's parts. */
56
+ sealed interface InputKind {
57
+ /** The wire string for this value. */
58
+ val rawValue: String
59
+ /** Text from the person using the app. */
60
+ object USER: InputKind {
61
+ /** The wire string for this value. */
62
+ override val rawValue = "user"
63
+ }
64
+ /** An event the app reported. */
65
+ object APP_EVENT: InputKind {
66
+ /** The wire string for this value. */
67
+ override val rawValue = "app_event"
68
+ }
69
+ /** Opaque app state text. */
70
+ object APP_STATE: InputKind {
71
+ /** The wire string for this value. */
72
+ override val rawValue = "app_state"
73
+ }
74
+ /**
75
+ * A wire value this SDK does not recognize.
76
+ *
77
+ * @property type The original wire string.
78
+ * @property fields The original wire value as JSON.
79
+ */
80
+ data class Unknown(val type: String, val fields: JsonElement): InputKind {
81
+ /** The wire string for this value. */
82
+ override val rawValue = type
83
+ }
84
+ }
85
+ /** How an agent reply ended. */
86
+ sealed interface MessageStatus {
87
+ /** The wire string for this value. */
88
+ val rawValue: String
89
+ /** The reply finished and answers its open inputs. */
90
+ object COMPLETED: MessageStatus {
91
+ /** The wire string for this value. */
92
+ override val rawValue = "completed"
93
+ }
94
+ /** The reply ended because its call or turn failed. */
95
+ object FAILED: MessageStatus {
96
+ /** The wire string for this value. */
97
+ override val rawValue = "failed"
98
+ }
99
+ /** The reply ended because its work was cancelled. */
100
+ object CANCELLED: MessageStatus {
101
+ /** The wire string for this value. */
102
+ override val rawValue = "cancelled"
103
+ }
104
+ /** The process stopped during the reply. */
105
+ object INTERRUPTED: MessageStatus {
106
+ /** The wire string for this value. */
107
+ override val rawValue = "interrupted"
108
+ }
109
+ /**
110
+ * A wire value this SDK does not recognize.
111
+ *
112
+ * @property type The original wire string.
113
+ * @property fields The original wire value as JSON.
114
+ */
115
+ data class Unknown(val type: String, val fields: JsonElement): MessageStatus {
116
+ /** The wire string for this value. */
117
+ override val rawValue = type
118
+ }
119
+ }
120
+ /** Whether the agent has work. */
121
+ sealed interface AgentStatus {
122
+ /** The wire string for this value. */
123
+ val rawValue: String
124
+ /** Nothing to do and nothing to receive. */
125
+ object IDLE: AgentStatus {
126
+ /** The wire string for this value. */
127
+ override val rawValue = "idle"
128
+ }
129
+ /** A turn runs, an accepted input is queued, or a tool result waits to continue the turn. */
130
+ object RUNNING: AgentStatus {
131
+ /** The wire string for this value. */
132
+ override val rawValue = "running"
133
+ }
134
+ /** Nothing to do, but a late tool result is still to arrive. */
135
+ object WAITING: AgentStatus {
136
+ /** The wire string for this value. */
137
+ override val rawValue = "waiting"
138
+ }
139
+ /**
140
+ * A wire value this SDK does not recognize.
141
+ *
142
+ * @property type The original wire string.
143
+ * @property fields The original wire value as JSON.
144
+ */
145
+ data class Unknown(val type: String, val fields: JsonElement): AgentStatus {
146
+ /** The wire string for this value. */
147
+ override val rawValue = type
148
+ }
149
+ }
150
+ /** Why a model call other than an ordinary reply call was made. */
151
+ sealed interface TurnPurpose {
152
+ /** The wire string for this value. */
153
+ val rawValue: String
154
+ /** The call made a context summary. */
155
+ object SUMMARY: TurnPurpose {
156
+ /** The wire string for this value. */
157
+ override val rawValue = "summary"
158
+ }
159
+ /**
160
+ * A wire value this SDK does not recognize.
161
+ *
162
+ * @property type The original wire string.
163
+ * @property fields The original wire value as JSON.
164
+ */
165
+ data class Unknown(val type: String, val fields: JsonElement): TurnPurpose {
166
+ /** The wire string for this value. */
167
+ override val rawValue = type
168
+ }
169
+ }
170
+ /** A memory operation the app can make. */
171
+ sealed interface MemoryOp {
172
+ /** The wire string for this value. */
173
+ val rawValue: String
174
+ /** One memory fact was deleted. */
175
+ object DELETE: MemoryOp {
176
+ /** The wire string for this value. */
177
+ override val rawValue = "delete"
178
+ }
179
+ /** All memory facts were deleted. */
180
+ object CLEAR: MemoryOp {
181
+ /** The wire string for this value. */
182
+ override val rawValue = "clear"
183
+ }
184
+ /** Memory was turned on or off. */
185
+ object ENABLED: MemoryOp {
186
+ /** The wire string for this value. */
187
+ override val rawValue = "enabled"
188
+ }
189
+ /**
190
+ * A wire value this SDK does not recognize.
191
+ *
192
+ * @property type The original wire string.
193
+ * @property fields The original wire value as JSON.
194
+ */
195
+ data class Unknown(val type: String, val fields: JsonElement): MemoryOp {
196
+ /** The wire string for this value. */
197
+ override val rawValue = type
198
+ }
199
+ }
200
+ /** Metadata of a stored image original that Core keeps for the app, a message or a tool call. */
201
+ data class Attachment(
202
+ /** Core-assigned attachment id, used to read, copy, release or delete the original. */
203
+ val id: String,
204
+ /** What the attachment is; Core currently stores only `image` (open string). */
205
+ val kind: String,
206
+ /** Where the stored original came from, for example `tool` (produced by a tool call) or `app` (copied in by the app). */
207
+ val origin: String,
208
+ /** Image media type of the stored original, for example `image/png`. */
209
+ val mediaType: String,
210
+ /** Size of the stored original in bytes. */
211
+ val bytes: Long,
212
+ /** Lowercase hex SHA-256 of the stored original's bytes. */
213
+ val sha256: String,
214
+ /** The original's pixel width, when Core reports it; absent otherwise. */
215
+ val width: Long? = null,
216
+ /** The original's pixel height, when Core reports it; absent otherwise. */
217
+ val height: Long? = null,
218
+ /** Description text supplied with the image; absent when none was given. */
219
+ val alt: String? = null,
220
+ /** Id of the agent tool call that produced the original (the same id as `ToolEvent.id`); absent for originals not produced by a call. */
221
+ val callId: String? = null,
222
+ /** Present only as `true` when the original is no longer stored at read time; the logged row itself is not changed. */
223
+ val deleted: Boolean? = null,
224
+ /** Why the original is gone: `deleted` (explicitly deleted or missing), `evicted` (removed to make room or past retention) or `cleared` (released by a history clear); present only with `deleted`. */
225
+ val deletedReason: String? = null
226
+ )
227
+ /** An error carried by an event or result, with the category that tells the app how to react. */
228
+ data class EventError(
229
+ /** Error code, for example `store_full` or `interrupted`; a code outside the known table has category `internal`. */
230
+ val code: String,
231
+ /** What the app does about the error. */
232
+ val category: ErrorCategory,
233
+ /** Human-readable explanation of the error. */
234
+ val message: String,
235
+ /** Integer seconds, present only on the hourly app-paid rate_limited refusal. */
236
+ val retryAfter: Long? = null
237
+ )
238
+ /** An image that could not be viewed for one model call; the call continues with the image's id and description. */
239
+ data class ViewError(
240
+ /** Id of the attachment whose view failed. */
241
+ val attachmentId: String,
242
+ /** Error code for the failed view, for example `image_unsupported`. */
243
+ val code: String,
244
+ /** What the app does about the error. */
245
+ val category: ErrorCategory,
246
+ /** Human-readable explanation of why the view failed. */
247
+ val message: String
248
+ )
249
+ /** Returned when Core accepts a send: the input's id, its status at acceptance and where its events start in the stream. */
250
+ @ConsistentCopyVisibility
251
+ data class SendReceipt internal constructor(
252
+ /** Id of the accepted input. */
253
+ val requestId: String,
254
+ /** The input's status when the receipt was made; `queued` for a newly accepted input, or the recorded status when the same id was sent again. */
255
+ val status: InputDisposition,
256
+ /** Stream sequence of the input's first event, or for a just-accepted input the position its events start from. */
257
+ val seq: Long,
258
+ /** Why the input failed; present when `status` is `failed`. */
259
+ val error: EventError? = null
260
+ )
261
+ /** The terminal result of an accepted `request`: the input's final status and the replies it caused. */
262
+ @ConsistentCopyVisibility
263
+ data class RequestResult internal constructor(
264
+ /** Id of the input this result is for. */
265
+ val id: String,
266
+ /** The input's terminal status. */
267
+ val status: InputDisposition,
268
+ /** The retained `message.end` events whose `causedBy` includes this input. */
269
+ val messages: List<MessageEnd>,
270
+ /** Present only as `true` when some of this input's events were already pruned, so `messages` can be incomplete or empty. */
271
+ val gap: Boolean? = null,
272
+ /** Why the input failed; always present when `status` is `failed`. */
273
+ val error: EventError? = null
274
+ )
275
+ /** An input was accepted or its status changed; each change re-emits the input's full current state. */
276
+ data class InputEvent(
277
+ /** Id of the input. */
278
+ val id: String,
279
+ /** Stream sequence of this event. */
280
+ val seq: Long,
281
+ /** Stream sequence of this input's first event; the same on every update of the input. */
282
+ val firstSeq: Long,
283
+ /** Which kind of input parts this row shows. */
284
+ val kind: InputKind,
285
+ /** The input's status after this change. */
286
+ val status: InputDisposition,
287
+ /** ISO 8601 time of this change. */
288
+ val at: String,
289
+ /** Text of the input's parts of this `kind`, joined with blank lines; absent when Core holds no summary for the input. */
290
+ val text: String? = null,
291
+ /** Why the input failed; always present when `status` is `failed` and absent otherwise. */
292
+ val error: EventError? = null
293
+ )
294
+ /** A held send left without running; Core emits it after reopen for a send that was held when the app stopped. */
295
+ data class InputDropped(
296
+ /** Id of the dropped input. */
297
+ val inputId: String,
298
+ /** Why the input was dropped; Core's stream emits `reopened` (open string). */
299
+ val reason: String,
300
+ /** Stream sequence of this event. */
301
+ val seq: Long,
302
+ /** Stream sequence of the input's first event when it had one, otherwise this event's own sequence. */
303
+ val firstSeq: Long
304
+ )
305
+ /** An agent reply began; Core emits it when the reply has its first visible text, before any of its deltas. */
306
+ data class MessageStart(
307
+ /** Id of the reply message, shared by its start, deltas and end. */
308
+ val id: String,
309
+ /** Stream sequence of this event. */
310
+ val seq: Long,
311
+ /** Stream sequence of the message's first event, which is this start. */
312
+ val firstSeq: Long,
313
+ /** ISO 8601 time the reply started. */
314
+ val at: String
315
+ )
316
+ /** New text of the open reply as it is written; a preview only, since `message.end` carries the stored text. */
317
+ data class MessageDelta(
318
+ /** Id of the open reply message. */
319
+ val id: String,
320
+ /** Text added to the reply since the previous delta. */
321
+ val text: String
322
+ )
323
+ /** The end of an agent reply with its stored text and final status; never rewritten. */
324
+ data class MessageEnd(
325
+ /** Id of the reply message. */
326
+ val id: String,
327
+ /** Stream sequence of this event. */
328
+ val seq: Long,
329
+ /** Stream sequence of the message's first event (its `message.start`). */
330
+ val firstSeq: Long,
331
+ /** ISO 8601 time the reply ended. */
332
+ val at: String,
333
+ /** How the reply ended. */
334
+ val status: MessageStatus,
335
+ /** The stored reply text with markers removed; empty after an interruption or when the reply was too large to store. */
336
+ val text: String,
337
+ /** Names of the registered markers found in the reply, in reply order. */
338
+ val markers: List<String>,
339
+ /** Ids of the inputs the turn producing this reply worked for. */
340
+ val causedBy: List<String>,
341
+ /** Ids of the inputs this reply answered; only a `completed` reply answers inputs, so it is empty otherwise. */
342
+ val inReplyTo: List<String>,
343
+ /** The reply before marker removal; equal to `text` when markers did not change it. */
344
+ val raw: String,
345
+ /** The checked structured-output value of a reply made with a response format; absent otherwise. */
346
+ val output: JsonElement? = null,
347
+ /** Why the reply did not complete; always present when `status` is `failed`. */
348
+ val error: EventError? = null,
349
+ /** Originals attached to this reply; absent when there are none. */
350
+ val attachments: List<Attachment>? = null
351
+ )
352
+ /** One model call was recorded, with its usage, cost and model; Core writes it when it records the call's cost. */
353
+ data class TurnEvent(
354
+ /** Opaque id of the model call; do not parse it. */
355
+ val id: String,
356
+ /** Ids of the inputs first seen by this call. */
357
+ val inputs: List<String>,
358
+ /** Ids of every input this call worked for. */
359
+ val causedBy: List<String>,
360
+ /** Token counts reported for the call (`prompt`, `completion`, `total`, `cached`, `cacheWrite`, `reasoning` when reported), or null when none were reported. */
361
+ val usage: JsonElement,
362
+ /** Cost of the call in credits; null when unknown. */
363
+ val cost: Double?,
364
+ /** How final `cost` is, for example `reported` (final), `unknown` (null cost), `estimated` (provisional) or `none` (zero cost). */
365
+ val costStatus: String,
366
+ /** The model recorded for the call; the requested model when no response named one. */
367
+ val model: String,
368
+ /** ISO 8601 time the call was recorded. */
369
+ val at: String,
370
+ /** `summary` when the call made a context summary; absent for an ordinary model call. */
371
+ val purpose: TurnPurpose? = null,
372
+ /** Reported serving-provider label; absent when unavailable. Diagnostic only; never changes pricing or settlement. */
373
+ val provider: String? = null,
374
+ /** Images whose view failed; the call continues with their id and description. */
375
+ val viewErrors: List<ViewError>? = null
376
+ )
377
+ /** An agent tool call started or changed status; updates keep the same id and `firstSeq`. */
378
+ data class ToolEvent(
379
+ /** Opaque Core-assigned call id, the same as `ToolContext.callId` and an attachment's `callId`; do not parse it. */
380
+ val id: String,
381
+ /** Stream sequence of this event. */
382
+ val seq: Long,
383
+ /** Stream sequence of the call's first event; the same on every update of the call. */
384
+ val firstSeq: Long,
385
+ /** Who made the call; Core emits `agent` for these events (open string). */
386
+ val origin: String,
387
+ /** Ids of the inputs the call works for. */
388
+ val causedBy: List<String>,
389
+ /** Name of the called tool. */
390
+ val tool: String,
391
+ /** Stable command key of the called command. */
392
+ val key: String,
393
+ /** Arguments of the call, without app-bound arguments; `{}` when there are none. */
394
+ val args: JsonElement,
395
+ /** Status of the call: `running`, `waiting` (its result arrives later), `completed`, `failed`, `cancelled` or `unused` (a late result whose cause was cancelled) (open string). */
396
+ val status: String,
397
+ /** Cost of the call in credits; null while running or when unknown, 0 for an unpaid call. */
398
+ val cost: Double?,
399
+ /** How final `cost` is, for example `unknown` while running, `reported`, or `none` for an unpaid call. */
400
+ val costStatus: String,
401
+ /** ISO 8601 time the call started. */
402
+ val startedAt: String,
403
+ /** ISO 8601 time of this update. */
404
+ val at: String,
405
+ /** Id of the `turn` event for the model call that requested this tool call; absent when not recorded. */
406
+ val requestedBy: String? = null,
407
+ /** What the model was given as the result: `{text}`, plus `images` metadata (`mediaType`, `bytes`, `attachment`) for result images; absent while running, and removed when Core closes an unsettled call as failed or cancelled. */
408
+ val delivered: JsonElement? = null,
409
+ /** Originals the call kept as attachments, as `{attachments: [{id, mediaType, bytes}]}`; absent when none. */
410
+ val outputs: JsonElement? = null
411
+ )
412
+ /** The agent's current state: status, queue length, typing, and what running work is doing. */
413
+ data class StateEvent(
414
+ /** Whether the agent is idle, running or waiting. */
415
+ val status: AgentStatus,
416
+ /** Number of accepted sends waiting in the queue. */
417
+ val queued: Long,
418
+ /** True while a reply's `message.start` is written and its `message.end` is not. */
419
+ val typing: Boolean,
420
+ /** What running work is doing, for example `model`, `summary` or `tool`; null unless `status` is `running`. */
421
+ val activity: String?,
422
+ /** Names of the tools in the current round, in call order (built-in or app command key, else `unknown`); present only when `activity` is `tool`. */
423
+ val tools: List<String>? = null
424
+ )
425
+ /** The subscription's starting point: the current log, state and the reply being streamed; delivered first on attach. */
426
+ data class SnapshotEvent(
427
+ /** Id of the log the subscription reads; pass it back with a `seq` to resume. */
428
+ val logId: String,
429
+ /** The current `state` event. */
430
+ val state: JsonElement,
431
+ /** The reply being streamed now as `{messageId, firstSeq, text}`, or null when none. */
432
+ val streaming: JsonElement
433
+ )
434
+ /** An older page of the conversation, delivered after `subscription.history()`. */
435
+ data class PageEvent(
436
+ /** The page's rows oldest first, each as its latest event. */
437
+ val messages: List<AgentEvent>,
438
+ /** True when no older retained row was left out of this page. */
439
+ val reachedFloor: Boolean,
440
+ /** Id of the log the page was read from. */
441
+ val logId: String,
442
+ /** Stream sequence of the latest history clear, or 0 when there was none. */
443
+ val clearedSeq: Long
444
+ )
445
+ /** A full `clearHistory()` took effect; empty the displayed conversation. */
446
+ data class ClearedEvent(
447
+ /** Core-assigned id of this clear. */
448
+ val id: String,
449
+ /** ISO 8601 time the clear took effect. */
450
+ val at: String
451
+ )
452
+ /** A memory delete, clear or enable change took effect. */
453
+ data class MemoryEvent(
454
+ /** Core-assigned id of the memory operation. */
455
+ val id: String,
456
+ /** Which memory operation took effect. */
457
+ val op: MemoryOp,
458
+ /** ISO 8601 time the operation took effect. */
459
+ val at: String,
460
+ /** Id of the deleted memory fact; present only for `delete`. */
461
+ val item: String? = null,
462
+ /** The new memory setting; present only for `enabled`. */
463
+ val enabled: Boolean? = null,
464
+ /** Number of memory facts removed; present for `delete` and `clear`. */
465
+ val removed: Long? = null
466
+ )
467
+ /** Events were missed; redraw from a `page`. */
468
+ data class GapEvent(
469
+ /** Last stream sequence before the missed range. */
470
+ val afterSeq: Long,
471
+ /** Last missed stream sequence (inclusive). */
472
+ val throughSeq: Long,
473
+ /** Why the events are missing: `limit` (retention pruned them) or `cleared` (a history clear removed them). */
474
+ val reason: String
475
+ )
476
+ /** The subscription ended with an error; it receives no further events. */
477
+ data class SubscriptionError(
478
+ /** Error code, for example `storage_error`. */
479
+ val code: String,
480
+ /** Human-readable explanation of the error. */
481
+ val message: String,
482
+ /** Present only as `true` when a storage failure stopped the agent from writing; reopen to continue. */
483
+ val poisoned: Boolean? = null
484
+ )
485
+ /** The subscription ended because a newer subscription replaced it. */
486
+ class ReplacedEvent
487
+ /** One subscription event, by its wire `type`. Ignore or log `Unknown`. */
488
+ sealed interface AgentEvent {
489
+ /**
490
+ * The `input` event: see [InputEvent].
491
+ *
492
+ * @property value The event payload.
493
+ */
494
+ data class InputEventEvent(val value: AppStreamContract.InputEvent): AgentEvent
495
+ /**
496
+ * The `input.dropped` event: see [InputDropped].
497
+ *
498
+ * @property value The event payload.
499
+ */
500
+ data class InputDroppedEvent(val value: AppStreamContract.InputDropped): AgentEvent
501
+ /**
502
+ * The `message.start` event: see [MessageStart].
503
+ *
504
+ * @property value The event payload.
505
+ */
506
+ data class MessageStartEvent(val value: AppStreamContract.MessageStart): AgentEvent
507
+ /**
508
+ * The `message.delta` event: see [MessageDelta].
509
+ *
510
+ * @property value The event payload.
511
+ */
512
+ data class MessageDeltaEvent(val value: AppStreamContract.MessageDelta): AgentEvent
513
+ /**
514
+ * The `message.end` event: see [MessageEnd].
515
+ *
516
+ * @property value The event payload.
517
+ */
518
+ data class MessageEndEvent(val value: AppStreamContract.MessageEnd): AgentEvent
519
+ /**
520
+ * The `turn` event: see [TurnEvent].
521
+ *
522
+ * @property value The event payload.
523
+ */
524
+ data class TurnEventEvent(val value: AppStreamContract.TurnEvent): AgentEvent
525
+ /**
526
+ * The `tool` event: see [ToolEvent].
527
+ *
528
+ * @property value The event payload.
529
+ */
530
+ data class ToolEventEvent(val value: AppStreamContract.ToolEvent): AgentEvent
531
+ /**
532
+ * The `state` event: see [StateEvent].
533
+ *
534
+ * @property value The event payload.
535
+ */
536
+ data class StateEventEvent(val value: AppStreamContract.StateEvent): AgentEvent
537
+ /**
538
+ * The `snapshot` event: see [SnapshotEvent].
539
+ *
540
+ * @property value The event payload.
541
+ */
542
+ data class SnapshotEventEvent(val value: AppStreamContract.SnapshotEvent): AgentEvent
543
+ /**
544
+ * The `page` event: see [PageEvent].
545
+ *
546
+ * @property value The event payload.
547
+ */
548
+ data class PageEventEvent(val value: AppStreamContract.PageEvent): AgentEvent
549
+ /**
550
+ * The `cleared` event: see [ClearedEvent].
551
+ *
552
+ * @property value The event payload.
553
+ */
554
+ data class ClearedEventEvent(val value: AppStreamContract.ClearedEvent): AgentEvent
555
+ /**
556
+ * The `memory` event: see [MemoryEvent].
557
+ *
558
+ * @property value The event payload.
559
+ */
560
+ data class MemoryEventEvent(val value: AppStreamContract.MemoryEvent): AgentEvent
561
+ /**
562
+ * The `gap` event: see [GapEvent].
563
+ *
564
+ * @property value The event payload.
565
+ */
566
+ data class GapEventEvent(val value: AppStreamContract.GapEvent): AgentEvent
567
+ /**
568
+ * The `error` event: see [SubscriptionError].
569
+ *
570
+ * @property value The event payload.
571
+ */
572
+ data class SubscriptionErrorEvent(val value: AppStreamContract.SubscriptionError): AgentEvent
573
+ /**
574
+ * The `replaced` event: see [ReplacedEvent].
575
+ *
576
+ * @property value The event payload.
577
+ */
578
+ data class ReplacedEventEvent(val value: AppStreamContract.ReplacedEvent): AgentEvent
579
+ /**
580
+ * An event type this SDK does not know, with every field kept.
581
+ *
582
+ * @property type The original event type.
583
+ * @property fields A copy of the original JSON object.
584
+ */
585
+ data class Unknown(val type: String, val fields: JsonObject): AgentEvent
586
+ }
587
+ private class StringReaderAdapter<T>(val read: (String) -> T, val write: (T) -> String): JsonDeserializer<T>, JsonSerializer<T> {
588
+ override fun deserialize(json: JsonElement, type: java.lang.reflect.Type, context: JsonDeserializationContext): T = read(json.asString)
589
+ override fun serialize(value: T, type: java.lang.reflect.Type, context: JsonSerializationContext): JsonElement = JsonPrimitive(write(value))
590
+ }
591
+ private val gson: Gson = GsonBuilder()
592
+ .registerTypeAdapter(InputDisposition::class.java, StringReaderAdapter<InputDisposition>({ value -> when (value) {
593
+ "queued" -> InputDisposition.QUEUED
594
+ "seen" -> InputDisposition.SEEN
595
+ "answered" -> InputDisposition.ANSWERED
596
+ "no_reply" -> InputDisposition.NO_REPLY
597
+ "failed" -> InputDisposition.FAILED
598
+ "cancelled" -> InputDisposition.CANCELLED
599
+ else -> InputDisposition.Unknown(value, JsonPrimitive(value))
600
+ } }, { it.rawValue }))
601
+ .registerTypeAdapter(InputKind::class.java, StringReaderAdapter<InputKind>({ value -> when (value) {
602
+ "user" -> InputKind.USER
603
+ "app_event" -> InputKind.APP_EVENT
604
+ "app_state" -> InputKind.APP_STATE
605
+ else -> InputKind.Unknown(value, JsonPrimitive(value))
606
+ } }, { it.rawValue }))
607
+ .registerTypeAdapter(MessageStatus::class.java, StringReaderAdapter<MessageStatus>({ value -> when (value) {
608
+ "completed" -> MessageStatus.COMPLETED
609
+ "failed" -> MessageStatus.FAILED
610
+ "cancelled" -> MessageStatus.CANCELLED
611
+ "interrupted" -> MessageStatus.INTERRUPTED
612
+ else -> MessageStatus.Unknown(value, JsonPrimitive(value))
613
+ } }, { it.rawValue }))
614
+ .registerTypeAdapter(AgentStatus::class.java, StringReaderAdapter<AgentStatus>({ value -> when (value) {
615
+ "idle" -> AgentStatus.IDLE
616
+ "running" -> AgentStatus.RUNNING
617
+ "waiting" -> AgentStatus.WAITING
618
+ else -> AgentStatus.Unknown(value, JsonPrimitive(value))
619
+ } }, { it.rawValue }))
620
+ .registerTypeAdapter(TurnPurpose::class.java, StringReaderAdapter<TurnPurpose>({ value -> when (value) {
621
+ "summary" -> TurnPurpose.SUMMARY
622
+ else -> TurnPurpose.Unknown(value, JsonPrimitive(value))
623
+ } }, { it.rawValue }))
624
+ .registerTypeAdapter(MemoryOp::class.java, StringReaderAdapter<MemoryOp>({ value -> when (value) {
625
+ "delete" -> MemoryOp.DELETE
626
+ "clear" -> MemoryOp.CLEAR
627
+ "enabled" -> MemoryOp.ENABLED
628
+ else -> MemoryOp.Unknown(value, JsonPrimitive(value))
629
+ } }, { it.rawValue }))
630
+ .registerTypeAdapter(AgentEvent::class.java, JsonDeserializer<AgentEvent> { json, _, _ -> decode(json.asJsonObject) }).create()
631
+ /** Decodes one event by its `type`. An unrecognized type becomes [AgentEvent.Unknown]. */
632
+ fun decode(value: JsonObject): AgentEvent = when (value.get("type").asString) {
633
+ "input" -> AgentEvent.InputEventEvent(gson.fromJson(value, InputEvent::class.java))
634
+ "input.dropped" -> AgentEvent.InputDroppedEvent(gson.fromJson(value, InputDropped::class.java))
635
+ "message.start" -> AgentEvent.MessageStartEvent(gson.fromJson(value, MessageStart::class.java))
636
+ "message.delta" -> AgentEvent.MessageDeltaEvent(gson.fromJson(value, MessageDelta::class.java))
637
+ "message.end" -> AgentEvent.MessageEndEvent(gson.fromJson(value, MessageEnd::class.java))
638
+ "turn" -> AgentEvent.TurnEventEvent(gson.fromJson(value, TurnEvent::class.java))
639
+ "tool" -> AgentEvent.ToolEventEvent(gson.fromJson(value, ToolEvent::class.java))
640
+ "state" -> AgentEvent.StateEventEvent(gson.fromJson(value, StateEvent::class.java))
641
+ "snapshot" -> AgentEvent.SnapshotEventEvent(gson.fromJson(value, SnapshotEvent::class.java))
642
+ "page" -> AgentEvent.PageEventEvent(gson.fromJson(value, PageEvent::class.java))
643
+ "cleared" -> AgentEvent.ClearedEventEvent(gson.fromJson(value, ClearedEvent::class.java))
644
+ "memory" -> AgentEvent.MemoryEventEvent(gson.fromJson(value, MemoryEvent::class.java))
645
+ "gap" -> AgentEvent.GapEventEvent(gson.fromJson(value, GapEvent::class.java))
646
+ "error" -> AgentEvent.SubscriptionErrorEvent(gson.fromJson(value, SubscriptionError::class.java))
647
+ "replaced" -> AgentEvent.ReplacedEventEvent(gson.fromJson(value, ReplacedEvent::class.java))
648
+ else -> AgentEvent.Unknown(value.get("type").asString, value.deepCopy())
649
+ }
650
+ internal fun decodeSendReceipt(value: JsonObject): SendReceipt = gson.fromJson(value, SendReceipt::class.java)
651
+ internal fun decodeRequestResult(value: JsonObject): RequestResult = gson.fromJson(value, RequestResult::class.java)
652
+ /** The ONE closed set (APP-API): Core attaches it to every code, and a value outside it does not decode. */
653
+ @JsonAdapter(ErrorCategoryAdapter::class, nullSafe = false)
654
+ enum class ErrorCategory {
655
+ /** A network or Croche Cloud failure. Retry later; the input is kept. */
656
+ OFFLINE,
657
+ /** Credit or allowance ran out. Tell the user; retrying after a top-up works. */
658
+ ALLOWANCE,
659
+ /** Usage is stopped by the project, an account or a rate limit. Wait, or contact the operator. */
660
+ PAUSED,
661
+ /** A developer fix is needed: key, config, model or device identity. */
662
+ SETUP,
663
+ /** The work or the wait stopped; nothing to fix. An aborted wait can leave the input running. */
664
+ CLOSED,
665
+ /** The app's request cannot run as given. */
666
+ INVALID,
667
+ /** The work failed for a reason outside the app. Report it. A code outside Core's table is also `internal`. */
668
+ INTERNAL
669
+ }
670
+ private class ErrorCategoryAdapter: TypeAdapter<ErrorCategory>() {
671
+ override fun read(input: JsonReader): ErrorCategory {
672
+ if (input.peek() != JsonToken.STRING) throw JsonParseException("ErrorCategory must be a string.")
673
+ return when (input.nextString()) {
674
+ "offline" -> ErrorCategory.OFFLINE
675
+ "allowance" -> ErrorCategory.ALLOWANCE
676
+ "paused" -> ErrorCategory.PAUSED
677
+ "setup" -> ErrorCategory.SETUP
678
+ "closed" -> ErrorCategory.CLOSED
679
+ "invalid" -> ErrorCategory.INVALID
680
+ "internal" -> ErrorCategory.INTERNAL
681
+ else -> throw JsonParseException("Unknown ErrorCategory.")
682
+ }
683
+ }
684
+ override fun write(output: JsonWriter, value: ErrorCategory) {
685
+ output.value(when (value) {
686
+ ErrorCategory.OFFLINE -> "offline"
687
+ ErrorCategory.ALLOWANCE -> "allowance"
688
+ ErrorCategory.PAUSED -> "paused"
689
+ ErrorCategory.SETUP -> "setup"
690
+ ErrorCategory.CLOSED -> "closed"
691
+ ErrorCategory.INVALID -> "invalid"
692
+ ErrorCategory.INTERNAL -> "internal"
693
+ })
694
+ }
695
+ }
696
+ internal fun errorCategory(code: String): ErrorCategory {
697
+ if (Regex("^http_[1-5][0-9]{2}$").matches(code)) return ErrorCategory.OFFLINE
698
+ return when (code) {
699
+ "offline", "network_error", "request_timeout", "gateway_unavailable", "invalid_cloud_response", "stale_control", "http_<status>" -> ErrorCategory.OFFLINE
700
+ "account_credit_exhausted", "project_budget_exhausted", "user_allowance_exhausted", "development_allowance_exhausted", "unverified_allowance_exhausted", "gateway_key_exhausted", "provider_credit_unavailable" -> ErrorCategory.ALLOWANCE
701
+ "usage_paused", "runtime_blocked", "project_access_disabled", "account_disabled", "server_key_revoked", "development_key_revoked", "development_device_limit", "rate_limited", "provider_rate_limited" -> ErrorCategory.PAUSED
702
+ "user_allowance_disabled", "invalid_configuration", "model_missing", "model_withdrawn", "model_unavailable", "project_key_unknown", "server_key_invalid", "development_key_invalid", "user_required", "gateway_key_rejected", "gateway_unsupported", "schema_unsupported", "capability_unsupported", "invalid_snapshot", "snapshot_mismatch", "invalid_tool", "invalid_wiki", "installation_unverified", "attestation_required", "attestation_rejected", "attestation_unverifiable", "attestation_failed", "attestation_unavailable", "attestation_unsupported", "attestation_timeout", "recovery_required", "host_unavailable", "core_unavailable" -> ErrorCategory.SETUP
703
+ "state_conflict", "outcome_unknown", "closed", "target_closed", "runtime_detached", "cancelled", "interrupted", "preempted", "aborted", "observation_lost", "store_busy", "instance_busy" -> ErrorCategory.CLOSED
704
+ "invalid_input", "input_too_large", "invalid_memory", "invalid_response_format", "invalid_request", "tool_unauthorized", "agent_conflict", "unknown_id", "attachment_storage_full", "idempotency_conflict", "identity_conflict", "busy", "queue_full", "cursor_reset", "context_limit", "output_limit", "iteration_limit", "structured_output_unsupported" -> ErrorCategory.INVALID
705
+ "failure_unrecorded", "internal", "asset_read_failed", "stream_incomplete", "provider_error", "provider_rejected", "invalid_provider_response", "invalid_response", "output_too_large", "output_invalid", "empty_response", "unexpected_tool_call", "storage_error", "store_refused", "store_full", "corrupt_store", "store_too_new", "fresh_reservation_lost", "archive_unavailable", "archive_error", "host_error", "host_unresponsive", "thread_unavailable", "core_error", "invalid_abi", "no_lock", "handler_failed", "subscriber_overflow" -> ErrorCategory.INTERNAL
706
+ else -> ErrorCategory.INTERNAL
707
+ }
708
+ }
709
+ internal fun representationErrorCategory(code: String): ErrorCategory = when (code) {
710
+ "invalid_configuration" -> ErrorCategory.SETUP
711
+ "invalid_input" -> ErrorCategory.INVALID
712
+ "invalid_tool_result" -> ErrorCategory.INVALID
713
+ else -> errorCategory(code)
714
+ }
715
+ }