@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.
- package/LICENSE +1 -1
- package/README.md +90 -451
- package/THIRD-PARTY-NOTICES +906 -14
- package/android/build.gradle +6 -1
- package/android/src/androidTest/java/dev/croche/reactnative/WikiFileBridgeTest.kt +126 -0
- package/android/src/main/AndroidManifest.xml +0 -5
- package/android/src/main/java/dev/croche/reactnative/CoreDispatch.kt +106 -0
- package/android/src/main/java/dev/croche/reactnative/CoreWire.kt +217 -0
- package/android/src/main/java/dev/croche/reactnative/CrocheRuntimeModule.kt +48 -824
- package/android/src/main/java/dev/croche/reactnative/NativePal.kt +68 -0
- package/android/src/main/java/dev/croche/reactnative/RNHostPal.kt +9 -0
- package/android/src/test/java/dev/croche/reactnative/AgentMemoryTest.kt +64 -41
- package/android/src/test/java/dev/croche/reactnative/BackgroundDelegationTest.kt +64 -0
- package/android/src/test/java/dev/croche/reactnative/BlobFilesTest.kt +107 -0
- package/android/src/test/java/dev/croche/reactnative/ImageAdapterWireTest.kt +70 -0
- package/android/src/test/java/dev/croche/reactnative/OpenForwardingFixture.kt +44 -0
- package/android/src/test/java/dev/croche/reactnative/ProjectAttestationTest.kt +19 -32
- package/android/src/test/java/dev/croche/reactnative/ProjectHandlerStagesTest.kt +32 -0
- package/android/src/test/java/dev/croche/reactnative/ProjectRecoveryTest.kt +12 -0
- package/android/src/test/java/dev/croche/reactnative/ProjectTimeZoneTest.kt +11 -15
- package/android/src/test/java/dev/croche/reactnative/StorageVersionWireTest.kt +37 -0
- package/android/src/test/java/dev/croche/reactnative/VerificationDispatchTest.kt +24 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/AndroidEventSink.kt +27 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/AndroidPlatform.kt +10 -8
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BackgroundRegistration.kt +16 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BackgroundWakeWorker.kt +55 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapDecodedImageCodec.kt +162 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapImageCodec.kt +1 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapImageInput.kt +15 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapOrientation.kt +40 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapPalCodec.kt +66 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidAssetPal.kt +30 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidCoreFactory.kt +35 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidCoreHost.kt +116 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidMainDispatcher.kt +17 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidPublicPlatform.kt +17 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidS2Pal.kt +14 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidStateStore.kt +216 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidStoragePal.kt +108 -0
- package/android/vendor/CrocheRuntimeSDK/consumer-rules.pro +8 -2
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Adapters.kt +75 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/BindingFacts.kt +29 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ContextConfig.kt +31 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Core.kt +25 -1
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Croche.kt +121 -103
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheAgent.kt +89 -103
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheRuntime.kt +20 -360
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheTools.kt +136 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Decision.kt +170 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/DecodedImageCodec.kt +23 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Effects.kt +26 -21
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/EncodedImageCodec.kt +51 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/GeneratedAppStream.kt +715 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Host.kt +9 -322
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ImagePal.kt +183 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Images.kt +16 -28
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/NativeEvent.kt +59 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/NativeHandleOwner.kt +118 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Platform.kt +10 -74
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectTypes.kt +294 -37
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/PublicResults.kt +127 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ReaderValues.kt +73 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/RunTool.kt +73 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/SendEncoding.kt +23 -21
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/StateStore.kt +90 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/SubscriptionTypes.kt +88 -24
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ffi/croche_ffi.kt +5723 -3088
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/AppEventSink.kt +34 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/AppStoragePal.kt +96 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/BackgroundOsRegistration.kt +35 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/BackgroundSink.kt +37 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreDefinitionCalls.kt +35 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreFactoryCalls.kt +30 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreOptionsEncoding.kt +41 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreStreamCalls.kt +35 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/ForeignCallbacks.kt +127 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/ImageAdapterHost.kt +28 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/JvmCoreHost.kt +70 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/JvmStateStore.kt +125 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/JvmStoragePal.kt +64 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/LifecycleBinding.kt +18 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/NativeCoreInitialization.kt +21 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/NativePlatform.kt +60 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/PalCallbacks.kt +27 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/PlainToolJson.kt +56 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/PublicCalls.kt +43 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/ScopeJson.kt +29 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/StateStoreContract.kt +103 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/StorageVersionContract.kt +40 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/ToolCompletionEncoding.kt +29 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/AtomicKeyFiles.kt +100 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/BlobFiles.kt +157 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/DirectHttpPal.kt +223 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/InstancePayloadPurge.kt +79 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/VersionedKeyFiles.kt +71 -0
- package/android/vendor/jniLibs/arm64-v8a/libcroche_ffi.so +0 -0
- package/android/vendor/jniLibs/armeabi-v7a/libcroche_ffi.so +0 -0
- package/android/vendor/jniLibs/x86_64/libcroche_ffi.so +0 -0
- package/croche-react-native.podspec +1 -0
- package/dist/package.json +1 -0
- package/dist/react-native/src/NativeCrocheRuntime.d.ts +16 -0
- package/dist/react-native/src/NativeCrocheRuntime.js +2 -0
- package/dist/react-native/src/core-native.d.ts +6 -0
- package/dist/react-native/src/core-native.js +316 -0
- package/dist/react-native/src/core-wire.d.ts +55 -0
- package/dist/react-native/src/core-wire.js +1 -0
- package/dist/react-native/src/native-module.d.ts +8 -0
- package/dist/react-native/src/native-module.js +53 -0
- package/dist/rn-shared-build.json +16 -0
- package/dist/runtime/src/adapters.d.ts +8 -0
- package/dist/runtime/src/adapters.js +29 -0
- package/dist/runtime/src/agent.d.ts +91 -0
- package/dist/runtime/src/agent.js +137 -0
- package/dist/runtime/src/app-api.d.ts +572 -0
- package/dist/runtime/src/app-api.js +1 -0
- package/dist/runtime/src/cancel.d.ts +9 -0
- package/dist/runtime/src/cancel.js +27 -0
- package/dist/runtime/src/core/foreground.d.ts +3 -0
- package/dist/runtime/src/core/foreground.js +40 -0
- package/dist/runtime/src/core/port.d.ts +247 -0
- package/dist/runtime/src/core/port.js +1 -0
- package/dist/runtime/src/core/wasm-owner.d.ts +32 -0
- package/dist/runtime/src/core/wasm-owner.js +237 -0
- package/dist/runtime/src/core/wasm.d.ts +1 -0
- package/dist/runtime/src/core/wasm.js +2 -0
- package/dist/runtime/src/croche.d.ts +97 -0
- package/dist/runtime/src/croche.js +172 -0
- package/dist/runtime/src/errors.d.ts +33 -0
- package/dist/runtime/src/errors.js +63 -0
- package/dist/runtime/src/events.d.ts +5 -0
- package/dist/runtime/src/events.js +31 -0
- package/dist/runtime/src/generated/app-stream.d.ts +328 -0
- package/dist/runtime/src/generated/app-stream.js +127 -0
- package/dist/runtime/src/image-input.d.ts +5 -0
- package/dist/runtime/src/image-input.js +60 -0
- package/dist/runtime/src/index.d.ts +6 -0
- package/dist/runtime/src/index.js +5 -0
- package/dist/runtime/src/index.native.d.ts +1 -0
- package/dist/runtime/src/index.native.js +2 -0
- package/dist/runtime/src/json.d.ts +13 -0
- package/dist/runtime/src/json.js +120 -0
- package/dist/runtime/src/native-adapter.d.ts +3 -0
- package/dist/runtime/src/native-adapter.js +30 -0
- package/dist/runtime/src/pal/host.d.ts +5 -0
- package/dist/runtime/src/pal/host.js +60 -0
- package/dist/runtime/src/pal/platform.d.ts +21 -0
- package/dist/runtime/src/pal/platform.js +7 -0
- package/dist/runtime/src/pal/state-store-lock.d.ts +8 -0
- package/dist/runtime/src/pal/state-store-lock.js +2 -0
- package/dist/runtime/src/pal/state-store.d.ts +66 -0
- package/dist/runtime/src/pal/state-store.js +1 -0
- package/dist/runtime/src/pal/storage-version-contract.d.ts +19 -0
- package/dist/runtime/src/pal/storage-version-contract.js +68 -0
- package/dist/runtime/src/pal/transactional-storage.d.ts +3 -0
- package/dist/runtime/src/pal/transactional-storage.js +124 -0
- package/dist/runtime/src/rn-entry.d.ts +1 -0
- package/dist/runtime/src/rn-entry.js +4 -0
- package/dist/runtime/src/run-tool.d.ts +33 -0
- package/dist/runtime/src/run-tool.js +7 -0
- package/dist/runtime/src/tools.d.ts +35 -0
- package/dist/runtime/src/tools.js +94 -0
- package/ios/CoreAgentTransport.swift +14 -0
- package/ios/CoreDeliveryTransport.swift +58 -0
- package/ios/CoreNativePal.swift +98 -0
- package/ios/CorePlatformTransport.swift +44 -0
- package/ios/CoreWireDispatch.swift +122 -0
- package/ios/CoreWireSupport.swift +286 -0
- package/ios/CrocheRuntimeBridge.swift +34 -994
- package/ios/ProjectPal.swift +49 -0
- package/ios/RNCrocheRuntime.mm +18 -201
- package/ios/vendor/CrocheRuntimeSDK/AppBuildFacts.swift +112 -0
- package/ios/vendor/CrocheRuntimeSDK/BlobFiles.swift +124 -0
- package/ios/vendor/CrocheRuntimeSDK/ContextConfig.swift +60 -0
- package/ios/vendor/CrocheRuntimeSDK/DirectHTTP.swift +258 -0
- package/ios/vendor/CrocheRuntimeSDK/Effects.swift +17 -17
- package/ios/vendor/CrocheRuntimeSDK/EncodedImages.swift +85 -0
- package/ios/vendor/CrocheRuntimeSDK/FFIStreamPort.swift +26 -157
- package/ios/vendor/CrocheRuntimeSDK/GeneratedAppStream.swift +672 -0
- package/ios/vendor/CrocheRuntimeSDK/Host.swift +34 -371
- package/ios/vendor/CrocheRuntimeSDK/ImagePal.swift +410 -0
- package/ios/vendor/CrocheRuntimeSDK/Images.swift +10 -9
- package/ios/vendor/CrocheRuntimeSDK/InstancePayloadPurge.swift +88 -0
- package/ios/vendor/CrocheRuntimeSDK/JSON.swift +30 -14
- package/ios/vendor/CrocheRuntimeSDK/Offload.swift +24 -0
- package/ios/vendor/CrocheRuntimeSDK/OpenOptions.swift +1 -155
- package/ios/vendor/CrocheRuntimeSDK/Platform.swift +33 -59
- package/ios/vendor/CrocheRuntimeSDK/PlatformBackground.swift +289 -0
- package/ios/vendor/CrocheRuntimeSDK/PlatformPal.swift +302 -0
- package/ios/vendor/CrocheRuntimeSDK/PlatformStateStore.swift +253 -0
- package/ios/vendor/CrocheRuntimeSDK/PlatformStorage.swift +281 -0
- package/ios/vendor/CrocheRuntimeSDK/Project.swift +4 -269
- package/ios/vendor/CrocheRuntimeSDK/Runtime.swift +24 -461
- package/ios/vendor/CrocheRuntimeSDK/RuntimeHTTPAdapter.swift +42 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Adapters.swift +110 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Agent.swift +248 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Allowance.swift +20 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1BindingFacts.swift +33 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Core.swift +170 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Croche.swift +313 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Decision.swift +146 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Events.swift +37 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1HandleOwner.swift +58 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Options.swift +346 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1RunTool.swift +89 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Storage.swift +165 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1TestHooks.swift +100 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Tools.swift +278 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Verification.swift +27 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/StateStoreContract.swift +189 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/StorageVersionContract.swift +68 -0
- package/ios/vendor/CrocheRuntimeSDK/Storage.swift +23 -269
- package/ios/vendor/CrocheRuntimeSDK/SubscriptionTypes.swift +163 -116
- package/ios/vendor/CrocheRuntimeSDK/Truncate.swift +12 -0
- package/ios/vendor/CrocheRuntimeSDK/croche_ffi.swift +4712 -2469
- package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64/Headers/croche_ffiFFI.h +899 -608
- package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64/libcroche_ffi.a +0 -0
- package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64_x86_64-simulator/Headers/croche_ffiFFI.h +899 -608
- package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64_x86_64-simulator/libcroche_ffi.a +0 -0
- package/package.json +18 -8
- package/scripts/README.md +11 -0
- package/scripts/build-shared.mjs +46 -0
- package/scripts/build.mjs +11 -0
- package/scripts/check-swift-vendor-modules.sh +15 -0
- package/scripts/vendor-native.sh +8 -6
- package/src/NativeCrocheRuntime.ts +12 -159
- package/android/src/main/java/dev/croche/reactnative/AgentMemory.kt +0 -25
- package/android/src/main/java/dev/croche/reactnative/ProjectAttestation.kt +0 -17
- package/android/src/main/java/dev/croche/reactnative/ProjectTimeZone.kt +0 -14
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/CrocheProjectRecordProvider.kt +0 -32
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/WorkManagerScheduler.kt +0 -146
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/AppStreamBranch.kt +0 -110
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Control.kt +0 -178
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/NativeCoreStreamPort.kt +0 -173
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectBinding.kt +0 -79
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectPalRouting.kt +0 -25
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectPlatform.kt +0 -46
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectRecords.kt +0 -87
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Storage.kt +0 -181
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/StreamHub.kt +0 -227
- package/ios/vendor/CrocheRuntimeSDK/Background.swift +0 -59
- package/ios/vendor/CrocheRuntimeSDK/Control.swift +0 -192
- package/ios/vendor/CrocheRuntimeSDK/StreamHub.swift +0 -453
- package/ios/vendor/CrocheRuntimeSDK/SubscriptionRuntime.swift +0 -38
- package/src/index.ts +0 -664
- package/src/project-types.ts +0 -35
- package/src/project.ts +0 -434
- package/src/protocol.ts +0 -28
- package/src/types.ts +0 -9
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
export const jsonRepresentationErrorCategories = {
|
|
2
|
+
"invalid_configuration": "setup",
|
|
3
|
+
"invalid_input": "invalid",
|
|
4
|
+
"invalid_tool_result": "invalid"
|
|
5
|
+
};
|
|
6
|
+
export const errorCategories = {
|
|
7
|
+
"offline": "offline",
|
|
8
|
+
"network_error": "offline",
|
|
9
|
+
"request_timeout": "offline",
|
|
10
|
+
"gateway_unavailable": "offline",
|
|
11
|
+
"invalid_cloud_response": "offline",
|
|
12
|
+
"stale_control": "offline",
|
|
13
|
+
"http_<status>": "offline",
|
|
14
|
+
"account_credit_exhausted": "allowance",
|
|
15
|
+
"project_budget_exhausted": "allowance",
|
|
16
|
+
"user_allowance_exhausted": "allowance",
|
|
17
|
+
"development_allowance_exhausted": "allowance",
|
|
18
|
+
"unverified_allowance_exhausted": "allowance",
|
|
19
|
+
"gateway_key_exhausted": "allowance",
|
|
20
|
+
"provider_credit_unavailable": "allowance",
|
|
21
|
+
"usage_paused": "paused",
|
|
22
|
+
"runtime_blocked": "paused",
|
|
23
|
+
"project_access_disabled": "paused",
|
|
24
|
+
"account_disabled": "paused",
|
|
25
|
+
"server_key_revoked": "paused",
|
|
26
|
+
"development_key_revoked": "paused",
|
|
27
|
+
"development_device_limit": "paused",
|
|
28
|
+
"rate_limited": "paused",
|
|
29
|
+
"provider_rate_limited": "paused",
|
|
30
|
+
"user_allowance_disabled": "setup",
|
|
31
|
+
"invalid_configuration": "setup",
|
|
32
|
+
"model_missing": "setup",
|
|
33
|
+
"model_withdrawn": "setup",
|
|
34
|
+
"model_unavailable": "setup",
|
|
35
|
+
"project_key_unknown": "setup",
|
|
36
|
+
"server_key_invalid": "setup",
|
|
37
|
+
"development_key_invalid": "setup",
|
|
38
|
+
"user_required": "setup",
|
|
39
|
+
"gateway_key_rejected": "setup",
|
|
40
|
+
"gateway_unsupported": "setup",
|
|
41
|
+
"schema_unsupported": "setup",
|
|
42
|
+
"capability_unsupported": "setup",
|
|
43
|
+
"invalid_snapshot": "setup",
|
|
44
|
+
"snapshot_mismatch": "setup",
|
|
45
|
+
"invalid_tool": "setup",
|
|
46
|
+
"invalid_wiki": "setup",
|
|
47
|
+
"installation_unverified": "setup",
|
|
48
|
+
"attestation_required": "setup",
|
|
49
|
+
"attestation_rejected": "setup",
|
|
50
|
+
"attestation_unverifiable": "setup",
|
|
51
|
+
"attestation_failed": "setup",
|
|
52
|
+
"attestation_unavailable": "setup",
|
|
53
|
+
"attestation_unsupported": "setup",
|
|
54
|
+
"attestation_timeout": "setup",
|
|
55
|
+
"recovery_required": "setup",
|
|
56
|
+
"host_unavailable": "setup",
|
|
57
|
+
"core_unavailable": "setup",
|
|
58
|
+
"state_conflict": "closed",
|
|
59
|
+
"outcome_unknown": "closed",
|
|
60
|
+
"closed": "closed",
|
|
61
|
+
"target_closed": "closed",
|
|
62
|
+
"runtime_detached": "closed",
|
|
63
|
+
"cancelled": "closed",
|
|
64
|
+
"interrupted": "closed",
|
|
65
|
+
"preempted": "closed",
|
|
66
|
+
"aborted": "closed",
|
|
67
|
+
"observation_lost": "closed",
|
|
68
|
+
"store_busy": "closed",
|
|
69
|
+
"instance_busy": "closed",
|
|
70
|
+
"invalid_input": "invalid",
|
|
71
|
+
"input_too_large": "invalid",
|
|
72
|
+
"invalid_memory": "invalid",
|
|
73
|
+
"invalid_response_format": "invalid",
|
|
74
|
+
"invalid_request": "invalid",
|
|
75
|
+
"tool_unauthorized": "invalid",
|
|
76
|
+
"agent_conflict": "invalid",
|
|
77
|
+
"unknown_id": "invalid",
|
|
78
|
+
"attachment_storage_full": "invalid",
|
|
79
|
+
"idempotency_conflict": "invalid",
|
|
80
|
+
"identity_conflict": "invalid",
|
|
81
|
+
"busy": "invalid",
|
|
82
|
+
"queue_full": "invalid",
|
|
83
|
+
"cursor_reset": "invalid",
|
|
84
|
+
"context_limit": "invalid",
|
|
85
|
+
"output_limit": "invalid",
|
|
86
|
+
"iteration_limit": "invalid",
|
|
87
|
+
"structured_output_unsupported": "invalid",
|
|
88
|
+
"failure_unrecorded": "internal",
|
|
89
|
+
"internal": "internal",
|
|
90
|
+
"asset_read_failed": "internal",
|
|
91
|
+
"stream_incomplete": "internal",
|
|
92
|
+
"provider_error": "internal",
|
|
93
|
+
"provider_rejected": "internal",
|
|
94
|
+
"invalid_provider_response": "internal",
|
|
95
|
+
"invalid_response": "internal",
|
|
96
|
+
"output_too_large": "internal",
|
|
97
|
+
"output_invalid": "internal",
|
|
98
|
+
"empty_response": "internal",
|
|
99
|
+
"unexpected_tool_call": "internal",
|
|
100
|
+
"storage_error": "internal",
|
|
101
|
+
"store_refused": "internal",
|
|
102
|
+
"store_full": "internal",
|
|
103
|
+
"corrupt_store": "internal",
|
|
104
|
+
"store_too_new": "internal",
|
|
105
|
+
"fresh_reservation_lost": "internal",
|
|
106
|
+
"archive_unavailable": "internal",
|
|
107
|
+
"archive_error": "internal",
|
|
108
|
+
"host_error": "internal",
|
|
109
|
+
"host_unresponsive": "internal",
|
|
110
|
+
"thread_unavailable": "internal",
|
|
111
|
+
"core_error": "internal",
|
|
112
|
+
"invalid_abi": "internal",
|
|
113
|
+
"no_lock": "internal",
|
|
114
|
+
"handler_failed": "internal",
|
|
115
|
+
"subscriber_overflow": "internal"
|
|
116
|
+
};
|
|
117
|
+
export function errorCategory(code) { return /^http_[1-5][0-9]{2}$/.test(code) ? 'offline' : (Object.hasOwn(errorCategories, code) ? errorCategories[code] : 'internal'); }
|
|
118
|
+
const knownEventTypes = new Set(["input", "input.dropped", "message.start", "message.delta", "message.end", "turn", "tool", "state", "snapshot", "page", "cleared", "memory", "gap", "error", "replaced"]);
|
|
119
|
+
export function decodeAgentEvent(value) {
|
|
120
|
+
if (value === null || Array.isArray(value) || typeof value !== 'object' || typeof value.type !== 'string')
|
|
121
|
+
throw new TypeError('An app event must have a string type.');
|
|
122
|
+
if (!knownEventTypes.has(value.type))
|
|
123
|
+
return { type: 'unknown', originalType: value.type, fields: value };
|
|
124
|
+
if (value.type === 'page' && Array.isArray(value.messages))
|
|
125
|
+
return { ...value, messages: value.messages.map(decodeAgentEvent) };
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CoreAttachmentInput } from './core/port.js';
|
|
2
|
+
/** Preserve the strict serializer's refusal for non-JSON values. For JSON image
|
|
3
|
+
* elements, move only valid base64 bytes beside the JSON, indexed by position.
|
|
4
|
+
* The caller's objects and every other member are left unchanged. */
|
|
5
|
+
export declare function imageInput(input: unknown): [string, CoreAttachmentInput[]];
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { jsonText } from './json.js';
|
|
2
|
+
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
3
|
+
const digits = new Int16Array(128).fill(-1);
|
|
4
|
+
for (let i = 0; i < alphabet.length; i++)
|
|
5
|
+
digits[alphabet.charCodeAt(i)] = i;
|
|
6
|
+
/** Standard padded base64, matching Core's decoder. Invalid encodings stay in
|
|
7
|
+
* JSON so Core supplies the refusal; this function never chooses an app error. */
|
|
8
|
+
function bytesFromBase64(data) {
|
|
9
|
+
if (data.length % 4 !== 0)
|
|
10
|
+
return undefined;
|
|
11
|
+
const padding = data.endsWith('==') ? 2 : data.endsWith('=') ? 1 : 0;
|
|
12
|
+
const end = data.length - padding;
|
|
13
|
+
for (let i = 0; i < end; i++) {
|
|
14
|
+
const code = data.charCodeAt(i);
|
|
15
|
+
if (code >= digits.length || digits[code] < 0)
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
if (padding && (end < 2 || (digits[data.charCodeAt(end - 1)] & (padding === 2 ? 15 : 3)) !== 0))
|
|
19
|
+
return undefined;
|
|
20
|
+
const bytes = new Uint8Array(data.length / 4 * 3 - padding);
|
|
21
|
+
let bits = 0, count = 0, offset = 0;
|
|
22
|
+
for (let i = 0; i < end; i++) {
|
|
23
|
+
bits = (bits << 6) | digits[data.charCodeAt(i)];
|
|
24
|
+
count += 6;
|
|
25
|
+
if (count >= 8) {
|
|
26
|
+
count -= 8;
|
|
27
|
+
bytes[offset++] = (bits >>> count) & 255;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return bytes;
|
|
31
|
+
}
|
|
32
|
+
/** Preserve the strict serializer's refusal for non-JSON values. For JSON image
|
|
33
|
+
* elements, move only valid base64 bytes beside the JSON, indexed by position.
|
|
34
|
+
* The caller's objects and every other member are left unchanged. */
|
|
35
|
+
export function imageInput(input) {
|
|
36
|
+
const raw = jsonText(input);
|
|
37
|
+
let value;
|
|
38
|
+
try {
|
|
39
|
+
value = JSON.parse(raw);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return [raw, []];
|
|
43
|
+
}
|
|
44
|
+
if (value === null || typeof value !== 'object' || !Array.isArray(value.input))
|
|
45
|
+
return [raw, []];
|
|
46
|
+
const images = [];
|
|
47
|
+
value.input.forEach((part, element) => {
|
|
48
|
+
if (part === null || typeof part !== 'object' || Array.isArray(part))
|
|
49
|
+
return;
|
|
50
|
+
const item = part;
|
|
51
|
+
if (item.type !== 'image' || typeof item.data !== 'string' || Object.hasOwn(item, 'uri'))
|
|
52
|
+
return;
|
|
53
|
+
const bytes = bytesFromBase64(item.data);
|
|
54
|
+
if (bytes === undefined)
|
|
55
|
+
return;
|
|
56
|
+
images.push({ element, bytes });
|
|
57
|
+
delete item.data;
|
|
58
|
+
});
|
|
59
|
+
return images.length ? [JSON.stringify(value), images] : [raw, []];
|
|
60
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Croche } from './croche.js';
|
|
2
|
+
export { Agent } from './agent.js';
|
|
3
|
+
export { defineTool, toolResult, ToolError, tools } from './tools.js';
|
|
4
|
+
export { CrocheError } from './errors.js';
|
|
5
|
+
export type { Adapter, BlobListPage, BlobStore, ImageAdapter, ImageSupport, ImageInfo, ImageResizeLimits, StateStore, StateCommitResult, StateCondition, StateEntry, StateListOptions, StateOp, StatePage, StateValue, RunToolResult, DecideInput, DecisionQuestion, DecisionConfidence, DecisionAnswer, DecisionResult, Attachment, BackgroundOptions, CrocheDebugger, DeleteScope, DeliverDueResult, SubscribeOptions, WakeTimes, AgentEvent, AgentOptions, RequestResult, SendReceipt, EventError, BackgroundEvent, DebugAttachOptions, AttachedDebugger, DebugCapability, ErrorCategory, ImageInput, InputDisposition, Json, ListOptions, MemoryItem, MessageEnd, OpenOptions, Page, PlatformHandle, ResponseFormat, SendInput, SendOptions, Subscription, TextInput, ToolArg, ToolCall, ToolContent, ToolContext, ToolDefinition, ToolEntryOptions, ToolExecute, ToolManifest, ToolRegistration, ToolResult, ToolScope, Verification, WikiDoc, WikiScope, } from './app-api.js';
|
|
6
|
+
export type { InputKind, MessageStatus, AgentStatus, TurnPurpose, MemoryOp, InputEvent, InputDropped, MessageStart, MessageDelta, TurnEvent, ToolEvent, StateEvent, SnapshotEvent, PageEvent, ClearedEvent, MemoryEvent, GapEvent, SubscriptionError, ReplacedEvent, } from './generated/app-stream.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Shared App API exports. The Node, workerd and native entries select their own PAL.
|
|
2
|
+
export { Croche } from './croche.js';
|
|
3
|
+
export { Agent } from './agent.js';
|
|
4
|
+
export { defineTool, toolResult, ToolError, tools } from './tools.js';
|
|
5
|
+
export { CrocheError } from './errors.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `value` as JSON text; when it has no JSON form, a non-JSON text naming the value and its path, which Core
|
|
3
|
+
* refuses with the code of the slot it is handed in.
|
|
4
|
+
*/
|
|
5
|
+
export declare function jsonText(value: unknown, path?: string): string;
|
|
6
|
+
/** `value` as JSON text, or undefined when it has no JSON form (a tool result: the bridge hands Core the fact). */
|
|
7
|
+
export declare function encodable(value: unknown): string | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Serializes a method's options object. The ONE relaxation: a top-level option whose value is `undefined` is
|
|
10
|
+
* omitted (it is a TS optional). Everything below the top level goes through `jsonText`, so
|
|
11
|
+
* `{tools: [{tool: 'x', bind: undefined}]}` reaches Core as non-JSON text. `undefined` options = no options.
|
|
12
|
+
*/
|
|
13
|
+
export declare function optionsText(options: unknown): string | undefined;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// The JSON serializer: the ONLY thing the TS SDK does with an app value (docs/APP-API.md: "every value the app
|
|
2
|
+
// gives is passed to Core UNCHANGED as JSON"). It writes exactly null, booleans, finite numbers, strings, dense arrays
|
|
3
|
+
// and plain objects, and never drops a key or rewrites a value. A value with no JSON form (undefined at any depth, a
|
|
4
|
+
// cycle, NaN/Infinity, a function, a bigint, a symbol, a non-plain object) is NOT refused here: the SDK chooses no
|
|
5
|
+
// code. It hands Core a non-JSON text in that argument's slot, and Core's refusal for the slot supplies the code
|
|
6
|
+
// (Keel's unencodable-value ruling, 2026-10-30). Value policy (e.g. integers outside ±(2^53-1)) is Core's too.
|
|
7
|
+
/** Thrown inside the writer only; it carries the non-JSON text that names the value. */
|
|
8
|
+
class Unencodable {
|
|
9
|
+
text;
|
|
10
|
+
constructor(text) {
|
|
11
|
+
this.text = text;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const IDENT = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
15
|
+
function member(path, key) {
|
|
16
|
+
return IDENT.test(key) ? `${path}.${key}` : `${path}[${JSON.stringify(key)}]`;
|
|
17
|
+
}
|
|
18
|
+
function isPlainObject(value) {
|
|
19
|
+
if (Object.prototype.toString.call(value) !== '[object Object]')
|
|
20
|
+
return false;
|
|
21
|
+
const proto = Object.getPrototypeOf(value);
|
|
22
|
+
// null-prototype, or this realm's / another realm's Object.prototype (whose own prototype is null).
|
|
23
|
+
return proto === null || Object.getPrototypeOf(proto) === null;
|
|
24
|
+
}
|
|
25
|
+
function encode(value, path) {
|
|
26
|
+
// The text starts with `$`, so it is never JSON; it names the first value with no JSON form and its path.
|
|
27
|
+
const fail = (at, what) => {
|
|
28
|
+
throw new Unencodable(`${at}: ${what} is not JSON`);
|
|
29
|
+
};
|
|
30
|
+
const ancestors = new Set();
|
|
31
|
+
const write = (v, at) => {
|
|
32
|
+
switch (typeof v) {
|
|
33
|
+
case 'string': return JSON.stringify(v);
|
|
34
|
+
case 'boolean': return v ? 'true' : 'false';
|
|
35
|
+
case 'number':
|
|
36
|
+
if (!Number.isFinite(v))
|
|
37
|
+
return fail(at, String(v));
|
|
38
|
+
return JSON.stringify(v);
|
|
39
|
+
case 'undefined': return fail(at, 'undefined (use null, or leave the key out)');
|
|
40
|
+
case 'function': return fail(at, 'a function');
|
|
41
|
+
case 'bigint': return fail(at, 'a bigint (pass it as a string)');
|
|
42
|
+
case 'symbol': return fail(at, 'a symbol');
|
|
43
|
+
}
|
|
44
|
+
if (v === null)
|
|
45
|
+
return 'null';
|
|
46
|
+
const obj = v;
|
|
47
|
+
if (ancestors.has(obj))
|
|
48
|
+
return fail(at, 'a cycle');
|
|
49
|
+
ancestors.add(obj);
|
|
50
|
+
let out;
|
|
51
|
+
if (Array.isArray(obj)) {
|
|
52
|
+
const parts = [];
|
|
53
|
+
for (let i = 0; i < obj.length; i++) {
|
|
54
|
+
if (!(i in obj))
|
|
55
|
+
fail(`${at}[${i}]`, 'an array hole');
|
|
56
|
+
parts.push(write(obj[i], `${at}[${i}]`));
|
|
57
|
+
}
|
|
58
|
+
out = `[${parts.join(',')}]`;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
if (!isPlainObject(obj))
|
|
62
|
+
fail(at, `a ${obj.constructor?.name ?? 'non-plain'} object`);
|
|
63
|
+
if (Object.getOwnPropertySymbols(obj).length > 0)
|
|
64
|
+
fail(at, 'a symbol-keyed property');
|
|
65
|
+
const parts = [];
|
|
66
|
+
for (const key of Object.keys(obj)) {
|
|
67
|
+
parts.push(`${JSON.stringify(key)}:${write(obj[key], member(at, key))}`);
|
|
68
|
+
}
|
|
69
|
+
out = `{${parts.join(',')}}`;
|
|
70
|
+
}
|
|
71
|
+
ancestors.delete(obj);
|
|
72
|
+
return out;
|
|
73
|
+
};
|
|
74
|
+
return write(value, path);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* `value` as JSON text; when it has no JSON form, a non-JSON text naming the value and its path, which Core
|
|
78
|
+
* refuses with the code of the slot it is handed in.
|
|
79
|
+
*/
|
|
80
|
+
export function jsonText(value, path = '$') {
|
|
81
|
+
try {
|
|
82
|
+
return encode(value, path);
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
if (error instanceof Unencodable)
|
|
86
|
+
return error.text;
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/** `value` as JSON text, or undefined when it has no JSON form (a tool result: the bridge hands Core the fact). */
|
|
91
|
+
export function encodable(value) {
|
|
92
|
+
try {
|
|
93
|
+
return encode(value, '$');
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
if (error instanceof Unencodable)
|
|
97
|
+
return undefined;
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Serializes a method's options object. The ONE relaxation: a top-level option whose value is `undefined` is
|
|
103
|
+
* omitted (it is a TS optional). Everything below the top level goes through `jsonText`, so
|
|
104
|
+
* `{tools: [{tool: 'x', bind: undefined}]}` reaches Core as non-JSON text. `undefined` options = no options.
|
|
105
|
+
*/
|
|
106
|
+
export function optionsText(options) {
|
|
107
|
+
if (options === undefined)
|
|
108
|
+
return undefined;
|
|
109
|
+
if (options === null || typeof options !== 'object' || Array.isArray(options) || !isPlainObject(options)
|
|
110
|
+
|| Object.getOwnPropertySymbols(options).length > 0) {
|
|
111
|
+
return jsonText(options); // not a plain options object: Core judges it
|
|
112
|
+
}
|
|
113
|
+
const kept = Object.create(null);
|
|
114
|
+
for (const key of Object.keys(options)) {
|
|
115
|
+
const v = options[key];
|
|
116
|
+
if (v !== undefined)
|
|
117
|
+
kept[key] = v;
|
|
118
|
+
}
|
|
119
|
+
return jsonText(kept);
|
|
120
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { captureReadVersioned, captureWriteIf } from '../../runtime/src/pal/storage-version-contract.js';
|
|
2
|
+
// Compiled at the canonical facade source root; it imports the RN adapter, not
|
|
3
|
+
// another facade or the web/WASM loader. Every source file stays single-owned.
|
|
4
|
+
import { createNativeCore, createNativeImageAdapter } from '../../react-native/src/core-native.js';
|
|
5
|
+
import { nativeWire, nativeCall, nativeSync, nativeHTTP, nativeStorageCall } from '../../react-native/src/native-module.js';
|
|
6
|
+
const storage = {
|
|
7
|
+
listState: (prefix, options) => nativeStorageCall('listState', [prefix, options]),
|
|
8
|
+
commit: (ops, condition) => nativeStorageCall('commit', [ops, condition]),
|
|
9
|
+
readVersioned: key => { const request = captureReadVersioned(key); return nativeStorageCall('readVersioned', [request.key]).then(request.decode); },
|
|
10
|
+
writeIf: (key, value, expect) => { const request = captureWriteIf(key, value, expect); return nativeStorageCall('writeIf', [request.key, request.value, request.expect]).then(request.decode); },
|
|
11
|
+
read: key => nativeStorageCall('read', [key]), write: (key, value) => nativeStorageCall('write', [key, value]),
|
|
12
|
+
purgeInstance: (prefix, credentialKey) => nativeStorageCall('purgeInstance', [prefix, credentialKey ?? null]),
|
|
13
|
+
remove: key => nativeStorageCall('remove', [key]), list: prefix => nativeStorageCall('list', [prefix]),
|
|
14
|
+
lock: name => nativeStorageCall('lock', [name]), unlock: name => nativeStorageCall('unlock', [name]),
|
|
15
|
+
secrets: { read: key => nativeStorageCall('readSecret', [key]), write: (key, value) => nativeStorageCall('writeSecret', [key, value]), remove: key => nativeStorageCall('removeSecret', [key]) },
|
|
16
|
+
};
|
|
17
|
+
const module = createNativeCore(nativeWire, storage);
|
|
18
|
+
export const coreModule = () => module;
|
|
19
|
+
const bytes = async (method, args) => new Uint8Array(await nativeCall(method, args));
|
|
20
|
+
export const nativePlatform = {
|
|
21
|
+
defaultStorage: () => storage,
|
|
22
|
+
nativeBlobs: true,
|
|
23
|
+
credentialStorage: storage.secrets,
|
|
24
|
+
platformFacts: () => nativeSync('platformFacts'),
|
|
25
|
+
readAsset: async (path) => { const value = await nativeCall('readAsset', [path]); return value === null ? null : new Uint8Array(value); },
|
|
26
|
+
readImage: (uri, maxBytes) => bytes('readImage', [uri, maxBytes]),
|
|
27
|
+
resolve: (host) => nativeCall('resolve', [host]),
|
|
28
|
+
http: nativeHTTP,
|
|
29
|
+
image: () => createNativeImageAdapter(nativeWire),
|
|
30
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BlobStore, PlatformHandle, StateStore, ImageAdapter } from '../app-api.js';
|
|
2
|
+
import type { CoreHost, CoreStoragePal } from '../core/port.js';
|
|
3
|
+
/** The app's storage, unchanged, or the platform default (Core has no default of its own). */
|
|
4
|
+
export declare function storageFor(storage: StateStore | undefined): CoreStoragePal;
|
|
5
|
+
export declare function createHost(handle: PlatformHandle | undefined, suppliedImage?: ImageAdapter, suppliedBlobs?: BlobStore): CoreHost;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { platform } from './platform.js';
|
|
2
|
+
import { CrocheError, HostError } from '../errors.js';
|
|
3
|
+
import { signalFor } from '../cancel.js';
|
|
4
|
+
import { transactionalStorage } from './transactional-storage.js';
|
|
5
|
+
/** The app's storage, unchanged, or the platform default (Core has no default of its own). */
|
|
6
|
+
export function storageFor(storage) {
|
|
7
|
+
const host = platform();
|
|
8
|
+
return storage === undefined
|
|
9
|
+
? host.defaultStorage()
|
|
10
|
+
: transactionalStorage(storage, host.credentialStorage);
|
|
11
|
+
}
|
|
12
|
+
export function createHost(handle, suppliedImage, suppliedBlobs) {
|
|
13
|
+
const pal = platform();
|
|
14
|
+
const blobs = suppliedBlobs ?? pal.defaultBlobs?.();
|
|
15
|
+
if (!blobs && !pal.nativeBlobs) {
|
|
16
|
+
throw new CrocheError('invalid_configuration', 'A BlobStore is required. Pass one in adapters, e.g. a BlobStore backed by an R2 bucket on Workers.', 'setup');
|
|
17
|
+
}
|
|
18
|
+
const image = suppliedImage ?? pal.image();
|
|
19
|
+
const purgeBlobStaging = blobs && pal.blobStagingPurge?.(blobs);
|
|
20
|
+
let timer;
|
|
21
|
+
return {
|
|
22
|
+
...(blobs && {
|
|
23
|
+
blobGet: blobs.get.bind(blobs),
|
|
24
|
+
blobPut: blobs.put.bind(blobs),
|
|
25
|
+
blobDelete: blobs.delete.bind(blobs),
|
|
26
|
+
blobList: blobs.list.bind(blobs),
|
|
27
|
+
}),
|
|
28
|
+
...(purgeBlobStaging && { blobPurgeStaging: purgeBlobStaging }),
|
|
29
|
+
readAsset: path => pal.readAsset(path),
|
|
30
|
+
http: (request, sink, cancel) => pal.http(request, sink, cancel),
|
|
31
|
+
resolve: (host, cancel) => pal.resolve(host, cancel),
|
|
32
|
+
nowMs: () => Date.now(),
|
|
33
|
+
utcOffsetMinutes: atMs => -new Date(atMs).getTimezoneOffset(),
|
|
34
|
+
// Node tracks foreground sleeps. Idle timers alone never hold the process open.
|
|
35
|
+
sleep: pal.sleep ?? (ms => new Promise(resolve => { setTimeout(resolve, ms).unref?.(); })),
|
|
36
|
+
wake(atMs, onWake) {
|
|
37
|
+
clearTimeout(timer);
|
|
38
|
+
timer = undefined;
|
|
39
|
+
if (atMs === null || typeof onWake !== 'function')
|
|
40
|
+
return;
|
|
41
|
+
timer = setTimeout(() => { timer = undefined; onWake(); }, Math.max(0, atMs - Date.now()));
|
|
42
|
+
timer.unref?.();
|
|
43
|
+
},
|
|
44
|
+
random: () => crypto.randomUUID(),
|
|
45
|
+
platformFacts: () => pal.platformFacts(), // the platform's own facts, locale included (absent, never defaulted)
|
|
46
|
+
platform: handle,
|
|
47
|
+
readImage: (request, cancel) => pal.readImage(request.source.uri, request.maxBytes, cancel),
|
|
48
|
+
imageSupport: () => image?.support,
|
|
49
|
+
async imageOperation(operation, bytes, options, cancel) {
|
|
50
|
+
if (!image)
|
|
51
|
+
throw new HostError('image_unsupported', 'No image adapter is registered.');
|
|
52
|
+
const signal = signalFor(cancel);
|
|
53
|
+
if (operation === 'info')
|
|
54
|
+
return { info: await image.info(bytes, { signal }) };
|
|
55
|
+
if (operation === 'resize')
|
|
56
|
+
return { bytes: await image.resize(bytes, options, { signal }) };
|
|
57
|
+
throw new HostError('image_unsupported', 'The image operation is not supported.');
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ImageAdapter, BlobStore } from '../app-api.js';
|
|
2
|
+
import type { CoreBodySink, CoreCancel, CoreHttpRequest, CoreStoragePal, PlatformFacts } from '../core/port.js';
|
|
3
|
+
export interface Platform {
|
|
4
|
+
/** The §2a storage this platform ships, used when the app passes none. */
|
|
5
|
+
defaultStorage(): CoreStoragePal;
|
|
6
|
+
credentialStorage?: CoreStoragePal['secrets'];
|
|
7
|
+
defaultBlobs?(): BlobStore;
|
|
8
|
+
/** The native transport supplies its own BlobStore when JS passes none. */
|
|
9
|
+
nativeBlobs?: true;
|
|
10
|
+
blobStagingPurge?(store: BlobStore): ((prefix: string) => Promise<void>) | undefined;
|
|
11
|
+
http(request: CoreHttpRequest, sink: CoreBodySink, cancel: CoreCancel): Promise<void>;
|
|
12
|
+
resolve(host: string, cancel: CoreCancel): Promise<string[]>;
|
|
13
|
+
readAsset(path: string): Promise<Uint8Array | null>;
|
|
14
|
+
readImage(uri: string, maxBytes: number, cancel: CoreCancel): Promise<Uint8Array>;
|
|
15
|
+
sleep?(ms: number): Promise<void>;
|
|
16
|
+
image(): ImageAdapter | undefined;
|
|
17
|
+
/** Build facts the platform knows natively (RN Android: a release build). Never inferred. */
|
|
18
|
+
platformFacts(): PlatformFacts;
|
|
19
|
+
}
|
|
20
|
+
export declare function usePlatform(platform: Platform): void;
|
|
21
|
+
export declare function platform(): Platform;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { StateStore } from './state-store.js';
|
|
2
|
+
type StoreLock = {
|
|
3
|
+
lock(name: string): Promise<'acquired' | 'held'>;
|
|
4
|
+
unlock(name: string): Promise<void>;
|
|
5
|
+
verify?(key: string): Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare const builtinStateLocks: WeakMap<StateStore, StoreLock>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** Stored value together with the version used for a conditional commit. */
|
|
2
|
+
export interface StateValue {
|
|
3
|
+
/** String value returned for the key. */
|
|
4
|
+
value: string;
|
|
5
|
+
/** Opaque version for the observed value. */
|
|
6
|
+
version: string;
|
|
7
|
+
}
|
|
8
|
+
/** Key and value returned by a state range read. */
|
|
9
|
+
export interface StateEntry {
|
|
10
|
+
/** Full stored key. */
|
|
11
|
+
key: string;
|
|
12
|
+
/** String value associated with this key. */
|
|
13
|
+
value: string;
|
|
14
|
+
}
|
|
15
|
+
/** Bounds and continuation for a StateStore prefix read. */
|
|
16
|
+
export interface StateListOptions {
|
|
17
|
+
/** Inclusive lower bound on full keys within the prefix. */
|
|
18
|
+
start?: string;
|
|
19
|
+
/** Use descending UTF-8 key order. The start bound is still a lower bound. */
|
|
20
|
+
reverse?: boolean;
|
|
21
|
+
/** Positive page limit up to 128. Omit to use 128. */
|
|
22
|
+
limit?: number;
|
|
23
|
+
/** Opaque continuation from a page for the same prefix, start and direction. */
|
|
24
|
+
cursor?: string;
|
|
25
|
+
}
|
|
26
|
+
/** One bounded page of stored entries. */
|
|
27
|
+
export interface StatePage {
|
|
28
|
+
/** Entries in the order requested for the range. */
|
|
29
|
+
entries: StateEntry[];
|
|
30
|
+
/** Opaque continuation if another page is available. A short page may still have a cursor. */
|
|
31
|
+
nextCursor?: string;
|
|
32
|
+
}
|
|
33
|
+
/** One put or delete in a conditional state batch. */
|
|
34
|
+
export type StateOp = {
|
|
35
|
+
type: 'put';
|
|
36
|
+
key: string;
|
|
37
|
+
value: string;
|
|
38
|
+
} | {
|
|
39
|
+
type: 'delete';
|
|
40
|
+
key: string;
|
|
41
|
+
};
|
|
42
|
+
/** Version check that guards an atomic state commit. */
|
|
43
|
+
export interface StateCondition {
|
|
44
|
+
/** Key checked before committing the batch. */
|
|
45
|
+
key: string;
|
|
46
|
+
/** Expected version, or null to require the key to be absent. */
|
|
47
|
+
version: string | null;
|
|
48
|
+
}
|
|
49
|
+
/** Outcome of comparing a state version and applying a write batch. */
|
|
50
|
+
export type StateCommitResult = {
|
|
51
|
+
type: 'committed';
|
|
52
|
+
version: string | null;
|
|
53
|
+
} | {
|
|
54
|
+
type: 'conflict';
|
|
55
|
+
};
|
|
56
|
+
/** Host-provided store for range reads and atomic conditional state commits. */
|
|
57
|
+
export interface StateStore {
|
|
58
|
+
/** Host adapter tag for state storage. */
|
|
59
|
+
readonly kind: 'state';
|
|
60
|
+
/** Read saved state so a user can continue where they left off. */
|
|
61
|
+
get(key: string): Promise<StateValue | null>;
|
|
62
|
+
/** Load just the relevant records so a long conversation still opens promptly. */
|
|
63
|
+
list(prefix: string, options?: StateListOptions): Promise<StatePage>;
|
|
64
|
+
/** Keep a saved reply and its related progress consistent if the app stops mid-write. */
|
|
65
|
+
commit(ops: readonly StateOp[], condition: StateCondition): Promise<StateCommitResult>;
|
|
66
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { StorageVersion, VersionedValue, WriteOutcome } from '../app-api.js';
|
|
2
|
+
export type { StorageVersion, VersionedValue, WriteOutcome } from '../app-api.js';
|
|
3
|
+
export interface VersionedStorageCallbacks {
|
|
4
|
+
readVersioned(key: string): Promise<VersionedValue>;
|
|
5
|
+
writeIf(key: string, value: string | null, expect: StorageVersion | null): Promise<WriteOutcome>;
|
|
6
|
+
}
|
|
7
|
+
export declare function decodeVersionedValue(result: unknown): VersionedValue;
|
|
8
|
+
/** Capture the logical read key before a callback is invoked. */
|
|
9
|
+
export declare function captureReadVersioned(key: unknown): Readonly<{
|
|
10
|
+
key: string;
|
|
11
|
+
decode: typeof decodeVersionedValue;
|
|
12
|
+
}>;
|
|
13
|
+
/** Validate before handoff and close over THIS request's primitive values. */
|
|
14
|
+
export declare function captureWriteIf(key: unknown, value: unknown, expect: unknown): Readonly<{
|
|
15
|
+
key: string;
|
|
16
|
+
value: string | null;
|
|
17
|
+
expect: string | null;
|
|
18
|
+
decode(result: unknown): WriteOutcome;
|
|
19
|
+
}>;
|