@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,172 @@
1
+ // Croche: one SDK object = one Core Croche, the shared-resource factory for one user's session (ARCHITECTURE §2-3).
2
+ // Core decides reuse (the same (projectKey, user) twice = the same Core Croche, ref-counted), defaults, validation
3
+ // and delivery. The wrapper serializes, calls once, parses.
4
+ import { wrapAgent } from './agent.js';
5
+ import { tokenFor } from './cancel.js';
6
+ import { coreModule } from './core/wasm.js';
7
+ import { CrocheError } from './errors.js';
8
+ import { eventSink } from './events.js';
9
+ import { jsonText, optionsText } from './json.js';
10
+ import { createHost, storageFor } from './pal/host.js';
11
+ import { adaptersFor } from './adapters.js';
12
+ import { coreDefinition } from './tools.js';
13
+ import { runToolResult } from './run-tool.js';
14
+ /** One `tools` entry: Core's definition handle, and the app's WHOLE wrapper object with `tool` as null (S1 #830).
15
+ * The wrapper's keys are Core's to read and refuse; the SDK only lifts out the handle it cannot serialize. */
16
+ function registration(entry, index) {
17
+ const bare = coreDefinition(entry);
18
+ if (bare)
19
+ return { registration: { tool: bare }, marker: null };
20
+ const object = typeof entry === 'object' && entry !== null ? entry : undefined;
21
+ const tool = object && coreDefinition(object.tool);
22
+ if (!object || !tool) {
23
+ throw new CrocheError('invalid_configuration', `$.tools[${index}]: not a tool definition (use defineTool or tools)`, 'setup');
24
+ }
25
+ const marker = { ...object, tool: null };
26
+ return { registration: { tool, optionsJson: jsonText(marker, `$.tools[${index}]`) }, marker };
27
+ }
28
+ /** An opaque reference the app gave becomes a null marker in the JSON; an absent one stays absent. For `storage`,
29
+ * presence is how Core records custom storage (#829): the platform default never adds the key. */
30
+ const nullIfGiven = (options, key) => options[key] === undefined ? {} : { [key]: null };
31
+ /** OpenOptions as Core takes it (vectors/s1-null-markers-06.json): the whole JSON with each given opaque reference as
32
+ * a null marker in place, the registrations in order, the storage and the host. */
33
+ function opening(options, recoveryGiven = false) {
34
+ const selected = adaptersFor(options.adapters);
35
+ const entries = options.tools === undefined || recoveryGiven ? [] : Array.from(options.tools, registration);
36
+ const whole = {
37
+ ...options,
38
+ ...(options.tools === undefined ? {} : { tools: recoveryGiven ? Array.from(options.tools, () => null) : entries.map(entry => entry.marker) }),
39
+ ...(options.adapters === undefined ? {} : { adapters: options.adapters.map(adapter => ({ kind: adapter.kind })) }),
40
+ ...nullIfGiven(options, 'platform'),
41
+ };
42
+ return {
43
+ json: optionsText(whole),
44
+ registrations: entries.map(entry => entry.registration),
45
+ host: createHost(options.platform, selected.image, selected.blob),
46
+ storage: storageFor(selected.storage),
47
+ };
48
+ }
49
+ /** A user's Croche session for opening agents, running tools and accessing shared resources. */
50
+ export class Croche {
51
+ #module;
52
+ #core;
53
+ constructor(module, core) {
54
+ this.#module = module;
55
+ this.#core = core;
56
+ }
57
+ /** Open the app’s user session before letting that user talk to an agent or run a tool. */
58
+ static async open(options, recovery) {
59
+ const module = coreModule();
60
+ const recoveryJson = optionsText(recovery);
61
+ // Carry the separate mode to Core unchanged. A supplied mode needs no tool
62
+ // references; Core validates the mode before deciding whether it can open.
63
+ const { json, registrations, storage, host } = opening(options, recoveryJson !== undefined);
64
+ return new Croche(module, await module.open(json, registrations, storage, host, recoveryJson));
65
+ }
66
+ /**
67
+ * Honor a user’s request to erase one workspace or all their local Croche data.
68
+ *
69
+ * Deletes this user's local data in the scope. Core closes selected agents first.
70
+ */
71
+ async deleteData(scope) {
72
+ await this.#core.deleteData(optionsText(scope));
73
+ }
74
+ /**
75
+ * Let the app keep up with due work when its UI is no longer in the foreground.
76
+ *
77
+ * Once at app start. Core keeps BackgroundEvents durably and delivers each at least once to the sink. Use the same
78
+ * adapters as open() (the platform defaults when omitted).
79
+ */
80
+ static registerBackground(options) {
81
+ const { adapters, ...given } = options ?? {};
82
+ if (Object.hasOwn(given, 'storage')) {
83
+ throw new CrocheError('invalid_configuration', 'Pass the StateStore in adapters.', 'setup');
84
+ }
85
+ const { sink } = given;
86
+ const { storage: state, image, blob } = adaptersFor(adapters);
87
+ const host = createHost(undefined, image, blob);
88
+ // The SDK selects adapters. Core still validates other options and the opaque storage and sink markers.
89
+ const json = optionsText({ ...given, ...nullIfGiven(given, 'sink'), ...(state === undefined ? {} : { storage: null }) });
90
+ coreModule().registerBackground(json, sink && eventSink(event => sink.onEvent(event)), storageFor(state), undefined, // INTERNAL platform_storage: Node and web have no separate OS default store
91
+ host);
92
+ }
93
+ /**
94
+ * Let a server schedule just the users whose background work is due.
95
+ *
96
+ * Read delivery deadlines without opening a project. before/after are epoch milliseconds; after is inclusive.
97
+ */
98
+ static async wakeTimes(options, query) {
99
+ const { json, storage, host } = opening(options);
100
+ return JSON.parse(await coreModule().wakeTimes(json, optionsText(query), storage, host));
101
+ }
102
+ /** Let a host deliver scheduled work when its timer or alarm fires. */
103
+ async deliverDue(options) {
104
+ const { signal, ...rest } = options ?? {};
105
+ const json = options === undefined ? undefined : optionsText(rest);
106
+ return JSON.parse(await this.#core.deliverDue(json, tokenFor(this.#module, signal)));
107
+ }
108
+ /** Give each chat, case, or workspace its own conversation while reusing the app’s agent definition. */
109
+ async agent(id, options) {
110
+ return wrapAgent(this.#module, await this.#core.agent(id, optionsText(options)));
111
+ }
112
+ /**
113
+ * Let an app button run a tool outside chat, such as generating an image for a form.
114
+ *
115
+ * App tools run outside every conversation. Recovery uses the same required id.
116
+ */
117
+ async runTool(name, args, options) {
118
+ const { signal, ...rest } = options;
119
+ return runToolResult(await this.#core.runTool(name, jsonText(args), optionsText(rest), tokenFor(this.#module, signal)));
120
+ }
121
+ /**
122
+ * Load a shared attachment when the user opens its preview.
123
+ *
124
+ * Read from Core at every access.
125
+ */
126
+ attachment(id) { return this.#core.attachment(id).then(JSON.parse); }
127
+ /** Let the user remove a shared attachment they no longer want to keep. */
128
+ deleteAttachment(id) { return this.#core.deleteAttachment(id); }
129
+ /** Populate a picker of attachments shared by this user’s agents, newest first, one page at a time. */
130
+ listAttachments(options) {
131
+ return this.#core.listAttachments(optionsText(options)).then(JSON.parse);
132
+ }
133
+ /**
134
+ * Set this user's allowance: the most credits the runtime lets this user spend per UTC day.
135
+ * Absolute, it replaces the earlier value; `null` returns the user to Studio's default. The runtime
136
+ * counts and enforces it from its own storage; Croche Cloud keeps no per-user ledger
137
+ * (founder 2026-11-21: «사용자 한도 안에서는 런타임이 보호하고.. (클라우드x»).
138
+ */
139
+ allowance = {
140
+ /** Set the user's absolute UTC-day limit in credits. Pass null to use Studio's default. */
141
+ set: async (limit) => { await this.#core.allowanceSet(jsonText(limit)); },
142
+ };
143
+ /**
144
+ * Let the app show how Croche Cloud verified this installation, or explain a withheld key.
145
+ *
146
+ * Read-only, from stored registration state; it never calls Cloud.
147
+ */
148
+ async verification() { return JSON.parse(await this.#core.verification()); }
149
+ /** Access the project's wiki documents available to this user. */
150
+ wiki = {
151
+ /** Make an updated help article available to agents in the current app session. */
152
+ put: (doc) => this.#core.wikiPut(jsonText(doc)),
153
+ /** Stop agents from using a help article the app has withdrawn. */
154
+ remove: (path) => this.#core.wikiRemove(path),
155
+ /** Show which help articles the app has made available to its agents. */
156
+ list: async (options) => JSON.parse(await this.#core.wikiList(optionsText(options))),
157
+ };
158
+ /** Access debugger controls for this session. */
159
+ debugger = {
160
+ attach: async (options) => {
161
+ const answer = await this.#core.debugAttach(jsonText(options));
162
+ return JSON.parse(answer);
163
+ },
164
+ detach: () => this.#core.debugDetach(),
165
+ };
166
+ /**
167
+ * Release the user’s session when they sign out or the app switches accounts.
168
+ *
169
+ * Resolves once new work has stopped; Core continues the bounded final delivery.
170
+ */
171
+ close() { return this.#core.shutdown(); }
172
+ }
@@ -0,0 +1,33 @@
1
+ import type { ErrorCategory } from './generated/app-stream.js';
2
+ export type { ErrorCategory } from './generated/app-stream.js';
3
+ /** A structured failure reported by Core or the SDK. */
4
+ export declare class CrocheError extends Error {
5
+ /** Machine-readable error code. */
6
+ readonly code: string;
7
+ /** Group used to decide how the app should handle the error. */
8
+ readonly category: ErrorCategory;
9
+ /** Suggested retry delay in seconds, when supplied. */
10
+ readonly retryAfter?: number;
11
+ /** Create an error with a code, human-readable message, category and optional retry delay. */
12
+ constructor(code: string, message: string, category: ErrorCategory, retryAfter?: number);
13
+ }
14
+ /** A PAL effect's failure, as a fact for Core: a code and a message, no category, no policy. */
15
+ export declare class HostError extends Error {
16
+ readonly code: string;
17
+ constructor(code: string, message: string, options?: ErrorOptions);
18
+ }
19
+ /** A thrown value's own string fields (name, message, code), read once; a throwing getter or a non-string reads as
20
+ * absent, and a thrown string is its message. Facts for Core, never interpreted here. */
21
+ export declare function thrownFacts(error: unknown): {
22
+ name?: string;
23
+ message?: string;
24
+ code?: string;
25
+ };
26
+ /** A tool's thrown value as the S1 completion carries it: `{type: name, message}` when the thrown value has both as
27
+ * strings, otherwise undefined (omitted). No code. */
28
+ export declare function thrownError(error: unknown): {
29
+ type: string;
30
+ message: string;
31
+ } | undefined;
32
+ /** Core's error (code, message, category, path?) as the app's CrocheError; anything else passes unchanged. */
33
+ export declare function coreFailure(error: unknown): unknown;
@@ -0,0 +1,63 @@
1
+ // 0.6 App API error (docs/APP-API.md). Core supplies `code` and `category` for its own errors and the port rejects
2
+ // with them unchanged. The SDK builds one itself only where nothing reached Core: a value that is not JSON
3
+ // (json.ts), a Core that cannot load (core/wasm.ts), a registration that is not a tool definition (croche.ts),
4
+ // or an unsupported JS host (index.unsupported.ts).
5
+ // An SDK-shipped effect (HTTP, codec, assets) that fails throws a HostError with a code from that effect's closed list;
6
+ // Core validates it and picks the category. A storage primitive that fails throws a plain Error: Core reports
7
+ // storage_error (ARCHITECTURE #837).
8
+ /** A structured failure reported by Core or the SDK. */
9
+ export class CrocheError extends Error {
10
+ /** Machine-readable error code. */
11
+ code;
12
+ /** Group used to decide how the app should handle the error. */
13
+ category;
14
+ /** Create an error with a code, human-readable message, category and optional retry delay. */
15
+ constructor(code, message, category, retryAfter) {
16
+ super(message);
17
+ this.name = 'CrocheError';
18
+ this.code = code;
19
+ this.category = category;
20
+ if (retryAfter !== undefined)
21
+ this.retryAfter = retryAfter;
22
+ }
23
+ }
24
+ /** A PAL effect's failure, as a fact for Core: a code and a message, no category, no policy. */
25
+ export class HostError extends Error {
26
+ code;
27
+ constructor(code, message, options) {
28
+ super(message, options);
29
+ this.name = 'HostError';
30
+ this.code = code;
31
+ }
32
+ }
33
+ /** A thrown value's own string fields (name, message, code), read once; a throwing getter or a non-string reads as
34
+ * absent, and a thrown string is its message. Facts for Core, never interpreted here. */
35
+ export function thrownFacts(error) {
36
+ const text = (key) => {
37
+ try {
38
+ const value = (typeof error === 'object' || typeof error === 'function') && error !== null ? error[key] : undefined;
39
+ return typeof value === 'string' ? value : undefined;
40
+ }
41
+ catch {
42
+ return undefined;
43
+ }
44
+ };
45
+ return { name: text('name'), message: typeof error === 'string' ? error : text('message'), code: text('code') };
46
+ }
47
+ /** A tool's thrown value as the S1 completion carries it: `{type: name, message}` when the thrown value has both as
48
+ * strings, otherwise undefined (omitted). No code. */
49
+ export function thrownError(error) {
50
+ const { name, message } = thrownFacts(error);
51
+ if (typeof name !== 'string' || typeof error === 'string' || typeof message !== 'string')
52
+ return undefined;
53
+ return { type: name, message };
54
+ }
55
+ /** Core's error (code, message, category, path?) as the app's CrocheError; anything else passes unchanged. */
56
+ export function coreFailure(error) {
57
+ if (error instanceof CrocheError || typeof error !== 'object' || error === null)
58
+ return error;
59
+ const { code, message, category, retryAfter } = error;
60
+ if (typeof code !== 'string' || typeof category !== 'string')
61
+ return error;
62
+ return new CrocheError(code, typeof message === 'string' ? message : code, category, retryAfter);
63
+ }
@@ -0,0 +1,5 @@
1
+ import type { CoreEventSink } from './core/port.js';
2
+ import type { Json } from './app-api.js';
3
+ /** `decode` is the GENERATED reader (decodeAgentEvent: a type this SDK does not know becomes the #828 `unknown`
4
+ * member); a sink without one passes Core's JSON through unchanged. */
5
+ export declare function eventSink<E>(handler: (event: E) => unknown, decode?: (value: Json) => E): CoreEventSink;
@@ -0,0 +1,31 @@
1
+ import { thrownFacts } from './errors.js';
2
+ function threw(error) {
3
+ return { outcome: 'threw', error: thrownFacts(error) };
4
+ }
5
+ function complete(delivery, outcome) {
6
+ delivery.complete(JSON.stringify(outcome));
7
+ }
8
+ /** `decode` is the GENERATED reader (decodeAgentEvent: a type this SDK does not know becomes the #828 `unknown`
9
+ * member); a sink without one passes Core's JSON through unchanged. */
10
+ export function eventSink(handler, decode = value => value) {
11
+ return (_deliveryId, eventJson, delivery) => {
12
+ const event = decode(JSON.parse(eventJson));
13
+ if (!delivery.tryEnter())
14
+ return; // Core withdrew it (closed, replaced): never enter the handler
15
+ let returned;
16
+ try {
17
+ returned = handler(event);
18
+ }
19
+ catch (error) {
20
+ complete(delivery, threw(error));
21
+ return;
22
+ }
23
+ if (typeof returned?.then === 'function') {
24
+ // Finished = the thenable settled; a then() that throws is a rejection.
25
+ Promise.resolve(returned).then(() => complete(delivery, { outcome: 'returned' }), error => complete(delivery, threw(error)));
26
+ }
27
+ else {
28
+ complete(delivery, { outcome: 'returned' });
29
+ }
30
+ };
31
+ }
@@ -0,0 +1,328 @@
1
+ export type Json = null | boolean | number | string | Json[] | {
2
+ [key: string]: Json;
3
+ };
4
+ /** Status of an accepted input: `queued` or `seen`, then one terminal status. */
5
+ export type InputDisposition = "queued" | "seen" | "answered" | "no_reply" | "failed" | "cancelled" | (string & {});
6
+ /** Kind of an input's parts. */
7
+ export type InputKind = "user" | "app_event" | "app_state" | (string & {});
8
+ /** How an agent reply ended. */
9
+ export type MessageStatus = "completed" | "failed" | "cancelled" | "interrupted" | (string & {});
10
+ /** Whether the agent has work. */
11
+ export type AgentStatus = "idle" | "running" | "waiting" | (string & {});
12
+ /** Why a model call other than an ordinary reply call was made. */
13
+ export type TurnPurpose = "summary" | (string & {});
14
+ /** A memory operation the app can make. */
15
+ export type MemoryOp = "delete" | "clear" | "enabled" | (string & {});
16
+ /** Metadata of a stored image original that Core keeps for the app, a message or a tool call. */
17
+ export interface Attachment {
18
+ /** Core-assigned attachment id, used to read, copy, release or delete the original. */
19
+ id: string;
20
+ /** What the attachment is; Core currently stores only `image` (open string). */
21
+ kind: string;
22
+ /** Where the stored original came from, for example `tool` (produced by a tool call) or `app` (copied in by the app). */
23
+ origin: string;
24
+ /** Image media type of the stored original, for example `image/png`. */
25
+ mediaType: string;
26
+ /** Size of the stored original in bytes. */
27
+ bytes: number;
28
+ /** Lowercase hex SHA-256 of the stored original's bytes. */
29
+ sha256: string;
30
+ /** The original's pixel width, when Core reports it; absent otherwise. */
31
+ width?: number;
32
+ /** The original's pixel height, when Core reports it; absent otherwise. */
33
+ height?: number;
34
+ /** Description text supplied with the image; absent when none was given. */
35
+ alt?: string;
36
+ /** Id of the agent tool call that produced the original (the same id as `ToolEvent.id`); absent for originals not produced by a call. */
37
+ callId?: string;
38
+ /** Present only as `true` when the original is no longer stored at read time; the logged row itself is not changed. */
39
+ deleted?: true;
40
+ /** 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`. */
41
+ deletedReason?: string;
42
+ }
43
+ /** An error carried by an event or result, with the category that tells the app how to react. */
44
+ export interface EventError {
45
+ /** Error code, for example `store_full` or `interrupted`; a code outside the known table has category `internal`. */
46
+ code: string;
47
+ /** What the app does about the error. */
48
+ category: ErrorCategory;
49
+ /** Human-readable explanation of the error. */
50
+ message: string;
51
+ /** Integer seconds, present only on the hourly app-paid rate_limited refusal. */
52
+ retryAfter?: number;
53
+ }
54
+ /** An image that could not be viewed for one model call; the call continues with the image's id and description. */
55
+ export interface ViewError {
56
+ /** Id of the attachment whose view failed. */
57
+ attachmentId: string;
58
+ /** Error code for the failed view, for example `image_unsupported`. */
59
+ code: string;
60
+ /** What the app does about the error. */
61
+ category: ErrorCategory;
62
+ /** Human-readable explanation of why the view failed. */
63
+ message: string;
64
+ }
65
+ /** Returned when Core accepts a send: the input's id, its status at acceptance and where its events start in the stream. */
66
+ export interface SendReceipt {
67
+ /** Id of the accepted input. */
68
+ requestId: string;
69
+ /** 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. */
70
+ status: InputDisposition;
71
+ /** Stream sequence of the input's first event, or for a just-accepted input the position its events start from. */
72
+ seq: number;
73
+ /** Why the input failed; present when `status` is `failed`. */
74
+ error?: EventError;
75
+ }
76
+ /** The terminal result of an accepted `request`: the input's final status and the replies it caused. */
77
+ export interface RequestResult {
78
+ /** Id of the input this result is for. */
79
+ id: string;
80
+ /** The input's terminal status. */
81
+ status: InputDisposition;
82
+ /** The retained `message.end` events whose `causedBy` includes this input. */
83
+ messages: Array<MessageEnd>;
84
+ /** Present only as `true` when some of this input's events were already pruned, so `messages` can be incomplete or empty. */
85
+ gap?: true;
86
+ /** Why the input failed; always present when `status` is `failed`. */
87
+ error?: EventError;
88
+ }
89
+ /** An input was accepted or its status changed; each change re-emits the input's full current state. */
90
+ export interface InputEvent {
91
+ type: 'input';
92
+ /** Id of the input. */
93
+ id: string;
94
+ /** Stream sequence of this event. */
95
+ seq: number;
96
+ /** Stream sequence of this input's first event; the same on every update of the input. */
97
+ firstSeq: number;
98
+ /** Which kind of input parts this row shows. */
99
+ kind: InputKind;
100
+ /** The input's status after this change. */
101
+ status: InputDisposition;
102
+ /** ISO 8601 time of this change. */
103
+ at: string;
104
+ /** Text of the input's parts of this `kind`, joined with blank lines; absent when Core holds no summary for the input. */
105
+ text?: string;
106
+ /** Why the input failed; always present when `status` is `failed` and absent otherwise. */
107
+ error?: EventError;
108
+ }
109
+ /** A held send left without running; Core emits it after reopen for a send that was held when the app stopped. */
110
+ export interface InputDropped {
111
+ type: 'input.dropped';
112
+ /** Id of the dropped input. */
113
+ inputId: string;
114
+ /** Why the input was dropped; Core's stream emits `reopened` (open string). */
115
+ reason: string;
116
+ /** Stream sequence of this event. */
117
+ seq: number;
118
+ /** Stream sequence of the input's first event when it had one, otherwise this event's own sequence. */
119
+ firstSeq: number;
120
+ }
121
+ /** An agent reply began; Core emits it when the reply has its first visible text, before any of its deltas. */
122
+ export interface MessageStart {
123
+ type: 'message.start';
124
+ /** Id of the reply message, shared by its start, deltas and end. */
125
+ id: string;
126
+ /** Stream sequence of this event. */
127
+ seq: number;
128
+ /** Stream sequence of the message's first event, which is this start. */
129
+ firstSeq: number;
130
+ /** ISO 8601 time the reply started. */
131
+ at: string;
132
+ }
133
+ /** New text of the open reply as it is written; a preview only, since `message.end` carries the stored text. */
134
+ export interface MessageDelta {
135
+ type: 'message.delta';
136
+ /** Id of the open reply message. */
137
+ id: string;
138
+ /** Text added to the reply since the previous delta. */
139
+ text: string;
140
+ }
141
+ /** The end of an agent reply with its stored text and final status; never rewritten. */
142
+ export interface MessageEnd {
143
+ type: 'message.end';
144
+ /** Id of the reply message. */
145
+ id: string;
146
+ /** Stream sequence of this event. */
147
+ seq: number;
148
+ /** Stream sequence of the message's first event (its `message.start`). */
149
+ firstSeq: number;
150
+ /** ISO 8601 time the reply ended. */
151
+ at: string;
152
+ /** How the reply ended. */
153
+ status: MessageStatus;
154
+ /** The stored reply text with markers removed; empty after an interruption or when the reply was too large to store. */
155
+ text: string;
156
+ /** Names of the registered markers found in the reply, in reply order. */
157
+ markers: Array<string>;
158
+ /** Ids of the inputs the turn producing this reply worked for. */
159
+ causedBy: Array<string>;
160
+ /** Ids of the inputs this reply answered; only a `completed` reply answers inputs, so it is empty otherwise. */
161
+ inReplyTo: Array<string>;
162
+ /** The reply before marker removal; equal to `text` when markers did not change it. */
163
+ raw: string;
164
+ /** The checked structured-output value of a reply made with a response format; absent otherwise. */
165
+ output?: Json;
166
+ /** Why the reply did not complete; always present when `status` is `failed`. */
167
+ error?: EventError;
168
+ /** Originals attached to this reply; absent when there are none. */
169
+ attachments?: Array<Attachment>;
170
+ }
171
+ /** One model call was recorded, with its usage, cost and model; Core writes it when it records the call's cost. */
172
+ export interface TurnEvent {
173
+ type: 'turn';
174
+ /** Opaque id of the model call; do not parse it. */
175
+ id: string;
176
+ /** Ids of the inputs first seen by this call. */
177
+ inputs: Array<string>;
178
+ /** Ids of every input this call worked for. */
179
+ causedBy: Array<string>;
180
+ /** Token counts reported for the call (`prompt`, `completion`, `total`, `cached`, `cacheWrite`, `reasoning` when reported), or null when none were reported. */
181
+ usage: Json;
182
+ /** Cost of the call in credits; null when unknown. */
183
+ cost: number | null;
184
+ /** How final `cost` is, for example `reported` (final), `unknown` (null cost), `estimated` (provisional) or `none` (zero cost). */
185
+ costStatus: string;
186
+ /** The model recorded for the call; the requested model when no response named one. */
187
+ model: string;
188
+ /** ISO 8601 time the call was recorded. */
189
+ at: string;
190
+ /** `summary` when the call made a context summary; absent for an ordinary model call. */
191
+ purpose?: TurnPurpose;
192
+ /** Reported serving-provider label; absent when unavailable. Diagnostic only; never changes pricing or settlement. */
193
+ provider?: string;
194
+ /** Images whose view failed; the call continues with their id and description. */
195
+ viewErrors?: Array<ViewError>;
196
+ }
197
+ /** An agent tool call started or changed status; updates keep the same id and `firstSeq`. */
198
+ export interface ToolEvent {
199
+ type: 'tool';
200
+ /** Opaque Core-assigned call id, the same as `ToolContext.callId` and an attachment's `callId`; do not parse it. */
201
+ id: string;
202
+ /** Stream sequence of this event. */
203
+ seq: number;
204
+ /** Stream sequence of the call's first event; the same on every update of the call. */
205
+ firstSeq: number;
206
+ /** Who made the call; Core emits `agent` for these events (open string). */
207
+ origin: string;
208
+ /** Ids of the inputs the call works for. */
209
+ causedBy: Array<string>;
210
+ /** Name of the called tool. */
211
+ tool: string;
212
+ /** Stable command key of the called command. */
213
+ key: string;
214
+ /** Arguments of the call, without app-bound arguments; `{}` when there are none. */
215
+ args: Json;
216
+ /** Status of the call: `running`, `waiting` (its result arrives later), `completed`, `failed`, `cancelled` or `unused` (a late result whose cause was cancelled) (open string). */
217
+ status: string;
218
+ /** Cost of the call in credits; null while running or when unknown, 0 for an unpaid call. */
219
+ cost: number | null;
220
+ /** How final `cost` is, for example `unknown` while running, `reported`, or `none` for an unpaid call. */
221
+ costStatus: string;
222
+ /** ISO 8601 time the call started. */
223
+ startedAt: string;
224
+ /** ISO 8601 time of this update. */
225
+ at: string;
226
+ /** Id of the `turn` event for the model call that requested this tool call; absent when not recorded. */
227
+ requestedBy?: string;
228
+ /** 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. */
229
+ delivered?: Json;
230
+ /** Originals the call kept as attachments, as `{attachments: [{id, mediaType, bytes}]}`; absent when none. */
231
+ outputs?: Json;
232
+ }
233
+ /** The agent's current state: status, queue length, typing, and what running work is doing. */
234
+ export interface StateEvent {
235
+ type: 'state';
236
+ /** Whether the agent is idle, running or waiting. */
237
+ status: AgentStatus;
238
+ /** Number of accepted sends waiting in the queue. */
239
+ queued: number;
240
+ /** True while a reply's `message.start` is written and its `message.end` is not. */
241
+ typing: boolean;
242
+ /** What running work is doing, for example `model`, `summary` or `tool`; null unless `status` is `running`. */
243
+ activity: string | null;
244
+ /** 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`. */
245
+ tools?: Array<string>;
246
+ }
247
+ /** The subscription's starting point: the current log, state and the reply being streamed; delivered first on attach. */
248
+ export interface SnapshotEvent {
249
+ type: 'snapshot';
250
+ /** Id of the log the subscription reads; pass it back with a `seq` to resume. */
251
+ logId: string;
252
+ /** The current `state` event. */
253
+ state: Json;
254
+ /** The reply being streamed now as `{messageId, firstSeq, text}`, or null when none. */
255
+ streaming: Json;
256
+ }
257
+ /** An older page of the conversation, delivered after `subscription.history()`. */
258
+ export interface PageEvent {
259
+ type: 'page';
260
+ /** The page's rows oldest first, each as its latest event. */
261
+ messages: Array<AgentEvent>;
262
+ /** True when no older retained row was left out of this page. */
263
+ reachedFloor: boolean;
264
+ /** Id of the log the page was read from. */
265
+ logId: string;
266
+ /** Stream sequence of the latest history clear, or 0 when there was none. */
267
+ clearedSeq: number;
268
+ }
269
+ /** A full `clearHistory()` took effect; empty the displayed conversation. */
270
+ export interface ClearedEvent {
271
+ type: 'cleared';
272
+ /** Core-assigned id of this clear. */
273
+ id: string;
274
+ /** ISO 8601 time the clear took effect. */
275
+ at: string;
276
+ }
277
+ /** A memory delete, clear or enable change took effect. */
278
+ export interface MemoryEvent {
279
+ type: 'memory';
280
+ /** Core-assigned id of the memory operation. */
281
+ id: string;
282
+ /** Which memory operation took effect. */
283
+ op: MemoryOp;
284
+ /** ISO 8601 time the operation took effect. */
285
+ at: string;
286
+ /** Id of the deleted memory fact; present only for `delete`. */
287
+ item?: string;
288
+ /** The new memory setting; present only for `enabled`. */
289
+ enabled?: boolean;
290
+ /** Number of memory facts removed; present for `delete` and `clear`. */
291
+ removed?: number;
292
+ }
293
+ /** Events were missed; redraw from a `page`. */
294
+ export interface GapEvent {
295
+ type: 'gap';
296
+ /** Last stream sequence before the missed range. */
297
+ afterSeq: number;
298
+ /** Last missed stream sequence (inclusive). */
299
+ throughSeq: number;
300
+ /** Why the events are missing: `limit` (retention pruned them) or `cleared` (a history clear removed them). */
301
+ reason: string;
302
+ }
303
+ /** The subscription ended with an error; it receives no further events. */
304
+ export interface SubscriptionError {
305
+ type: 'error';
306
+ /** Error code, for example `storage_error`. */
307
+ code: string;
308
+ /** Human-readable explanation of the error. */
309
+ message: string;
310
+ /** Present only as `true` when a storage failure stopped the agent from writing; reopen to continue. */
311
+ poisoned?: boolean;
312
+ }
313
+ /** The subscription ended because a newer subscription replaced it. */
314
+ export interface ReplacedEvent {
315
+ type: 'replaced';
316
+ }
317
+ export type AgentEvent = InputEvent | InputDropped | MessageStart | MessageDelta | MessageEnd | TurnEvent | ToolEvent | StateEvent | SnapshotEvent | PageEvent | ClearedEvent | MemoryEvent | GapEvent | SubscriptionError | ReplacedEvent | {
318
+ type: 'unknown';
319
+ originalType: string;
320
+ fields: Json;
321
+ };
322
+ /** What the app does about an error. A code outside Core's table has category `internal`. */
323
+ export type ErrorCategory = 'offline' | 'allowance' | 'paused' | 'setup' | 'closed' | 'invalid' | 'internal';
324
+ export type JsonRepresentationErrorCode = "invalid_configuration" | "invalid_input" | "invalid_tool_result";
325
+ export declare const jsonRepresentationErrorCategories: Readonly<Record<JsonRepresentationErrorCode, ErrorCategory>>;
326
+ export declare const errorCategories: Readonly<Record<string, ErrorCategory>>;
327
+ export declare function errorCategory(code: string): ErrorCategory;
328
+ export declare function decodeAgentEvent(value: Json): AgentEvent;