@h1r-ai/croche-react-native 0.5.4 → 0.6.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 (196) hide show
  1. package/README.md +69 -458
  2. package/THIRD-PARTY-NOTICES +7 -8
  3. package/android/build.gradle +6 -1
  4. package/android/src/androidTest/java/dev/croche/reactnative/WikiFileBridgeTest.kt +125 -0
  5. package/android/src/main/java/dev/croche/reactnative/CoreDispatch.kt +81 -0
  6. package/android/src/main/java/dev/croche/reactnative/CoreWire.kt +83 -0
  7. package/android/src/main/java/dev/croche/reactnative/CrocheRuntimeModule.kt +45 -824
  8. package/android/src/main/java/dev/croche/reactnative/NativePal.kt +51 -0
  9. package/android/src/main/java/dev/croche/reactnative/RNHostPal.kt +9 -0
  10. package/android/src/test/java/dev/croche/reactnative/AgentMemoryTest.kt +42 -41
  11. package/android/src/test/java/dev/croche/reactnative/BackgroundDelegationTest.kt +71 -0
  12. package/android/src/test/java/dev/croche/reactnative/OpenForwardingFixture.kt +29 -0
  13. package/android/src/test/java/dev/croche/reactnative/ProjectAttestationTest.kt +19 -32
  14. package/android/src/test/java/dev/croche/reactnative/ProjectHandlerStagesTest.kt +32 -0
  15. package/android/src/test/java/dev/croche/reactnative/ProjectRecoveryTest.kt +12 -0
  16. package/android/src/test/java/dev/croche/reactnative/ProjectTimeZoneTest.kt +11 -15
  17. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/AndroidEventSink.kt +27 -0
  18. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/AndroidPlatform.kt +6 -6
  19. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BackgroundRegistration.kt +16 -0
  20. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BackgroundWakeWorker.kt +51 -0
  21. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapDecodedImageCodec.kt +162 -0
  22. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapImageInput.kt +15 -0
  23. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapOrientation.kt +40 -0
  24. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapPalCodec.kt +66 -0
  25. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/WorkManagerScheduler.kt +8 -8
  26. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidAssetPal.kt +30 -0
  27. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidCoreFactory.kt +35 -0
  28. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidCoreHost.kt +121 -0
  29. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidMainDispatcher.kt +17 -0
  30. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidPublicPlatform.kt +17 -0
  31. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidS2Pal.kt +14 -0
  32. package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidStoragePal.kt +73 -0
  33. package/android/vendor/CrocheRuntimeSDK/consumer-rules.pro +9 -0
  34. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/AppStreamBranch.kt +5 -2
  35. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/BindingFacts.kt +29 -0
  36. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ContextConfig.kt +45 -0
  37. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Core.kt +16 -1
  38. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Croche.kt +60 -105
  39. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheAgent.kt +47 -107
  40. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheRuntime.kt +41 -40
  41. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheTools.kt +67 -0
  42. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/DecodedImageCodec.kt +20 -0
  43. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Effects.kt +18 -20
  44. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/GeneratedAppStream.kt +322 -0
  45. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Host.kt +71 -34
  46. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ImagePal.kt +183 -0
  47. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Images.kt +9 -7
  48. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/NativeCoreStreamPort.kt +47 -19
  49. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Platform.kt +5 -5
  50. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectPalRouting.kt +1 -1
  51. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectRecords.kt +9 -9
  52. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectTypes.kt +108 -37
  53. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/PublicResults.kt +44 -0
  54. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ReaderValues.kt +73 -0
  55. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/RunTool.kt +40 -0
  56. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/SendEncoding.kt +23 -21
  57. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Storage.kt +8 -8
  58. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/StoragePal.kt +18 -0
  59. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/StreamHub.kt +50 -25
  60. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/SubscriptionTypes.kt +22 -22
  61. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ffi/croche_ffi.kt +8285 -2159
  62. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/AppEventSink.kt +34 -0
  63. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/AppStoragePal.kt +25 -0
  64. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/BackgroundOsRegistration.kt +35 -0
  65. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/BackgroundSink.kt +37 -0
  66. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreDefinitionCalls.kt +35 -0
  67. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreFactoryCalls.kt +31 -0
  68. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreOptionsEncoding.kt +41 -0
  69. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreStreamCalls.kt +35 -0
  70. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/ForeignCallbacks.kt +128 -0
  71. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/JvmCoreHost.kt +72 -0
  72. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/JvmStoragePal.kt +34 -0
  73. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/LifecycleBinding.kt +18 -0
  74. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/NativePlatform.kt +45 -0
  75. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/PalCallbacks.kt +27 -0
  76. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/PlainToolJson.kt +56 -0
  77. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/PublicCalls.kt +34 -0
  78. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/ScopeJson.kt +29 -0
  79. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/ToolCompletionEncoding.kt +29 -0
  80. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/AtomicKeyFiles.kt +79 -0
  81. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/DirectHttpPal.kt +223 -0
  82. package/android/vendor/jniLibs/arm64-v8a/libcroche_ffi.so +0 -0
  83. package/android/vendor/jniLibs/armeabi-v7a/libcroche_ffi.so +0 -0
  84. package/android/vendor/jniLibs/x86_64/libcroche_ffi.so +0 -0
  85. package/dist/package.json +1 -0
  86. package/dist/react-native/src/NativeCrocheRuntime.d.ts +16 -0
  87. package/dist/react-native/src/NativeCrocheRuntime.js +2 -0
  88. package/dist/react-native/src/core-native.d.ts +3 -0
  89. package/dist/react-native/src/core-native.js +193 -0
  90. package/dist/react-native/src/core-wire.d.ts +38 -0
  91. package/dist/react-native/src/core-wire.js +1 -0
  92. package/dist/react-native/src/native-module.d.ts +8 -0
  93. package/dist/react-native/src/native-module.js +53 -0
  94. package/dist/rn-shared-build.json +16 -0
  95. package/dist/runtime/src/agent.d.ts +43 -0
  96. package/dist/runtime/src/agent.js +75 -0
  97. package/dist/runtime/src/app-api.d.ts +284 -0
  98. package/dist/runtime/src/app-api.js +1 -0
  99. package/dist/runtime/src/cancel.d.ts +9 -0
  100. package/dist/runtime/src/cancel.js +24 -0
  101. package/dist/runtime/src/core/port.d.ts +234 -0
  102. package/dist/runtime/src/core/port.js +1 -0
  103. package/dist/runtime/src/core/wasm.d.ts +1 -0
  104. package/dist/runtime/src/core/wasm.js +2 -0
  105. package/dist/runtime/src/croche.d.ts +42 -0
  106. package/dist/runtime/src/croche.js +111 -0
  107. package/dist/runtime/src/errors.d.ts +26 -0
  108. package/dist/runtime/src/errors.js +49 -0
  109. package/dist/runtime/src/events.d.ts +5 -0
  110. package/dist/runtime/src/events.js +31 -0
  111. package/dist/runtime/src/generated/app-stream.d.ts +174 -0
  112. package/dist/runtime/src/generated/app-stream.js +124 -0
  113. package/dist/runtime/src/index.native.d.ts +21 -0
  114. package/dist/runtime/src/index.native.js +8 -0
  115. package/dist/runtime/src/json.d.ts +13 -0
  116. package/dist/runtime/src/json.js +120 -0
  117. package/dist/runtime/src/native-adapter.d.ts +3 -0
  118. package/dist/runtime/src/native-adapter.js +24 -0
  119. package/dist/runtime/src/pal/codec.d.ts +15 -0
  120. package/dist/runtime/src/pal/codec.js +52 -0
  121. package/dist/runtime/src/pal/host.d.ts +5 -0
  122. package/dist/runtime/src/pal/host.js +35 -0
  123. package/dist/runtime/src/pal/platform.d.ts +16 -0
  124. package/dist/runtime/src/pal/platform.js +7 -0
  125. package/dist/runtime/src/rn-entry.d.ts +1 -0
  126. package/dist/runtime/src/rn-entry.js +4 -0
  127. package/dist/runtime/src/run-tool.d.ts +33 -0
  128. package/dist/runtime/src/run-tool.js +7 -0
  129. package/dist/runtime/src/tools.d.ts +19 -0
  130. package/dist/runtime/src/tools.js +70 -0
  131. package/ios/CoreAgentTransport.swift +14 -0
  132. package/ios/CoreDeliveryTransport.swift +58 -0
  133. package/ios/CoreNativePal.swift +93 -0
  134. package/ios/CorePlatformTransport.swift +44 -0
  135. package/ios/CoreWireDispatch.swift +92 -0
  136. package/ios/CoreWireSupport.swift +111 -0
  137. package/ios/CrocheRuntimeBridge.swift +34 -994
  138. package/ios/ProjectPal.swift +46 -0
  139. package/ios/RNCrocheRuntime.mm +18 -201
  140. package/ios/vendor/CrocheRuntimeSDK/AppBuildFacts.swift +112 -0
  141. package/ios/vendor/CrocheRuntimeSDK/Background.swift +11 -11
  142. package/ios/vendor/CrocheRuntimeSDK/ContextConfig.swift +64 -0
  143. package/ios/vendor/CrocheRuntimeSDK/DirectHTTP.swift +258 -0
  144. package/ios/vendor/CrocheRuntimeSDK/Effects.swift +17 -17
  145. package/ios/vendor/CrocheRuntimeSDK/FFIStreamPort.swift +85 -43
  146. package/ios/vendor/CrocheRuntimeSDK/GeneratedAppStream.swift +443 -0
  147. package/ios/vendor/CrocheRuntimeSDK/Host.swift +122 -61
  148. package/ios/vendor/CrocheRuntimeSDK/ImagePal.swift +410 -0
  149. package/ios/vendor/CrocheRuntimeSDK/Images.swift +10 -9
  150. package/ios/vendor/CrocheRuntimeSDK/JSON.swift +4 -4
  151. package/ios/vendor/CrocheRuntimeSDK/Offload.swift +24 -0
  152. package/ios/vendor/CrocheRuntimeSDK/OpenOptions.swift +37 -36
  153. package/ios/vendor/CrocheRuntimeSDK/Platform.swift +35 -35
  154. package/ios/vendor/CrocheRuntimeSDK/PlatformBackground.swift +285 -0
  155. package/ios/vendor/CrocheRuntimeSDK/PlatformPal.swift +266 -0
  156. package/ios/vendor/CrocheRuntimeSDK/PlatformStorage.swift +195 -0
  157. package/ios/vendor/CrocheRuntimeSDK/Project.swift +209 -95
  158. package/ios/vendor/CrocheRuntimeSDK/Runtime.swift +97 -123
  159. package/ios/vendor/CrocheRuntimeSDK/S1/S1Agent.swift +195 -0
  160. package/ios/vendor/CrocheRuntimeSDK/S1/S1BindingFacts.swift +33 -0
  161. package/ios/vendor/CrocheRuntimeSDK/S1/S1Core.swift +161 -0
  162. package/ios/vendor/CrocheRuntimeSDK/S1/S1Croche.swift +234 -0
  163. package/ios/vendor/CrocheRuntimeSDK/S1/S1Events.swift +28 -0
  164. package/ios/vendor/CrocheRuntimeSDK/S1/S1Options.swift +177 -0
  165. package/ios/vendor/CrocheRuntimeSDK/S1/S1RunTool.swift +61 -0
  166. package/ios/vendor/CrocheRuntimeSDK/S1/S1Storage.swift +95 -0
  167. package/ios/vendor/CrocheRuntimeSDK/S1/S1TestHooks.swift +105 -0
  168. package/ios/vendor/CrocheRuntimeSDK/S1/S1Tools.swift +209 -0
  169. package/ios/vendor/CrocheRuntimeSDK/Storage.swift +52 -52
  170. package/ios/vendor/CrocheRuntimeSDK/StreamHub.swift +180 -137
  171. package/ios/vendor/CrocheRuntimeSDK/SubscriptionRuntime.swift +16 -10
  172. package/ios/vendor/CrocheRuntimeSDK/SubscriptionTypes.swift +131 -116
  173. package/ios/vendor/CrocheRuntimeSDK/Truncate.swift +12 -0
  174. package/ios/vendor/CrocheRuntimeSDK/croche_ffi.swift +7209 -2803
  175. package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64/Headers/croche_ffiFFI.h +1342 -218
  176. package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64/libcroche_ffi.a +0 -0
  177. package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64_x86_64-simulator/Headers/croche_ffiFFI.h +1342 -218
  178. package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64_x86_64-simulator/libcroche_ffi.a +0 -0
  179. package/package.json +18 -8
  180. package/scripts/README.md +11 -0
  181. package/scripts/build-shared.mjs +46 -0
  182. package/scripts/build.mjs +11 -0
  183. package/scripts/vendor-native.sh +5 -4
  184. package/src/NativeCrocheRuntime.ts +12 -159
  185. package/android/src/main/java/dev/croche/reactnative/AgentMemory.kt +0 -25
  186. package/android/src/main/java/dev/croche/reactnative/ProjectAttestation.kt +0 -17
  187. package/android/src/main/java/dev/croche/reactnative/ProjectTimeZone.kt +0 -14
  188. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Control.kt +0 -178
  189. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectBinding.kt +0 -79
  190. package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectPlatform.kt +0 -46
  191. package/ios/vendor/CrocheRuntimeSDK/Control.swift +0 -192
  192. package/src/index.ts +0 -664
  193. package/src/project-types.ts +0 -35
  194. package/src/project.ts +0 -434
  195. package/src/protocol.ts +0 -28
  196. package/src/types.ts +0 -9
