@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
@@ -0,0 +1,284 @@
1
+ export type { RunToolResult } from './run-tool.js';
2
+ export type { ErrorCategory } from './errors.js';
3
+ import type { AgentEvent } from './generated/app-stream.js';
4
+ export type { Attachment, AgentEvent, InputDisposition, MessageEnd, EventError, SendReceipt, RequestResult } from './generated/app-stream.js';
5
+ export type Json = null | boolean | number | string | Json[] | {
6
+ [k: string]: Json;
7
+ };
8
+ export interface ToolManifest {
9
+ manifestVersion: 1 | (number & {});
10
+ name: string;
11
+ summary: string;
12
+ guide?: string;
13
+ commands: Array<{
14
+ key: string;
15
+ summary: string;
16
+ name?: string;
17
+ aliases?: string[];
18
+ timeoutMs?: number;
19
+ positionals?: ToolArg[];
20
+ flags?: ToolArg[];
21
+ }>;
22
+ }
23
+ export interface ToolArg {
24
+ name: string;
25
+ type: 'string' | 'integer' | 'number' | 'boolean' | 'duration' | (string & {});
26
+ required?: boolean;
27
+ enum?: Json[];
28
+ default?: Json;
29
+ description?: string;
30
+ }
31
+ export interface ToolDefinition {
32
+ readonly name: string;
33
+ }
34
+ export type ToolExecute = (call: ToolCall, ctx: ToolContext) => ToolResult | Json | undefined | void | Promise<ToolResult | Json | undefined | void>;
35
+ export interface ToolCall {
36
+ key: string;
37
+ args: Record<string, Json>;
38
+ }
39
+ export interface ToolContext {
40
+ callId: string;
41
+ agentId: string;
42
+ instance: string | null;
43
+ user: string | null;
44
+ causedBy: string[];
45
+ signal: AbortSignal;
46
+ }
47
+ export type ToolResult = {
48
+ content: ToolContent[];
49
+ } | {
50
+ json: Json;
51
+ };
52
+ export type ToolContent = {
53
+ type: 'text';
54
+ text: string;
55
+ } | {
56
+ type: 'image';
57
+ mediaType: string;
58
+ data: string;
59
+ } | {
60
+ type: 'image';
61
+ mediaType: string;
62
+ uri: string;
63
+ };
64
+ export type WikiDoc = {
65
+ path: string;
66
+ description: string;
67
+ markdown: string;
68
+ } | {
69
+ path: string;
70
+ description: string;
71
+ file: string;
72
+ };
73
+ export interface ToolEntryOptions<T> {
74
+ tool: T;
75
+ bind?: Record<string, Json>;
76
+ commands?: string[];
77
+ guide?: string;
78
+ }
79
+ export type ToolRegistration = ToolDefinition | {
80
+ tool: ToolDefinition;
81
+ bind: Record<string, Json>;
82
+ };
83
+ export type ToolScope = Array<string | ToolEntryOptions<string>>;
84
+ export type WikiScope = Array<string | {
85
+ doc: string;
86
+ guide?: string;
87
+ }>;
88
+ export interface AgentOptions {
89
+ instance?: {
90
+ id: string;
91
+ config?: Json;
92
+ };
93
+ tools?: ToolScope | 'all' | null;
94
+ wiki?: WikiScope | 'all' | null;
95
+ }
96
+ export interface OpenOptions {
97
+ projectKey: string;
98
+ user?: string;
99
+ language?: string;
100
+ bundledConfig: Json;
101
+ tools?: ToolRegistration[];
102
+ wiki?: WikiDoc[];
103
+ storage?: StoragePal;
104
+ platform?: PlatformHandle;
105
+ serverKey?: string;
106
+ debugKey?: string;
107
+ }
108
+ export interface DecideInput {
109
+ id?: string;
110
+ state: Json;
111
+ questions?: Array<string | DecisionQuestion>;
112
+ }
113
+ export type DecisionQuestion = {
114
+ id: string;
115
+ } & ({
116
+ type: 'noul';
117
+ instructions: string;
118
+ criteria?: {
119
+ true?: string;
120
+ false?: string;
121
+ };
122
+ } | {
123
+ type: 'choice';
124
+ instructions: string;
125
+ criteria: Array<{
126
+ id: string;
127
+ description?: string;
128
+ }>;
129
+ } | {
130
+ type: 'score';
131
+ instructions: string;
132
+ criteria: string[];
133
+ });
134
+ export interface DecisionConfidence {
135
+ value: number;
136
+ method: 'typesafe' | 'p_max' | (string & {});
137
+ }
138
+ export type DecisionAnswer = {
139
+ type: 'noul';
140
+ value: boolean;
141
+ probability?: number;
142
+ confidence?: DecisionConfidence;
143
+ } | {
144
+ type: 'choice';
145
+ value: string;
146
+ probabilities?: Record<string, number>;
147
+ confidence?: DecisionConfidence;
148
+ } | {
149
+ type: 'score';
150
+ value: number;
151
+ probabilities?: number[];
152
+ confidence?: DecisionConfidence;
153
+ } | {
154
+ type: 'refusal';
155
+ reason?: string;
156
+ } | {
157
+ type: 'unknown';
158
+ originalType: string;
159
+ fields: Json;
160
+ };
161
+ export interface DecisionResult {
162
+ id: string;
163
+ model: string;
164
+ answers: Record<string, DecisionAnswer>;
165
+ provider?: string;
166
+ usage: Json;
167
+ cost: number | null;
168
+ costStatus: 'reported' | 'unknown' | 'none' | (string & {});
169
+ }
170
+ export type SendInput = string | {
171
+ id?: string;
172
+ input: Array<TextInput | ImageInput>;
173
+ };
174
+ export interface TextInput {
175
+ type: 'text';
176
+ text: string;
177
+ kind?: 'user' | 'app_event' | 'app_state';
178
+ }
179
+ export interface ImageInput {
180
+ type: 'image';
181
+ mediaType?: string;
182
+ data?: string;
183
+ uri?: string;
184
+ alt?: string;
185
+ }
186
+ export interface SendOptions {
187
+ signal?: AbortSignal;
188
+ responseFormat?: ResponseFormat;
189
+ }
190
+ export type ResponseFormat = {
191
+ type: 'json_schema';
192
+ json_schema: {
193
+ name: string;
194
+ schema: Json;
195
+ strict?: boolean;
196
+ description?: string;
197
+ };
198
+ } | {
199
+ type: 'json_object';
200
+ };
201
+ export interface Subscription {
202
+ history(options: {
203
+ before?: number;
204
+ limit: number;
205
+ }): Promise<void>;
206
+ close(): void;
207
+ readonly ended: boolean;
208
+ }
209
+ export interface MemoryItem {
210
+ id: string;
211
+ text: string;
212
+ [k: string]: Json;
213
+ }
214
+ export type BackgroundEvent = {
215
+ type: 'delivered' | 'deadline' | 'cancelled' | 'skipped' | (string & {});
216
+ at: string;
217
+ [k: string]: Json;
218
+ } & {
219
+ reason?: 'storage_unavailable' | 'os_registration_failed' | (string & {});
220
+ };
221
+ export interface BackgroundOptions {
222
+ sink?: {
223
+ onEvent(event: BackgroundEvent): void;
224
+ };
225
+ storage?: StoragePal;
226
+ }
227
+ export type DebugCapability = 'agents.list' | 'status' | 'history' | 'send' | 'cancel' | 'tools' | (string & {});
228
+ export interface StoragePal {
229
+ read(key: string): Promise<string | null>;
230
+ write(key: string, value: string): Promise<void>;
231
+ remove(key: string): Promise<void>;
232
+ list(prefix: string): Promise<string[]>;
233
+ lock(name: string): Promise<'acquired' | 'held'>;
234
+ unlock(name: string): Promise<void>;
235
+ secrets: {
236
+ read(key: string): Promise<string | null>;
237
+ write(key: string, value: string): Promise<void>;
238
+ remove(key: string): Promise<void>;
239
+ };
240
+ }
241
+ export type PlatformHandle = unknown;
242
+ export interface SubscribeOptions {
243
+ onEvent: (event: AgentEvent) => void;
244
+ initialMessages?: number;
245
+ after?: {
246
+ logId: string;
247
+ seq: number;
248
+ };
249
+ deltaMs?: number;
250
+ }
251
+ export interface DeliverDueResult {
252
+ ran: boolean;
253
+ delivered: number;
254
+ deferred: Array<{
255
+ user: string;
256
+ agent: string;
257
+ instance: string | null;
258
+ code: 'deadline' | 'cancelled' | (string & {});
259
+ message: string;
260
+ }>;
261
+ }
262
+ export interface WakeTimes {
263
+ wakes: Array<{
264
+ user: string;
265
+ at: number;
266
+ }>;
267
+ next?: number;
268
+ }
269
+ export interface DeleteScope {
270
+ agent?: string;
271
+ instance?: string;
272
+ }
273
+ export interface DebugAttachOptions {
274
+ url: string;
275
+ token: string;
276
+ }
277
+ export interface AttachedDebugger {
278
+ debuggerId: string;
279
+ capabilities: DebugCapability[];
280
+ }
281
+ export interface CrocheDebugger {
282
+ attach(options: DebugAttachOptions): Promise<AttachedDebugger>;
283
+ detach(): Promise<void>;
284
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { CoreCancel, CoreModule } from './core/port.js';
2
+ /**
3
+ * A fresh Core token for one call, bridged to the app's AbortSignal when there is one (S1: Core borrows a token on
4
+ * every call). Already aborted = cancelled before the call (Core: never queued). The listener is never removed on
5
+ * settle: `send`'s signal is sugar for cancel(id) after acceptance too.
6
+ */
7
+ export declare function tokenFor(core: CoreModule, signal: AbortSignal | undefined): CoreCancel;
8
+ /** Core's token as the AbortSignal a tool's execute sees (`ctx.signal`). */
9
+ export declare function signalFor(token: CoreCancel): AbortSignal;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * A fresh Core token for one call, bridged to the app's AbortSignal when there is one (S1: Core borrows a token on
3
+ * every call). Already aborted = cancelled before the call (Core: never queued). The listener is never removed on
4
+ * settle: `send`'s signal is sugar for cancel(id) after acceptance too.
5
+ */
6
+ export function tokenFor(core, signal) {
7
+ const token = core.newCancel();
8
+ if (signal === undefined)
9
+ return token;
10
+ if (signal.aborted)
11
+ token.cancel();
12
+ else
13
+ signal.addEventListener('abort', () => token.cancel(), { once: true });
14
+ return token;
15
+ }
16
+ /** Core's token as the AbortSignal a tool's execute sees (`ctx.signal`). */
17
+ export function signalFor(token) {
18
+ const controller = new AbortController();
19
+ if (token.isCancelled())
20
+ controller.abort();
21
+ else
22
+ token.onCancel(() => controller.abort());
23
+ return controller.signal;
24
+ }
@@ -0,0 +1,234 @@
1
+ import type { Json, PlatformHandle } from '../app-api.js';
2
+ /** JSON text, produced by `jsonText` on the way in (non-JSON text when the value has none; Core refuses it) and by Core on the way out. */
3
+ export type JsonText = string;
4
+ /** Core's cancellation token (WasmCancel). Core decides what a cancel means at each point. */
5
+ export interface CoreCancel {
6
+ cancel(): void;
7
+ isCancelled(): boolean;
8
+ onCancel(callback: () => void): void;
9
+ }
10
+ /** The module-level entry points: factories and the statics of `Croche`. */
11
+ export interface CoreModule {
12
+ /** Optional web/Node decision capability; absent on native until its bridge is proven. */
13
+ readonly decisions?: CoreDecisions;
14
+ newCancel(): CoreCancel;
15
+ /** The JSON is the app's WHOLE options object: each opaque reference (a tool definition, the storage, the platform
16
+ * handle) is a null marker there and travels in its own argument. `registrations` keeps the app's order. The
17
+ * storage argument is always a PAL: the app's (then `storage: null` is in the JSON) or the platform default (then
18
+ * the key is absent; Core records custom storage by its presence, #829). */
19
+ open(openJson: JsonText, registrations: CoreToolRegistration[], storage: CoreStoragePal, host: CoreHost, recoveryJson?: JsonText): Promise<CoreCroche>;
20
+ /** `optionsJson` is the app's whole BackgroundOptions, sink and storage as null markers. `platformStorage` is
21
+ * INTERNAL (no app option): the platform-default backend, given only when the selected storage is custom and the
22
+ * platform has a separate OS default store. Node and web have none, so the SDK passes undefined (Atlas #830
23
+ * 1e28b27e: custom storage + no platform store writes no marker and keeps an internal fact, not an error). */
24
+ registerBackground(optionsJson: JsonText, sink: CoreEventSink | undefined, storage: CoreStoragePal, platformStorage: CoreStoragePal | undefined, host: CoreHost): void;
25
+ wakeTimes(openJson: JsonText, queryJson: JsonText | undefined, storage: CoreStoragePal, host: CoreHost): Promise<JsonText>;
26
+ /** A tool definition (WASM: `new CoreToolDefinition(manifestJson, execute)`): Core validates the manifest. */
27
+ defineTool(manifestJson: JsonText, execute: CoreExecute): CoreToolDefinition;
28
+ /** The Core-owned webSearch definition (`coreWebSearch()`), registered by the name `webSearch`. */
29
+ webSearch(): CoreToolDefinition;
30
+ }
31
+ export interface CoreToolDefinition {
32
+ readonly name: string;
33
+ }
34
+ /** One entry of `tools` (WASM: a fresh `new CoreToolRegistration(tool, optionsJson)` per open). `optionsJson` is
35
+ * absent for a bare definition; otherwise the app's WHOLE wrapper object with `tool` as null: bind, commands, guide
36
+ * and unknown keys reach Core, which refuses what it does not take. */
37
+ export interface CoreToolRegistration {
38
+ tool: CoreToolDefinition;
39
+ optionsJson?: JsonText;
40
+ }
41
+ /** The storage Core reads and writes (ARCHITECTURE §2a; the app's StoragePal fits it unchanged).
42
+ * A failing primitive just throws (Core reports storage_error and ignores any
43
+ * code on it); contention is `lock` returning `held` (#837). */
44
+ export interface CoreStoragePal {
45
+ read(key: string): Promise<string | null>;
46
+ write(key: string, value: string): Promise<void>;
47
+ remove(key: string): Promise<void>;
48
+ list(prefix: string): Promise<string[]>;
49
+ lock(name: string): Promise<'acquired' | 'held'>;
50
+ unlock(name: string): Promise<void>;
51
+ secrets: {
52
+ read(key: string): Promise<string | null>;
53
+ write(key: string, value: string): Promise<void>;
54
+ remove(key: string): Promise<void>;
55
+ };
56
+ }
57
+ /** Owned image bytes for a send, indexing `input.input` (S1). The 0.6 TS App API has no bytes input (an image is
58
+ * `data` or `uri` in the input JSON, read by Core), so the wrapper passes an empty list. */
59
+ export interface CoreImageInput {
60
+ element: number;
61
+ bytes: Uint8Array;
62
+ }
63
+ /** Core calls a tool: the call `{key, args}` and context `{agentId, instance, user, causedBy}` as JSON, plus its token.
64
+ * It answers ONE ToolCompletion as JSON text, the transport Core reads unchanged (no adapter mapping). */
65
+ export type CoreExecute = (callJson: JsonText, contextJson: JsonText, cancel: CoreCancel) => Promise<JsonText>;
66
+ /**
67
+ * What one execute did, as facts, discriminated by `type` (Atlas's S1 pin, Keel 10-30; the same on every SDK). Core
68
+ * picks the model text, the codes (`tool_failed`, `invalid_tool_result`), the timeout and the settlement. The SDK maps
69
+ * no codes.
70
+ */
71
+ export type ToolCompletion = {
72
+ type: 'json';
73
+ value: Json;
74
+ } | {
75
+ type: 'result';
76
+ content: Json;
77
+ } | {
78
+ type: 'empty';
79
+ } | {
80
+ type: 'invalid_result';
81
+ } | {
82
+ type: 'tool_error';
83
+ message: string;
84
+ } | {
85
+ type: 'handler_error';
86
+ error?: ThrownError;
87
+ } | {
88
+ type: 'cancelled';
89
+ } | {
90
+ type: 'unavailable';
91
+ };
92
+ /** A thrown value as the transport carries it: its own `name` (as type) and `message`, both strings. */
93
+ export interface ThrownError {
94
+ type: string;
95
+ message: string;
96
+ }
97
+ /** A thrown value's own string fields, read once (event delivery); anything else reads as absent. */
98
+ export interface ThrownFacts {
99
+ name?: string;
100
+ message?: string;
101
+ code?: string;
102
+ }
103
+ /**
104
+ * Delivers Core's events, one JSON object each, in Core's order (S1 checkpoint: `eventSink(deliveryId, eventJson,
105
+ * delivery)`). The SDK calls `tryEnter()` synchronously right before entering the app's handler (false = do not
106
+ * enter, do not complete), then `complete(outcomeJson)` once the handler has FINISHED: returned, or its thenable
107
+ * settled. Core assigns the codes (`handler_failed`) and holds the next event until then; the SDK keeps no queue.
108
+ */
109
+ export type CoreEventSink = (deliveryId: string, eventJson: JsonText, delivery: CoreDelivery) => void;
110
+ export interface CoreDelivery {
111
+ tryEnter(): boolean;
112
+ complete(outcomeJson: JsonText): void;
113
+ }
114
+ /** `unavailable` = the handler could not be reached (a post failure, a teardown): a transport fact on ANY binding. */
115
+ export type DeliveryOutcome = {
116
+ outcome: 'returned';
117
+ } | {
118
+ outcome: 'threw';
119
+ error?: ThrownFacts;
120
+ } | {
121
+ outcome: 'unavailable';
122
+ };
123
+ export interface CoreCroche {
124
+ runTool(name: string, argsJson: JsonText, optionsJson: JsonText, cancel: CoreCancel): Promise<JsonText>;
125
+ deleteData(scopeJson: JsonText | undefined): Promise<void>;
126
+ agent(id: string, optionsJson: JsonText | undefined): Promise<CoreAgent>;
127
+ agentIds(): string[];
128
+ deliverDue(optionsJson: JsonText | undefined, cancel: CoreCancel): Promise<JsonText>;
129
+ wikiPut(docJson: JsonText): Promise<void>;
130
+ wikiRemove(path: string): Promise<void>;
131
+ wikiList(): Promise<JsonText>;
132
+ debugAttach(optionsJson: JsonText): Promise<JsonText>;
133
+ debugDetach(): Promise<void>;
134
+ shutdown(): Promise<void>;
135
+ }
136
+ export interface CoreAgent {
137
+ /** Immutable identity, readable after close (Atlas S1 pin). */
138
+ readonly id: string;
139
+ readonly instance: string | null;
140
+ /** A fresh token on every call, signal or not (S1: WASM borrows it). It stays bridged to the app's signal:
141
+ * cancelled before acceptance = never queued; after = cancel(id). */
142
+ send(inputJson: JsonText, images: CoreImageInput[], optionsJson: JsonText | undefined, cancel: CoreCancel): Promise<JsonText>;
143
+ request(inputJson: JsonText, images: CoreImageInput[], optionsJson: JsonText | undefined, cancel: CoreCancel): Promise<JsonText>;
144
+ subscribe(selectionJson: JsonText, sink: CoreEventSink): CoreSubscription;
145
+ cancel(id: string | undefined): Promise<void>;
146
+ clearHistory(): Promise<void>;
147
+ memoryList(): Promise<JsonText>;
148
+ memoryDelete(id: string): Promise<void>;
149
+ memoryClear(): Promise<void>;
150
+ memoryEnabled(on: boolean): Promise<void>;
151
+ setTools(scopeJson: JsonText): Promise<void>;
152
+ resetTools(): Promise<void>;
153
+ setWiki(scopeJson: JsonText): Promise<void>;
154
+ resetWiki(): Promise<void>;
155
+ shutdown(): Promise<void>;
156
+ }
157
+ /** Separate capability: no shared CoreAgent method is required of an unbridged native transport. */
158
+ export interface CoreDecisions {
159
+ decide(agent: CoreAgent, inputJson: JsonText, optionsJson: JsonText | undefined, cancel: CoreCancel): Promise<JsonText>;
160
+ }
161
+ export interface CoreSubscription {
162
+ history(optionsJson: JsonText): Promise<void>;
163
+ shutdown(): void;
164
+ readonly ended: boolean;
165
+ }
166
+ /** One HTTP request as Core built it. `connectTo` = the checked address Core pinned (SSRF: Core decides). */
167
+ export interface CoreHttpRequest {
168
+ url: string;
169
+ method: string;
170
+ headers: [string, string][];
171
+ body?: string;
172
+ timeoutMs: number;
173
+ maxResponseBytes: number;
174
+ connectTo?: string;
175
+ }
176
+ export interface CoreBodySink {
177
+ head(status: number, headers: [string, string][]): void;
178
+ chunk(bytes: Uint8Array): boolean;
179
+ }
180
+ /** Core's decode request, passed to the codec unchanged. */
181
+ export interface ImageDecodeOptions {
182
+ frame: number;
183
+ applyOrientation: boolean;
184
+ }
185
+ /** `hasAlpha: null` = the codec cannot tell (Core decides what that means). */
186
+ export interface DecodedImage {
187
+ handle: string;
188
+ width: number;
189
+ height: number;
190
+ hasAlpha: boolean | null;
191
+ }
192
+ export interface PlatformFacts {
193
+ targetKind?: 'ios-device' | 'ios-simulator' | 'android' | 'other';
194
+ debuggable?: boolean;
195
+ locale?: string;
196
+ attestationPlatform?: string;
197
+ browserFetch?: boolean;
198
+ }
199
+ /** The platform's effects and facts. Storage is NOT here: it is its own argument (CoreStoragePal). */
200
+ export interface CoreHost {
201
+ /** An app asset (a wiki `file`), resolved by the platform rule; null = absent. */
202
+ readAsset(path: string): Promise<Uint8Array | null>;
203
+ http(request: CoreHttpRequest, sink: CoreBodySink, cancel: CoreCancel): Promise<void>;
204
+ /** Every A/AAAA answer, unfiltered; Core checks them and chooses `connectTo`. */
205
+ resolve(host: string, cancel: CoreCancel): Promise<string[]>;
206
+ nowMs(): number;
207
+ utcOffsetMinutes(atMs: number): number;
208
+ sleep(ms: number): Promise<void>;
209
+ /** Optional platform wake hint (null = none). Core's per-Runtime owned loop drives timed upkeep
210
+ * through PAL sleep; post-reply upkeep starts directly. No shared SDK timer decides upkeep. */
211
+ wake(atMs: number | null, onWake?: () => void): void;
212
+ random(): string;
213
+ /** Sampled at open (Core's CrocheHost). Absent = unknown; the SDK never fills a default. `browserFetch` only where the
214
+ * transport is the browser's fetch (Core then cannot pin; it never resolves). */
215
+ platformFacts(): PlatformFacts;
216
+ readonly platform: PlatformHandle | undefined;
217
+ readImage(request: {
218
+ source: {
219
+ kind: 'local';
220
+ uri: string;
221
+ };
222
+ maxBytes: number;
223
+ }, cancel: CoreCancel): Promise<Uint8Array>;
224
+ imageCodecAvailable(): boolean;
225
+ decodeImage(bytes: Uint8Array, options: ImageDecodeOptions, cancel: CoreCancel): Promise<DecodedImage>;
226
+ renderImage(request: {
227
+ handle: string;
228
+ width: number;
229
+ height: number;
230
+ format: 'png' | 'jpeg';
231
+ quality?: number;
232
+ }, cancel: CoreCancel): Promise<Uint8Array>;
233
+ releaseDecodedImage(handle: string): void;
234
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export { coreModule } from '../native-adapter.js';
@@ -0,0 +1,2 @@
1
+ // Native Core transport selected at RN build time.
2
+ export { coreModule } from '../native-adapter.js';
@@ -0,0 +1,42 @@
1
+ import { type Agent } from './agent.js';
2
+ import type { AgentOptions, BackgroundOptions, CrocheDebugger, DeleteScope, DeliverDueResult, OpenOptions, WakeTimes, WikiDoc } from './app-api.js';
3
+ import { type RunToolResult } from './run-tool.js';
4
+ import type { Json } from './app-api.js';
5
+ export declare class Croche {
6
+ #private;
7
+ private constructor();
8
+ static open(options: OpenOptions, recovery?: {
9
+ recover: 'delete';
10
+ }): Promise<Croche>;
11
+ /** Deletes this user's local data in the scope. Core closes selected agents first. */
12
+ deleteData(scope?: DeleteScope): Promise<void>;
13
+ /**
14
+ * Once at app start. Core keeps BackgroundEvents durably and delivers each at least once to the sink. `storage` is
15
+ * the same StoragePal the app passes to open() (the platform default when omitted).
16
+ */
17
+ static registerBackground(options?: BackgroundOptions): void;
18
+ static wakeTimes(options: OpenOptions, query?: {
19
+ before?: number;
20
+ after?: number;
21
+ limit?: number;
22
+ }): Promise<WakeTimes>;
23
+ deliverDue(options?: {
24
+ signal?: AbortSignal;
25
+ }): Promise<DeliverDueResult>;
26
+ agent(id: string, options?: AgentOptions): Promise<Agent>;
27
+ /** App tools run outside every conversation. Recovery uses the same required id. */
28
+ runTool(name: string, args: Record<string, Json>, options: {
29
+ id: string;
30
+ signal?: AbortSignal;
31
+ }): Promise<RunToolResult>;
32
+ /** Read from Core at every access. */
33
+ get agentIds(): readonly string[];
34
+ readonly wiki: {
35
+ put: (doc: WikiDoc) => Promise<void>;
36
+ remove: (path: string) => Promise<void>;
37
+ list: () => Promise<WikiDoc[]>;
38
+ };
39
+ readonly debugger: CrocheDebugger;
40
+ /** Resolves once new work has stopped; Core continues the bounded final delivery. */
41
+ close(): Promise<void>;
42
+ }