package/README.md CHANGED
@@ -1,501 +1,112 @@
1
1
  # @h1r-ai/croche-react-native
2
2
 
3
- ## App temperature (0.5.3)
4
-
5
- In `Croche.open({config: ...})`, `config.temperature` is a finite number 0–2.
6
- Absent uses a tuned default when no layer supplies it; `null` omits it (including an inherited
7
- value). For example: `config: {instructions: 'Be helpful.', temperature: null}`.
8
- Structured calls always omit temperature; summary calls keep their existing behavior.
9
- Remote config documents carrying it require schema 4 and SDK 0.5.3+; older apps
10
- keep compatible config instead. RN shares the TS project config type; this is not
11
- a new host option or native bridge field.
12
-
13
- Put an AI character or assistant into a React Native app, on iOS and Android, with **no
14
- backend of your own**. You write instructions and JavaScript tools. Croche runs the
15
- model and tool loop, streams replies, remembers across sessions, keeps per-user
16
- allowances, and calls the model provider directly with a key that Croche Cloud gives only
17
- to a genuine install of your app.
18
-
19
- The shared Rust Core makes every decision. On iOS it runs through the Swift SDK
20
- (`sdk/swift`) and on Android through the Kotlin SDK (`sdk/kotlin`). This package is a thin
21
- bridge, and its API has the same shape as `@h1r-ai/croche` on the web.
22
-
23
- ## Requirements
24
-
25
- - React Native 0.76 or later with the New Architecture (TurboModules). iOS 15.1+,
26
- Android API 26+.
27
- - Nothing else: the package carries the native Core. No Rust toolchain, no Croche checkout.
3
+ Croche for React Native on iOS and Android. It has the same app API as
4
+ `@h1r-ai/croche`: open a user session, choose a declared agent, send a message,
5
+ and receive its reply through a subscription.
28
6
 
29
7
  ## Install
30
8
 
31
- From npm:
9
+ React Native 0.76+ with the New Architecture, iOS15.1+ or Android API26+.
32
10
 
33
11
  ```sh
34
12
  npm install @h1r-ai/croche @h1r-ai/croche-react-native
35
13
  cd ios && pod install
36
14
  ```
37
15
 
38
- Install both npm packages together without version suffixes. Commit the project lockfile
39
- to record their resolved versions.
40
-
41
- `@h1r-ai/croche` is a peer dependency: this package shares its types, and the app holds
42
- exactly one copy. The React Native package contains the native Core: the iOS xcframework
43
- (`ios/vendor`) and the Android libraries for arm64-v8a, armeabi-v7a and x86_64
44
- (`android/vendor`). Android needs no further step.
45
-
46
- **Building the tarball (Croche contributors, on a Mac):** `npm run pack:rn` in the Croche
47
- repository builds the native Core into the package (`scripts/vendor-native.sh all`, which
48
- needs `rustup`, the iOS and Android targets, `cargo-ndk`, Xcode and an Android NDK) and packs
49
- it into `artifacts/`.
50
-
51
- ## Debug keys, simulators and devices
52
-
53
- An install receives a model key only after it proves it runs your app:
54
- - **Real iPhones and Android phones** prove it with App Attest / Play Integrity. The SDK
55
- does this automatically. Their usage is billed to the project's Runtime Credit.
56
- - **Simulators and emulators cannot.** Issue a **debug key** (`cdt_…`) in Croche
57
- Studio → Debug keys (`croche keys development list <project-id>` lists them), and
58
- pass it as `debugKey`. Development usage is billed to your
59
- weekly development allowance, never to Runtime Credit.
60
-
61
- A phone with a debug key still attests first; the key is only the fallback. A
62
- release build that carries a `debugKey` logs a loud warning: never ship one.
16
+ Commit your project's lockfile. The React Native package carries the native
17
+ libraries; apps do not need Rust or a Croche checkout.
63
18
 
64
19
  ## First conversation
65
20
 
66
- Open a **project** once per user, then its agent. Replies stream as events on a subscription.
67
-
68
- ```tsx
69
- import { Croche, type AgentEvent, type ToolHandler } from '@h1r-ai/croche-react-native';
70
-
71
- const inventory: ToolHandler = ({ key, args }) =>
72
- key === 'inventory_give' ? game.give(String(args.item)) : { items: game.items() };
73
-
74
- const croche = await Croche.open({
75
- projectKey: 'pk_…', // public; safe to ship
76
- debugKey: __DEV__ ? 'cdt_…' : undefined, // simulators and emulators only
77
- user: playerId,
78
- config: {
79
- instructions: 'You are Mara, the innkeeper of the Lantern Inn. Answer in one or two sentences.',
80
- tools: [{ name: 'inventory', summary: "The player's inventory", commands: [
81
- { key: 'inventory_give', name: 'give', summary: 'Give the player an item the player asks for.',
82
- flags: [{ name: 'item', type: 'string', enum: ['ale', 'bread', 'key'], required: true }] },
83
- { key: 'inventory_list', name: 'list', summary: 'List what the player carries.', reads: true },
84
- ] }],
85
- },
86
- handlers: { inventory },
87
- });
88
- const mara = await croche.agent();
89
-
90
- let shown = '';
91
- const subscription = mara.subscribe({ onEvent: (event: AgentEvent) => {
92
- if (event.type === 'message.start') shown = '';
93
- if (event.type === 'message.delta') setText(shown += String(event.text)); // provisional
94
- if (event.type === 'message.end') setText(shown = String(event.text)); // final
95
- } });
96
- await mara.send({ id: `msg-${Date.now()}`, text: 'Hello!' });
97
- // When the screen goes away: subscription.close(). When the app is done: await croche.close().
98
- ```
99
-
100
- `request(input)` instead resolves when that input is answered, with its messages. Several
101
- agents (`config.agents`, `croche.agent('helper')`) and the event list are in the
102
- `@h1r-ai/croche` reference, "Projects and agents". The API includes instances
103
- (`instance`, `fresh`) and project-level `Croche.deleteStore`.
104
-
105
- ## One agent without a project: `CrocheRuntime`
106
-
107
- `CrocheRuntime` is the same Core for a single agent, with its options flat. The rest of this
108
- page shows it; for project agents, its agent options are fields of `config`.
109
-
21
+ Create the project's bundled config in your app. Use a debug key for development;
22
+ keep it out of release builds. A real device uses the platform's attestation.
23
+ Development usage consumes your development allowance.
110
24
 
111
- ```tsx
112
- import { CrocheRuntime, type RuntimeEvent } from '@h1r-ai/croche-react-native';
113
-
114
- const runtime = await CrocheRuntime.create({
115
- projectKey: 'pk_…', // public; safe to ship
116
- debugKey: __DEV__ ? 'cdt_…' : undefined, // simulators and emulators only
117
- instructions: 'You are Mara, the innkeeper of the Lantern Inn. Answer in one or two sentences.',
118
- markerGuide: ':smile: warm; :wink: playful',
119
- });
120
-
121
- let shown = '';
122
- const result = await runtime.send(
123
- { id: `msg-${Date.now()}`, text: 'Hello!' },
124
- { onEvent: (event: RuntimeEvent) => {
125
- if (event.type === 'text.delta') setText(shown += event.text); // streams as the model writes
126
- if (event.type === 'marker') playAnimation(event.name); // :smile: never appears as text
127
- } },
128
- );
129
- setText(result.text); // authoritative: replace what you streamed
130
- if (result.status !== 'completed') showError(result.error?.code, result.error?.message);
25
+ ```ts
26
+ import {Croche} from '@h1r-ai/croche-react-native';
131
27
  ```
132
28
 
133
- Open one Runtime per character when the app starts, and close it when the app no longer
134
- needs it (`await runtime.close()`). Reopening with the same options restores the session,
135
- history and memory.
136
-
137
- ## Tools: let the character act
138
-
139
- The model sees one function and calls your commands through it. The Core validates every
140
- argument against your declaration before your code runs, and feeds rejections back to the
141
- model so it can correct itself.
142
-
29
+ <!-- snippet: packages/react-native/tests/readme-examples.ts#rn-recommended -->
143
30
  ```ts
144
- const runtime = await CrocheRuntime.create({
145
- // ...
146
- tools: [{
147
- name: 'inventory',
148
- summary: "The player's inventory",
149
- commands: [
150
- { key: 'inventory_give', name: 'give', summary: 'Give the player an item',
151
- positionals: [{ name: 'item', type: 'string', required: true, enum: ['ale', 'bread', 'key'] }] },
152
- { key: 'inventory_list', name: 'list', summary: 'List what the player carries' },
153
- ],
154
- async execute(invocation, context) {
155
- if (context.signal.aborted) return { status: 'cancelled' };
156
- if (invocation.key === 'inventory_give') return game.give(invocation.args.item);
157
- return { items: game.items() };
31
+ const croche = await Croche.open({
32
+ projectKey,
33
+ debugKey,
34
+ bundledConfig: {
35
+ schema: 7,
36
+ project: {
37
+ defaults: { model: 'deepseek/deepseek-v4.1-flash' },
38
+ languages: { default: 'en', supported: ['en'] },
158
39
  },
159
- }],
40
+ agents: { companion: { instructions: 'You are a brief, warm companion.' } },
41
+ },
160
42
  });
43
+ const agent = await croche.agent('companion');
44
+ const subscription = agent.subscribe({
45
+ onEvent: event => {
46
+ if (event.type === 'message.end') render(event.text ?? '');
47
+ },
48
+ });
49
+ await agent.send('Hello!');
161
50
  ```
162
51
 
163
- - Return what actually happened, as JSON. Return `{ status: 'rejected', reason }` for an
164
- outcome the model can correct; **throw** only when the effect's state is unknown (that
165
- ends the turn and is never retried automatically).
166
- - `context` carries `callId`, `messageId`, `userId`, `agentId`
167
- and an abort `signal`.
168
- - Tool results are data, never instructions to the model.
169
- - Return images beside the value with `toolResult(value, { images, imageResolution })`, as on
170
- the web: they cross the bridge beside the value, and the native SDK re-encodes standard ones
171
- (at most 512 px). A plain value is never looked inside. An invalid image list fails that call
172
- alone with `invalid_tool_result`, and the turn goes on. The runtime README has the rules.
173
-
174
- Change the tools while the Runtime is open, for example to unlock a room once the user earns
175
- it. The Core validates the new list at once, all or nothing: a refused list rejects and changes
176
- nothing. Turns already sent keep the old list; the next ones are offered the new one, and a
177
- removed command answers `withdrawn`. Await `setTools` before a send that must see the new list:
178
- the native bridges do not yet keep a send started meanwhile behind it.
179
-
180
- ```ts
181
- await runtime.setTools([inventory, room]); // the full new list, each with its execute
182
- runtime.tools(); // the metadata the model is offered now
183
- ```
184
-
185
- ## Several characters, or several roles
186
-
187
- Give each one an `agentId`. Each gets its own store, history and memory, and they can
188
- stream at the same time. Every one of them shares the installation's user and allowance.
189
-
190
- ```ts
191
- const mara = await CrocheRuntime.create({ ...common, agentId: 'mara', instructions: maraPersona });
192
- const pip = await CrocheRuntime.create({ ...common, agentId: 'pip', instructions: pipPersona });
193
- await Promise.all([mara.send({ id: 'a1', text: 'Hi' }), pip.send({ id: 'b1', text: 'Hi' })]);
194
- ```
195
-
196
- For roles inside one app (a planner and a critic), the app routes: pass one agent's
197
- result to another as an app event, `send({ id, text, kind: 'event' })`, or as trusted
198
- `context`.
52
+ An `app_state` text element is optional app state, separate from the person's words.
53
+ Send it when it changes or a request needs it; earlier states remain as sent
54
+ until folded. Tools must still check authoritative app data.
199
55
 
200
- ## App events and trusted context
201
-
202
- - `send({ id, text, kind: 'event' })` is a turn your app starts ("night fell", "the quest
203
- is complete"). It costs a model call like any turn.
204
- - `send({ id, text, context: { screen: 'cart', items: 3 } })` gives the model the current
205
- app state, kept apart from the person's words. It is useful when the request needs app
206
- state: a command or button acting on app data, or after that state changed. Without it,
207
- an input carries only the message; earlier states remain in history as sent until folded.
208
- They are not a live view of the app. Tools must check authoritative app data themselves.
209
-
210
- ## Documents the character can look up
211
-
212
- The wiki works as it does in `@h1r-ai/croche`, but every call returns a promise, because
213
- it crosses the bridge.
214
-
215
- - The character sees a catalog of paths and titles, and reads a document only when it
216
- needs it.
217
- - Put the documents in the app: a `wiki` folder reference in the iOS target, and
218
- `android/app/src/main/assets/wiki/` on Android. `wikiFromAppAssets()` reads them.
219
- - `include`/`exclude` choose which documents this character sees.
56
+ `send` returns an acceptance receipt. The subscription delivers the reply.
57
+ For a collected result, use `request` instead:
220
58
 
59
+ <!-- snippet: packages/react-native/tests/readme-examples.ts#rn-simple -->
221
60
  ```ts
222
- import { CrocheRuntime, wikiFromAppAssets } from '@h1r-ai/croche-react-native';
223
-
224
- const runtime = await CrocheRuntime.create({
225
- ...options,
226
- wiki: { docs: await wikiFromAppAssets(), exclude: ['staff/**'] },
227
- });
228
- const page = await runtime.wiki.read('menu/stew.md');
229
- // The user's own documents live under user/ and are stored with their state.
230
- await runtime.wiki.put({ path: 'user/notes/recipe.md', markdown, scope: 'user' });
231
- await CrocheRuntime.shareWiki([mara, pip], { path: 'user/quest.md', markdown });
61
+ const answer=await agent.request('Hello!');
62
+ for(const message of answer.messages)render(message.text??'');
232
63
  ```
233
64
 
234
- `set`, `put`, `remove`, `clear({ scope: 'user' })`, `list`, `read` and `search` take the
235
- same arguments as on the web.
236
-
237
- **Not yet verified:** the native wiki bridge (iOS and Android) has not been compiled or
238
- run. The JavaScript layer is tested against the real Core through `tests/mock-native.ts`.
239
-
240
- ## Language selection
241
-
242
- Set the project's default in `config.defaultLanguage` (default `"en"`). The
243
- `language` option on `Croche.open()` is the current user's language. **This SDK does
244
- not yet supply the device locale when none is given** (#587); pass it yourself. Core
245
- selects the app's matching language configuration or its default, never from user text.
246
- The model is not told the language: a reply's language follows your instructions and the
247
- user's own message.
248
- The old host `defaultLanguage` option is removed and refused by name, including
249
- on legacy `CrocheRuntime.create()`; it is not a second configuration source.
250
-
251
- ## What the character remembers
252
-
253
- A project agent opened with `Croche.open()` → `croche.agent()` exposes the same `agent.memory` API as `CrocheRuntime.memory`, with asynchronous native operations.
65
+ ## App tools
254
66
 
255
- Only the model writes memories, using `memory save` and `memory replace`. Core assigns
256
- monotonic ids per person and agent, and keeps the newest 2,000 current and replaced facts.
257
- The app reads and deletes them; calls return promises because they cross the bridge:
67
+ Register a definition at open, and select registered tools for each agent.
68
+ Bound values stay out of the model-facing description. Return a branded
69
+ `toolResult` when supplying structured tool content.
258
70
 
259
71
  ```ts
260
- const items = await runtime.memory.list(); // id, text, turnN, refs, replacement links
261
- await runtime.memory.delete('m2'); // that fact and its earlier versions
262
- await runtime.memory.clear(); // memories only, not the conversation summary
263
- await runtime.memory.enabled(false); // this person turned memory off
264
- const all = await runtime.memory.export(); // AI-written facts, never the summary
265
- await runtime.memory.onChanged(e => refresh(e.id)); // at-most-once durable-change hint
266
- runtime.memory(); // snapshot as of the last call
72
+ import {defineTool,toolResult} from '@h1r-ai/croche-react-native';
267
73
  ```
268
74
 
269
- `memory.list()` is the source of truth; a crash after persistence can lose a change hint.
270
- `memory.delete(id)` removes that memory and its earlier versions; `memory.clear()` removes
271
- every memory. The summary of earlier conversation is part of the conversation, not memory:
272
- `clearHistory()` or `Croche.deleteStore()` removes it. Kept turns and the turn archive are
273
- not rewritten by memory deletes. App facts belong in app state or instructions, not `set()`.
274
-
275
- A nonempty legacy keyed/text memory store is refused before writes with
276
- `memory_store_too_old`: `croche.agent(id)` rejects with that `CrocheError` code (`Croche.open`
277
- succeeds).
278
-
279
- This agent's store was written by an older Croche build whose memory this Core cannot read or convert. Nothing was changed. To continue, delete this agent's store and reopen; this permanently loses this agent's conversation and memories for this user. Only an older build that still runs can export them first.
280
-
281
- For project stores, call `croche.close()` first (deleting an open store refuses with
282
- `store_busy`; closing first is simplest), then
283
- `Croche.deleteStore({ …projectOptions, agent: 'your-agent' })` (`'default'` for the default
284
- agent) and reopen. This removes that
285
- agent's conversation, memory, user wiki, archive and message log; other agents are unchanged.
286
- The separate single-agent `CrocheRuntime` has no delete method. Its recovery through
287
- the project API is not verified on React Native; do not assume that call reaches a
288
- custom/native single-agent store. Only an older build that still runs can export first.
289
- Use the storage owner's scoped
290
- recovery procedure. Never delete other agents' stores to bypass the refusal.
291
-
292
- **Verification:** the project-agent memory gates exercise the real Core through
293
- `tests/mock-native.ts`, the iOS bridge host test, and Android FFI dispatch unit tests.
294
- CI compiles both native bridges. The single-agent `CrocheRuntime.memory` native
295
- bridge path is compiled in CI but is not run by any host test. A device run is
296
- not covered by these gates.
297
-
298
- ## Users and money
299
-
300
- - Croche issues the opaque user id shown by `status().userId`. The app user is
301
- scoped to its project and installation.
302
- - `user` is the app's exact user identity (1–200 UTF-16 units, without padding,
303
- controls or lone surrogates). It separates the local store and the Cloud balance
304
- within this installation. Omission selects an anonymous installation user.
305
- `accountLabel` is removed and refused.
306
- - Each user has an allowance, held in Cloud. Your app can raise or set it within the
307
- ceilings you configure in Studio (turn on app-controlled allowances for the project:
308
- `host_budget_control_enabled`, with a maximum per adjustment and per user; otherwise
309
- `userBudget.add` fails with `host_budget_disabled`), for example after an in-app purchase:
310
- `await runtime.userBudget.add({ amount: 0.5, id: purchaseId })`. The `id` makes a retry
311
- safe: Cloud applies each id once. `runtime.userBudget.get()` shows the balance.
312
- - `runtime.history()` and `runtime.memory()` show the conversation and what the character
313
- remembers; `runtime.clearHistory()` starts over (money and identity stay).
314
- - When the allowance is spent, `send` returns `allowance_exhausted` before any model
315
- call. Show it; don't retry.
316
-
317
- ## Background upkeep and outages
318
-
319
- The Runtime delivers its call reports and syncs balances, policy and the model key in the
320
- background: after each turn and every minute (`backgroundSync`, default `true`;
321
- `maintenanceIntervalMs`). A turn never waits for it. Call it when the app returns to the
322
- foreground:
323
-
75
+ <!-- snippet: packages/react-native/tests/readme-examples.ts#rn-tools -->
324
76
  ```ts
325
- AppState.addEventListener('change', state => { if (state === 'active') void runtime.maintain(); });
77
+ const orders=defineTool({manifestVersion:1,name:'orders',summary:'Order lookup',
78
+ commands:[{key:'lookup',summary:'Read an order',flags:[{name:'id',type:'string',required:true}]}],
79
+ },async call=>toolResult({orderId:call.args.id,status:'shipped'}));
80
+ // Register with Croche.open({tools:[{tool:orders,bind:{account:'signed-in-user'}}],...}).
81
+ // An agent can select it with croche.agent('companion',{tools:['orders']}).
326
82
  ```
327
83
 
328
- If Croche Cloud is down, turns keep working on the key the install holds; reports wait in
329
- the outbox. Only a first registration and allowance changes need Cloud.
330
-
331
- ## The agent's scheduled notes
332
-
333
- With `crocheTools: { schedule: true }`, the agent can leave itself a note for later
334
- (`schedule at +2h call mum`). The native SDK delivers it as a turn of its own when it is due:
335
- while the app runs, and at each return to the foreground. `runtime.deliverDue()` and
336
- `runtime.schedules()` are there too.
84
+ ## Storage and app lifecycle
337
85
 
338
- `backgroundDelivery: true` (or `{ iosTaskIdentifier }`, default `"dev.croche.schedule"`) also
339
- registers the earliest note with the OS, so it can come while the app is not running:
340
- BGTaskScheduler on iOS, WorkManager on Android.
86
+ The default storage uses app-private files and Keychain/Keystore secrets. You can
87
+ supply a `StoragePal` through `Croche.open({storage,...})`. Lock contention returns
88
+ `'held'`; a failed primitive throws an Error with its diagnostic message.
341
89
 
342
- `Croche.open` does not offer `backgroundDelivery` yet: a project refuses it with
343
- `invalid_configuration`, and its agents deliver due notes while the app runs and at each return
344
- to the foreground.
90
+ Call `subscription.close()`, `agent.close()` and `croche.close()` when their owners
91
+ finish. Core controls streaming, sync, maintenance and retry timing; there are no
92
+ public host interval options.
345
93
 
346
- iOS app setup:
347
- 1. Info.plist: add the identifier to `BGTaskSchedulerPermittedIdentifiers`.
348
- 2. Background Modes: check **Background fetch**.
349
- 3. In `application(_:didFinishLaunchingWithOptions:)`, before it returns:
350
- `CrocheRuntimeBridge.registerBackgroundDelivery("dev.croche.schedule")`.
351
-
352
- Without step 1, the Runtime reports `schedule.degraded` (`not_configured`) on the debug stream and
353
- delivers at the next foreground. Android needs no setup.
354
-
355
- A background run delivers through the Runtime your JavaScript opened with `backgroundDelivery`.
356
- When the OS starts the app in the background, iOS usually starts JavaScript, and the run waits up
357
- to 20 seconds for that Runtime to open. A process that WorkManager starts on Android runs no
358
- JavaScript, so the run ends and the next foreground delivers. Neither has been measured.
359
-
360
- **The guarantee: never before the note's time; best effort after it; at the latest at the next
361
- foreground or open.** Each note is delivered once: a delivery cut short (`cancel()`, or the OS
362
- ending background time) leaves its notes pending for the next one; one that finished spends them,
363
- except a failure that keeps them, as below.
364
- A note is not exactly-once model or tool execution: a delivery cut short may already have made
365
- calls, and its retry makes them again.
366
-
367
- | | iOS (BGTaskScheduler) | Android (WorkManager) |
368
- |---|---|---|
369
- | Never before `at` | **measured** (Linux: Swift tests with a fake scheduler; the Core checks the time; the simulator: nothing ran before `at`) | **measured** (JVM: Kotlin tests with a fake scheduler; the same Core check; the emulator: a run forced before `at` delivered nothing) |
370
- | Earliest delay after `at` | simulator, app in the foreground, in-process timer: 6.4 s (one clean run; the lag is unexplained); the background task: not measured | emulator, app alive in the background: the worker started 0.12 s after `at`, delivered 2.8 s after it |
371
- | Typical delay | not measured (iOS decides; it favours apps the person uses often) | emulator, process dead: **more than 7.5 min** in one run, with every constraint met (Doze and App Standby buckets defer it) |
372
- | Worst delay | not measured (it may never run; then at the next foreground) | not measured |
373
- | Runs while the app is not running | simulator: **no**, iOS refuses every request (`.unavailable`, so `schedule.degraded` with `background_unavailable`); device: not measured | emulator, when forced: yes, a service-only process runs the worker. React Native: it delivers nothing there (no JavaScript, no Runtime); the next open does |
374
- | After a reboot | not measured | not measured (WorkManager keeps its requests across reboots, per its docs) |
375
- | After a force-quit (swipe away / Force stop) | not measured (per Apple's docs, no background runs until the next open) | not measured (per Android's docs, Force stop cancels its work until the next open) |
376
- | App setup | Info.plist identifier + Background fetch mode + `registerHandler` at launch | none (the library's manifest merges WorkManager in) |
377
- | Fallback | the next foreground (the Runtime calls `deliverDue()` itself) or open: measured on the simulator, once each | the next foreground (`install`) or open: open measured on the emulator, once |
378
-
379
- Every cell says how it is known. The simulator and emulator cells were measured on an iOS 27.0
380
- simulator and an Android 15 (API 35) emulator through the React Native harness, before this
381
- version's fixes to the Android worker and to background cancellation; nothing here was measured
382
- on a device, and iOS and Android remain unverified (GLOSSARY). The device check is to schedule a
383
- note for `+2m`, background the app, record whether and when it runs without opening the app,
384
- then open it: the note has been delivered exactly once, never before its time.
385
-
386
- A delivery that fails keeps its notes pending only when both hold: the failure is one that waiting
387
- can cure (no network, a timeout, the provider's 5xx or 429, a code the Runtime does not know), and
388
- the turn ran no command (the app's, or the agent's own memory, wiki or schedule command). Then each
389
- note gets `attempts` and `retryAt`, `deliverDue()` returns `delivered: false` with `retryAt`, and
390
- the notes are tried again from `retryAt`: 1, 2, 4 … minutes after each failure, at most an hour
391
- apart, until a day after the note's time. Any other failure spends them: the note records
392
- `failed: <code>` and `retry` (`permanent`, `dispatched` when the turn ran a command, or `expired`
393
- after a day). A spent note was not necessarily answered; the turn's result says whether it was.
394
- The backoff, the one-day limit and which failures count as curable are provisional.
395
-
396
- A delivery the native SDK runs on its own (its timer, the foreground, a background run) is in
397
- `history()` shortly after; nothing in JavaScript is called for it yet. Each Runtime opened with
398
- `backgroundDelivery` registers under a name of its own.
399
-
400
- The iOS and Android bridges and the vendored SDKs were compiled on the Mac through the harness
401
- before this version's changes; CI does not compile them. `scripts/vendor-native.sh` needs a Mac,
402
- cargo-ndk and the Android NDK. The JavaScript side is tested against the real Core through
403
- `tests/mock-native.ts`.
404
-
405
- ## Cancel, retry, restart
406
-
407
- On a project agent, `agent.cancel()` without an id stops the running turn and resolves at once:
408
- unlike TypeScript, where it resolves once the stop is saved, the stop is not yet durable when it
409
- resolves on React Native (and on native Swift and Kotlin).
410
-
411
- - A `send` made while a turn runs is held, never refused as busy: the sends held behind a turn
412
- go together as the next turn, each in its own channel.
413
- - Held sends keep the order your `send` calls were made in: their `input.queued` positions and
414
- the turn's `causedBy` follow it.
415
- - `runtime.cancel()` stops the current turn only; held sends still run, together, next. What was
416
- already shown stays in `result.text`, and the status is `cancelled`.
417
- - `runtime.clearQueued()` drops the held sends (each ends `cancelled`, with `input.dropped`) and
418
- leaves the running turn; `runtime.clearHistory()` drops them too.
419
- - A held send is stored before `input.queued` says so. If the app is killed or the Runtime closed
420
- with sends held, the next `create` runs them as the next turn, before any new send, with no
421
- callback: send the same `id` again to get its result.
422
- - A send's own `signal` drops just that send while it is held. Once its turn has started, aborting
423
- stops the turn, for every send it carries. A retry of the same `id` has its own `signal`.
424
- - Retrying `send` with the **same** `id` and the same content returns the saved result
425
- without calling the model again. For a new attempt, use a new `id`.
426
- - If the app is killed during a turn, reopening returns `interrupted` for it. Tools are
427
- never re-run on reopen, and a call that was in flight is charged a conservative estimate.
428
-
429
- ## Errors you will see
430
-
431
- `result.error.code` on a failed turn (or the thrown `CrocheError.code` from `create`):
432
-
433
- | Code | Meaning | What the app does |
434
- | --- | --- | --- |
435
- | `project_key_unknown` | Registration: no project has the supplied public project key, including a key that was rotated | Copy the current public project key from Studio → project → Keys, or `croche projects list`; do not use an account or debug key |
436
- | `project_access_disabled` | The known project is paused or has app access turned off, or its owning account was deleted. An existing Runtime learns access changes at a sync | Tell the user the AI is unavailable; the developer checks the project's access state in Studio |
437
- | `runtime_blocked` | The project owner blocked this install in Studio | Tell the user; only the developer can unblock it |
438
- | `account_disabled` | The developer's Croche account is disabled | Tell the user; the developer contacts Croche |
439
- | `allowance_exhausted` / `user_allowance_exhausted` | This user's AI allowance is spent | Offer a top-up (`userBudget.add`) or wait |
440
- | `project_budget_exhausted` | The project's money is spent | Tell the user; the developer raises the budget in Studio |
441
- | `account_credit_exhausted` | The developer's Runtime Credit is spent | Tell the user; the developer tops up Runtime Credit |
442
- | `development_allowance_exhausted` | The weekly development allowance is used up (debug keys) | Wait for Monday (UTC) or top up in Studio |
443
- | `installation_unverified` | This install proved nothing: no attestation and no `debugKey` | On a simulator, set `debugKey` |
444
- | `debug_token_invalid` / `debug_token_revoked` | The debug key is wrong or revoked | Issue a new one in Studio |
445
- | `attestation_unavailable` / `attestation_failed` | The project requires proof and the platform could not attest (e.g. a simulator without a `debugKey`). Where proof is not required, the install registers without it instead | Use a real device, or set `debugKey` in development |
446
- | `attestation_rejected` (registration) | Cloud checked the attestation against the project's settings and it failed | Check the Team ID and bundle id, or the package, signing certificate and Play keys, in Studio |
447
- | `attestation_required` / `attestation_unverifiable` (registration) | The project requires attestation, and none was sent, or the project has no settings for this platform | Send an attestation from a real device, or add the platform's settings in Studio |
448
- | `unverified_allowance_exhausted` | This install has no platform proof (a sideload, an emulator, a test device), and the project's $10 allowance for such installs is used up | Install from the store; the developer can't top it up (Require proof turns the path off) |
449
- | `gateway_unavailable` | No model key yet (first registration still pending) | Retry when online |
450
- | `gateway_key_exhausted` | The model key hit its limit and no new one came back | Retry later |
451
- | `provider_rate_limited`, `provider_error`, `provider_rejected`, `provider_credit_unavailable` | The model provider refused or failed | Retry later; report persistent ones |
452
- | `network_error`, `request_timeout` | The request did not complete | Retry with a new `id` |
453
- | `cancelled`, `interrupted` | Stopped by the app, or by the process ending | Nothing, or offer to continue |
454
- | `output_limit`, `context_limit`, `iteration_limit` | A bound was reached | Shorten, or continue in a new turn |
455
- | `store_busy` | This store is already open (two Runtimes for one agent) | Open each agent once |
456
- | `memory_store_too_old` (from `croche.agent()`) | An older build wrote this agent's store with keyed memory | Close the project, `Croche.deleteStore({ …, agent })`, reopen (see Memory) |
457
- | `host_budget_disabled` (from `userBudget.add/set`) | App-controlled allowances are off for the project | Turn them on in Studio |
458
-
459
- ## Debug events
460
-
461
- To see what your agent did on a device, pass `onDebugEvent` to `Croche.open`, as on TypeScript.
462
- It receives every agent's debug entries from its open.
463
-
464
- ```ts
465
- const croche = await Croche.open({
466
- /* ... */
467
- onDebugEvent: event => console.log('[croche]', event.type, event.data),
468
- });
469
- ```
94
+ Use `agent.memory` for list/delete/clear/enabled. Register wiki documents with
95
+ `Croche.open({wiki:{docs:[...]},...})`; document files are read when needed.
470
96
 
471
- The entries are the `runtime` projection: your app's own side (inputs, tool calls and their
472
- results, trace events). Model calls appear only as trace entries, without their content: no
473
- prompts and no model output. It works the same in development and release builds, so a release
474
- build can log what happened. Public builds have no other projection.
97
+ ## API
475
98
 
476
- The observer is fixed for the project's life: reopen the project to change it. An observer that
477
- throws never breaks the project.
99
+ The React Native package exports the same `Croche`, `Agent`, `defineTool`,
100
+ `toolResult`, `ToolError`, `tools`, `CrocheError` and public types as the TypeScript
101
+ SDK. See the [app API](../../docs/APP-API.md) and the
102
+ [TypeScript API reference](../runtime/README.md). Unknown events arrive as
103
+ `{type:'unknown',originalType,fields}`; ignore types and fields your app does not use.
478
104
 
479
- ## Options
105
+ ## Contributor build
480
106
 
481
- | Option | Default | Meaning |
482
- | --- | --- | --- |
483
- | `projectKey`, `instructions` | required | Your public project key and the character |
484
- | `debugKey` | none | Debug key for simulators and emulators |
485
- | `agentId` | none | Which character this is, when there are several |
486
- | `user` | none | Exact app user identity, scoped to this installation |
487
- | `tools`, `markerGuide` | none | Commands the character can use; what your markers mean |
488
- | `memory` | on | `{ enabled, maxTokens, policy }`: model-owned id facts and a separate conversation summary |
489
- | `wiki` | none | Documents to look up: `docs`, or `{ docs, include, exclude }` |
490
- | `streaming` | `true` | Stream replies as `text.delta` |
491
- | `backgroundSync`, `maintenanceIntervalMs` | `true`, 60000 | Background upkeep |
492
- | `crocheTools.schedule` | off | `true`: the agent's own scheduled notes |
493
- | `backgroundDelivery` | off | `true` or `{ iosTaskIdentifier }`: notes while the app is not running (BGTaskScheduler, WorkManager) |
494
- | `heartbeat` | off | `{ everyMs }`, 900000..86400000 (15 minutes to 24 hours): a regular check-in turn, delivered like a due note |
495
- | `maxIterations`, `maxOutputTokens`, `maxContextTokens`, `requestTimeoutMs` | 8, 2048, 12000, 90000 | Bounds; context and memory budgets are estimated tokens |
496
- | `attestation` | `"platform"` | `"off"` never attests (then only a `debugKey` admits the install) |
497
- | `android.cloudProjectNumber` | none | The Google Cloud project linked to the app in Play Console (Play Integrity) |
498
- | `storageKey` | derived | Override the local store name |
107
+ The shared facade is compiled from its single source into this package; it imports
108
+ the native adapter instead of WASM. `npm run build --workspace @h1r-ai/croche-react-native`
109
+ builds its JS and declarations. `npm run pack:rn` also builds/vendors the native
110
+ artifacts (Xcode and Android toolchains required).
499
111
 
500
- The model is not an option: the project's main and fallback models are configured in
501
- Croche Cloud.
112
+ Model-call `turn` events report `cost` in credits; `null` is unknown, never zero. The numeric value and precision are unchanged. Emitted `costStatus` values are `reported`, `unknown`, and `none`; `unknown` means `cost: null`. Readers remain open to future status strings.
@@ -2638,7 +2638,7 @@ Used by:
2638
2638
  - idna 1.1.0
2639
2639
  - idna_adapter 1.2.2
2640
2640
  - indexmap 2.14.2
2641
- - js-sys 0.3.81
2641
+ - js-sys 0.3.84
2642
2642
  - linux-raw-sys 0.12.1
2643
2643
  - log 0.4.34
2644
2644
  - num-traits 0.2.19
@@ -2656,13 +2656,12 @@ Used by:
2656
2656
  - url 2.5.8
2657
2657
  - version_check 0.9.5
2658
2658
  - wasi 0.11.1+wasi-snapshot-preview1
2659
- - wasm-bindgen-backend 0.2.104
2660
- - wasm-bindgen-futures 0.4.54
2661
- - wasm-bindgen-macro-support 0.2.104
2662
- - wasm-bindgen-macro 0.2.104
2663
- - wasm-bindgen-shared 0.2.104
2664
- - wasm-bindgen 0.2.104
2665
- - web-sys 0.3.81
2659
+ - wasm-bindgen-futures 0.4.57
2660
+ - wasm-bindgen-macro-support 0.2.107
2661
+ - wasm-bindgen-macro 0.2.107
2662
+ - wasm-bindgen-shared 0.2.107
2663
+ - wasm-bindgen 0.2.107
2664
+ - web-sys 0.3.84
2666
2665
 
2667
2666
  Apache License
2668
2667
  Version 2.0, January 2004
@@ -17,7 +17,10 @@ apply plugin: "com.facebook.react"
17
17
  android {
18
18
  namespace "dev.croche.reactnative"
19
19
  compileSdk 35
20
- defaultConfig { minSdk 26; consumerProguardFiles "vendor/CrocheRuntimeSDK/consumer-rules.pro" }
20
+ defaultConfig {
21
+ minSdk 26; consumerProguardFiles "vendor/CrocheRuntimeSDK/consumer-rules.pro"
22
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
23
+ }
21
24
  sourceSets {
22
25
  main {
23
26
  java.srcDirs += ["src/main/java", "vendor/CrocheRuntimeSDK/core", "vendor/CrocheRuntimeSDK/android"]
@@ -38,6 +41,8 @@ dependencies {
38
41
  implementation "com.google.android.play:integrity:1.4.0"
39
42
  implementation "androidx.work:work-runtime:2.10.1"
40
43
  testImplementation "junit:junit:4.13.2"
44
+ androidTestImplementation "androidx.test.ext:junit:1.2.1"
45
+ androidTestImplementation "androidx.test:runner:1.6.2"
41
46
  }
42
47
 
43
48
  react {