@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,49 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
/// Every effect, including process-wide OS registration, delegates unchanged to
|
|
4
|
+
/// S6. RN must never install a competing BGTaskScheduler launch handler.
|
|
5
|
+
final class RNProjectPal: HostPal, @unchecked Sendable {
|
|
6
|
+
private let base: any HostPal
|
|
7
|
+
private let image: RNImageCallback?
|
|
8
|
+
private let blobs: RNBlobCallback?
|
|
9
|
+
init(_ base: any HostPal, image: RNImageCallback? = nil, blobs: RNBlobCallback? = nil) {
|
|
10
|
+
self.base = base; self.image = image; self.blobs = blobs
|
|
11
|
+
}
|
|
12
|
+
func blobOperation(operation: String, key: String, cursor: String?, bytes: Data?) throws -> PalBlobReply {
|
|
13
|
+
if let blobs { return try blobs.call(operation, key, cursor, bytes) }
|
|
14
|
+
return try base.blobOperation(operation: operation, key: key, cursor: cursor, bytes: bytes)
|
|
15
|
+
}
|
|
16
|
+
func streamPlatform() -> HostStreamPlatform { base.streamPlatform() }
|
|
17
|
+
func imageSupport() -> String? { if let image { return image.support }; return base.imageSupport() }
|
|
18
|
+
func imageOperation(operation: String, bytes: Data, optionsJson: String, cancel: CancelToken) throws -> PalImageReply {
|
|
19
|
+
if let image { return try image.call(operation, bytes, optionsJson, cancel) }
|
|
20
|
+
return try base.imageOperation(operation: operation, bytes: bytes, optionsJson: optionsJson, cancel: cancel)
|
|
21
|
+
}
|
|
22
|
+
func readImage(request: PalImageReadRequest, cancel: CancelToken) throws -> Data { try base.readImage(request: request, cancel: cancel) }
|
|
23
|
+
func releaseImage(capture: String) { base.releaseImage(capture: capture) }
|
|
24
|
+
func http(request: PalHttpRequest, sink: HttpSink, cancel: CancelToken) throws { try base.http(request: request, sink: sink, cancel: cancel) }
|
|
25
|
+
func resolve(host: String, cancel: CancelToken) throws -> [String] { try base.resolve(host: host, cancel: cancel) }
|
|
26
|
+
func platformFacts() -> PalPlatformFacts { base.platformFacts() }
|
|
27
|
+
func readAsset(path: String) throws -> Data? { try base.readAsset(path: path) }
|
|
28
|
+
func list(prefix: String) throws -> [String] { try base.list(prefix: prefix) }
|
|
29
|
+
func read(key: String) throws -> String? { try base.read(key: key) }
|
|
30
|
+
func write(key: String, value: String) throws { try base.write(key: key, value: value) }
|
|
31
|
+
func readSecret(key: String) throws -> String? { try base.readSecret(key: key) }
|
|
32
|
+
func writeSecret(key: String, value: String) throws { try base.writeSecret(key: key, value: value) }
|
|
33
|
+
func remove(key: String) throws { try base.remove(key: key) }
|
|
34
|
+
func purgeInstance(prefix: String) throws { try base.purgeInstance(prefix: prefix) }
|
|
35
|
+
func removeSecret(key: String) throws { try base.removeSecret(key: key) }
|
|
36
|
+
func lock(key: String) throws -> PalLockOutcome { try base.lock(key: key) }
|
|
37
|
+
func unlock(key: String) throws { try base.unlock(key: key) }
|
|
38
|
+
func storeIdentity() -> String { base.storeIdentity() }
|
|
39
|
+
func tool(invocation: String, cancel: CancelToken) throws -> ToolOutput { try base.tool(invocation: invocation, cancel: cancel) }
|
|
40
|
+
func attest(request: String, timeoutMs: UInt64) throws -> String { try base.attest(request: request, timeoutMs: timeoutMs) }
|
|
41
|
+
func nowMs() -> Double { base.nowMs() }
|
|
42
|
+
func utcOffsetMinutes(atMs: Double) -> Int64 { base.utcOffsetMinutes(atMs: atMs) }
|
|
43
|
+
func random() -> String { base.random() }
|
|
44
|
+
func wake(atMs: Double?) { base.wake(atMs: atMs) }
|
|
45
|
+
func schedule(entries: String) throws { try base.schedule(entries: entries) }
|
|
46
|
+
func registerBackground(identifier: String, wake: CoreBackgroundWake) throws {
|
|
47
|
+
try base.registerBackground(identifier: identifier, wake: wake)
|
|
48
|
+
}
|
|
49
|
+
}
|
package/ios/RNCrocheRuntime.mm
CHANGED
|
@@ -1,221 +1,38 @@
|
|
|
1
|
-
// TurboModule entry point (New Architecture). Forwards to the Swift CrocheRuntimeBridge and
|
|
2
|
-
// emits the single `CrocheRuntimeEvent` stream.
|
|
3
1
|
#import <React/RCTEventEmitter.h>
|
|
4
2
|
#import <CrocheRuntimeSpec/CrocheRuntimeSpec.h>
|
|
5
3
|
#import "croche_react_native-Swift.h"
|
|
6
4
|
|
|
7
5
|
@interface RNCrocheRuntime : RCTEventEmitter <NativeCrocheRuntimeSpec>
|
|
8
6
|
@end
|
|
9
|
-
|
|
10
|
-
// RN converts synchronous NSExceptions to JSError.cause, losing the top-level code.
|
|
11
|
-
// Restore the Core code at the native boundary; the JS package remains unchanged.
|
|
12
|
-
class CrocheRuntimeSpecJSI final : public facebook::react::NativeCrocheRuntimeSpecJSI {
|
|
13
|
-
public:
|
|
14
|
-
explicit CrocheRuntimeSpecJSI(const facebook::react::ObjCTurboModule::InitParams ¶ms)
|
|
15
|
-
: NativeCrocheRuntimeSpecJSI(params) {
|
|
16
|
-
methodMap_["projectInfo"] = {1, [](facebook::jsi::Runtime &runtime, facebook::react::TurboModule &module,
|
|
17
|
-
const facebook::jsi::Value *args, size_t count) -> facebook::jsi::Value {
|
|
18
|
-
try {
|
|
19
|
-
return static_cast<facebook::react::ObjCTurboModule &>(module).invokeObjCMethod(
|
|
20
|
-
runtime, facebook::react::StringKind, "projectInfo", @selector(projectInfo:), args, count);
|
|
21
|
-
} catch (facebook::jsi::JSError &error) {
|
|
22
|
-
auto object = error.value().asObject(runtime);
|
|
23
|
-
auto cause = object.getProperty(runtime, "cause");
|
|
24
|
-
if (cause.isObject()) {
|
|
25
|
-
auto details = cause.asObject(runtime);
|
|
26
|
-
object.setProperty(runtime, "code", details.getProperty(runtime, "name"));
|
|
27
|
-
object.setProperty(runtime, "message", details.getProperty(runtime, "message"));
|
|
28
|
-
}
|
|
29
|
-
throw;
|
|
30
|
-
}
|
|
31
|
-
}};
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
@implementation RNCrocheRuntime {
|
|
36
|
-
CrocheRuntimeBridge *_bridge;
|
|
37
|
-
BOOL _observing;
|
|
38
|
-
}
|
|
39
|
-
|
|
7
|
+
@implementation RNCrocheRuntime { CrocheRuntimeBridge *_bridge; }
|
|
40
8
|
RCT_EXPORT_MODULE(CrocheRuntime)
|
|
41
|
-
|
|
42
9
|
- (instancetype)init {
|
|
43
|
-
if (self = [super init]) {
|
|
10
|
+
if ((self = [super init])) {
|
|
44
11
|
_bridge = [CrocheRuntimeBridge new];
|
|
45
12
|
__weak RNCrocheRuntime *weakSelf = self;
|
|
46
|
-
_bridge.emit = ^(NSString *
|
|
47
|
-
|
|
48
|
-
if (strongSelf && strongSelf->_observing) {
|
|
49
|
-
[strongSelf sendEventWithName:@"CrocheRuntimeEvent" body:@{@"handle": handle, @"type": type, @"json": json}];
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
_bridge.emitStream = ^(NSString *handle, NSString *type, NSString *json) {
|
|
53
|
-
RNCrocheRuntime *strongSelf = weakSelf;
|
|
54
|
-
if (!strongSelf) return;
|
|
55
|
-
// Raw stream callbacks are never filtered by the legacy _observing flag.
|
|
56
|
-
[strongSelf sendEventWithName:@"CrocheRuntimeEvent" body:@{@"handle": handle, @"type": type, @"json": json}];
|
|
57
|
-
};
|
|
13
|
+
_bridge.emit = ^(NSString *json) { [weakSelf sendEventWithName:@"CrocheCoreEvent" body:json]; };
|
|
14
|
+
_bridge.emitPal = ^(NSString *json) { [weakSelf sendEventWithName:@"CrochePalEvent" body:json]; };
|
|
58
15
|
}
|
|
59
16
|
return self;
|
|
60
17
|
}
|
|
61
|
-
|
|
62
18
|
+ (BOOL)requiresMainQueueSetup { return NO; }
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
static dispatch_once_t once;
|
|
67
|
-
dispatch_once(&once, ^{ queue = dispatch_queue_create("dev.croche.react-native", DISPATCH_QUEUE_SERIAL); });
|
|
68
|
-
return queue;
|
|
69
|
-
}
|
|
70
|
-
- (NSArray<NSString *> *)supportedEvents { return @[@"CrocheRuntimeEvent"]; }
|
|
71
|
-
- (void)startObserving { _observing = YES; }
|
|
72
|
-
- (void)stopObserving { _observing = NO; }
|
|
73
|
-
|
|
74
|
-
- (void)open:(NSString *)handle configJson:(NSString *)configJson optionsJson:(NSString *)optionsJson
|
|
75
|
-
resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
76
|
-
[_bridge open:handle configJson:configJson optionsJson:optionsJson
|
|
77
|
-
resolve:^(NSString *value) { resolve(value); }
|
|
78
|
-
reject:^(NSString *code, NSString *message) { reject(code, message, nil); }];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
- (void)send:(NSString *)handle inputJson:(NSString *)inputJson responseFormatJson:(NSString *)responseFormatJson callId:(NSString *)callId
|
|
82
|
-
resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
83
|
-
[_bridge send:handle inputJson:inputJson responseFormatJson:responseFormatJson callId:callId
|
|
84
|
-
resolve:^(NSString *value) { resolve(value); }
|
|
85
|
-
reject:^(NSString *code, NSString *message) { reject(code, message, nil); }];
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
- (void)projectDeleteStore:(NSString *)optionsJson resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
89
|
-
[_bridge projectDeleteStore:optionsJson resolve:^{ resolve(nil); } reject:^(NSString *code, NSString *message) { reject(code, message, nil); }];
|
|
90
|
-
}
|
|
91
|
-
- (void)projectOpen:(NSString *)project optionsJson:(NSString *)optionsJson resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
92
|
-
[_bridge projectOpen:project optionsJson:optionsJson resolve:^(NSString *value) { resolve(value); } reject:^(NSString *code, NSString *message) { reject(code, message, nil); }];
|
|
19
|
+
- (NSArray<NSString *> *)supportedEvents { return @[@"CrocheCoreEvent", @"CrochePalEvent"]; }
|
|
20
|
+
RCT_EXPORT_METHOD(coreCall:(NSString *)handle method:(NSString *)method argsJson:(NSString *)args images:(NSArray *)images resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
|
|
21
|
+
[_bridge coreCall:handle method:method args:args images:images resolve:resolve reject:reject];
|
|
93
22
|
}
|
|
94
|
-
|
|
23
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(coreCallSync:(NSString *)handle method:(NSString *)method argsJson:(NSString *)args) {
|
|
95
24
|
NSError *error = nil;
|
|
96
|
-
NSString *value = [_bridge
|
|
97
|
-
if (
|
|
98
|
-
// The native JSI wrapper below retains this code on the synchronous JS error.
|
|
99
|
-
@throw [NSException exceptionWithName:error.userInfo[@"code"] ?: @"native_error"
|
|
100
|
-
reason:error.localizedDescription userInfo:nil];
|
|
101
|
-
}
|
|
25
|
+
NSString *value = [_bridge coreCallSync:handle method:method args:args error:&error];
|
|
26
|
+
if (error) @throw [NSException exceptionWithName:@"CrocheNativeTransport" reason:error.localizedDescription userInfo:nil];
|
|
102
27
|
return value;
|
|
103
28
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
- (void)agentControl:(NSString *)handle op:(NSString *)op argsJson:(NSString *)argsJson resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
112
|
-
[_bridge agentControl:handle op:op argsJson:argsJson resolve:^(NSString *value) { resolve(value); } reject:^(NSString *code, NSString *message) { reject(code, message, nil); }];
|
|
113
|
-
}
|
|
114
|
-
- (void)cancelTurn:(NSString *)handle resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
115
|
-
[_bridge cancelTurn:handle resolve:^{ resolve(nil); } reject:^(NSString *code, NSString *message) { reject(code, message, nil); }];
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
- (void)observe:(NSString *)handle resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
119
|
-
[_bridge observe:handle resolve:^{ resolve(nil); } reject:^(NSString *code, NSString *message) { reject(code, message, nil); }];
|
|
120
|
-
}
|
|
121
|
-
- (void)unobserve:(NSString *)handle { [_bridge unobserve:handle]; }
|
|
122
|
-
- (void)select:(NSString *)handle selectionJson:(NSString *)selectionJson resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
123
|
-
[_bridge select:handle selectionJson:selectionJson resolve:^(NSNumber *value) { resolve(value); } reject:^(NSString *code, NSString *message) { reject(code, message, nil); }];
|
|
124
|
-
}
|
|
125
|
-
- (void)closeProjection:(NSString *)handle projection:(double)projection { [_bridge closeProjection:handle projection:projection]; }
|
|
126
|
-
- (void)history:(NSString *)handle projection:(double)projection before:(double)before limit:(double)limit resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
127
|
-
[_bridge history:handle projection:projection before:before limit:limit resolve:^{ resolve(nil); } reject:^(NSString *code, NSString *message) { reject(code, message, nil); }];
|
|
128
|
-
}
|
|
129
|
-
- (void)readOutcome:(NSString *)handle id:(NSString *)id fromSeq:(double)fromSeq readId:(NSString *)readId resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
130
|
-
[_bridge readOutcome:handle id:id fromSeq:fromSeq readId:readId resolve:^(NSString *value) { resolve(value); } reject:^(NSString *code, NSString *message) { reject(code, message, nil); }];
|
|
131
|
-
}
|
|
132
|
-
- (void)sendReceipt:(NSString *)handle inputJson:(NSString *)inputJson responseFormatJson:(NSString *)responseFormatJson callId:(NSString *)callId resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
133
|
-
[_bridge sendReceipt:handle inputJson:inputJson responseFormatJson:responseFormatJson callId:callId resolve:^(NSString *value) { resolve(value); } reject:^(NSString *code, NSString *message) { reject(code, message, nil); }];
|
|
134
|
-
}
|
|
135
|
-
- (void)cancelInput:(NSString *)handle id:(NSString *)id resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
136
|
-
[_bridge cancelInput:handle id:id resolve:^{ resolve(nil); } reject:^(NSString *code, NSString *message) { reject(code, message, nil); }];
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
- (void)cancel:(NSString *)handle { [_bridge cancel:handle]; }
|
|
140
|
-
|
|
141
|
-
- (void)cancelSend:(NSString *)handle callId:(NSString *)callId { [_bridge cancelSend:handle callId:callId]; }
|
|
142
|
-
|
|
143
|
-
- (void)clearQueued:(NSString *)handle resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
144
|
-
[_bridge clearQueued:handle
|
|
145
|
-
resolve:^(NSNumber *value) { resolve(value); }
|
|
146
|
-
reject:^(NSString *code, NSString *message) { reject(code, message, nil); }];
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
- (void)inspect:(NSString *)handle resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
150
|
-
[_bridge inspect:handle
|
|
151
|
-
resolve:^(NSString *value) { resolve(value); }
|
|
152
|
-
reject:^(NSString *code, NSString *message) { reject(code, message, nil); }];
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
- (void)maintain:(NSString *)handle force:(BOOL)force
|
|
156
|
-
resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
157
|
-
[_bridge maintain:handle force:force
|
|
158
|
-
resolve:^(NSString *value) { resolve(value); }
|
|
159
|
-
reject:^(NSString *code, NSString *message) { reject(code, message, nil); }];
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
- (void)deliverDue:(NSString *)handle resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
163
|
-
[_bridge deliverDue:handle
|
|
164
|
-
resolve:^(NSString *value) { resolve(value); }
|
|
165
|
-
reject:^(NSString *code, NSString *message) { reject(code, message, nil); }];
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
- (void)schedules:(NSString *)handle resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
169
|
-
[_bridge schedules:handle
|
|
170
|
-
resolve:^(NSString *value) { resolve(value); }
|
|
171
|
-
reject:^(NSString *code, NSString *message) { reject(code, message, nil); }];
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
- (void)adjustBudget:(NSString *)handle amount:(double)amount absolute:(BOOL)absolute id:(NSString *)id
|
|
175
|
-
resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
176
|
-
[_bridge adjustBudget:handle amount:amount absolute:absolute id:id
|
|
177
|
-
resolve:^(NSString *value) { resolve(value); }
|
|
178
|
-
reject:^(NSString *code, NSString *message) { reject(code, message, nil); }];
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
- (void)wiki:(NSString *)handle op:(NSString *)op argsJson:(NSString *)argsJson
|
|
182
|
-
resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
183
|
-
[_bridge wiki:handle op:op argsJson:argsJson
|
|
184
|
-
resolve:^(NSString *value) { resolve(value); }
|
|
185
|
-
reject:^(NSString *code, NSString *message) { reject(code, message, nil); }];
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
- (void)memory:(NSString *)handle op:(NSString *)op argsJson:(NSString *)argsJson
|
|
189
|
-
resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
190
|
-
[_bridge memory:handle op:op argsJson:argsJson
|
|
191
|
-
resolve:^(NSString *value) { resolve(value); }
|
|
192
|
-
reject:^(NSString *code, NSString *message) { reject(code, message, nil); }];
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
- (void)setTools:(NSString *)handle toolsJson:(NSString *)toolsJson resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
196
|
-
[_bridge setTools:handle toolsJson:toolsJson
|
|
197
|
-
resolve:^{ resolve(nil); }
|
|
198
|
-
reject:^(NSString *code, NSString *message) { reject(code, message, nil); }];
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
- (void)clearHistory:(NSString *)handle resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
202
|
-
[_bridge clearHistory:handle
|
|
203
|
-
resolve:^{ resolve(nil); }
|
|
204
|
-
reject:^(NSString *code, NSString *message) { reject(code, message, nil); }];
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
- (void)close:(NSString *)handle resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
|
|
208
|
-
[_bridge close:handle
|
|
209
|
-
resolve:^{ resolve(nil); }
|
|
210
|
-
reject:^(NSString *code, NSString *message) { reject(code, message, nil); }];
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
- (void)resolveTool:(NSString *)callId ok:(BOOL)ok resultJson:(NSString *)resultJson {
|
|
214
|
-
[_bridge resolveTool:callId ok:ok resultJson:resultJson];
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params {
|
|
218
|
-
return std::make_shared<CrocheRuntimeSpecJSI>(params);
|
|
29
|
+
RCT_EXPORT_METHOD(coreReply:(NSString *)call completionJson:(NSString *)json) { [_bridge coreReply:call json:json]; }
|
|
30
|
+
RCT_EXPORT_METHOD(platformCall:(NSString *)method argsJson:(NSString *)args resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) { [_bridge platformCall:method args:args resolve:resolve reject:reject]; }
|
|
31
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(platformCallSync:(NSString *)method argsJson:(NSString *)args) {
|
|
32
|
+
NSError *error = nil; NSString *value = [_bridge platformCallSync:method args:args error:&error];
|
|
33
|
+
if (error) @throw [NSException exceptionWithName:@"CrocheNativeTransport" reason:error.localizedDescription userInfo:nil];
|
|
34
|
+
return value;
|
|
219
35
|
}
|
|
220
|
-
|
|
36
|
+
- (void)invalidate { [_bridge invalidate]; [super invalidate]; }
|
|
37
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params { return std::make_shared<facebook::react::NativeCrocheRuntimeSpecJSI>(params); }
|
|
221
38
|
@end
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
/// Whether the app's own code signature grants `get-task-allow`, the entitlement the OS checks
|
|
4
|
+
/// before it lets a debugger attach. It comes from the running executable, never from app options
|
|
5
|
+
/// or a build macro: a macro here would describe this SDK's build, not the app's.
|
|
6
|
+
///
|
|
7
|
+
/// Only the XML entitlements slot is read. A signature without it reads as `false`; anything that
|
|
8
|
+
/// cannot be parsed reads as `nil` (unknown), and the caller refuses both.
|
|
9
|
+
enum AppBuildFacts {
|
|
10
|
+
/// From this slice's own compile target, never from options. iOS means device or simulator;
|
|
11
|
+
/// every other Apple or Linux host is Other, which has no build gate.
|
|
12
|
+
static var targetKind: PalTargetKind {
|
|
13
|
+
#if targetEnvironment(simulator)
|
|
14
|
+
return .iosSimulator
|
|
15
|
+
#elseif os(iOS)
|
|
16
|
+
return .iosDevice
|
|
17
|
+
#else
|
|
18
|
+
return .other
|
|
19
|
+
#endif
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/// The OS's own notion of debuggable for this process. The simulator has no such fact (no
|
|
23
|
+
/// slice carries the entitlement, Debug or Release), so a simulator build counts as debuggable
|
|
24
|
+
/// by rule: it cannot run on a device. Device rule: documented, not yet device-proven.
|
|
25
|
+
static let debuggable: Bool? = {
|
|
26
|
+
#if targetEnvironment(simulator)
|
|
27
|
+
return true
|
|
28
|
+
#elseif os(iOS)
|
|
29
|
+
return ProcessInfo.processInfo.isiOSAppOnMac ? nil : getTaskAllow(executable: Bundle.main.executableURL)
|
|
30
|
+
#else
|
|
31
|
+
return nil
|
|
32
|
+
#endif
|
|
33
|
+
}()
|
|
34
|
+
|
|
35
|
+
static func getTaskAllow(executable: URL?) -> Bool? {
|
|
36
|
+
guard let executable, let data = try? Data(contentsOf: executable, options: .alwaysMapped) else { return nil }
|
|
37
|
+
return getTaskAllow(macho: data)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static func getTaskAllow(macho data: Data) -> Bool? {
|
|
41
|
+
let bytes = Bytes(data: Data(data))
|
|
42
|
+
guard let slice = arm64Slice(bytes), let signature = signature(slice) else { return nil }
|
|
43
|
+
return entitlement(signature)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/// The arm64 Mach-O: the file itself, or that slice of a universal binary.
|
|
47
|
+
private static func arm64Slice(_ file: Bytes) -> Bytes? {
|
|
48
|
+
if file.be32(0) == 0xcafe_babe {
|
|
49
|
+
guard let count = file.be32(4) else { return nil }
|
|
50
|
+
for index in 0..<Int(min(count, 64)) {
|
|
51
|
+
let entry = 8 + index * 20
|
|
52
|
+
guard file.be32(entry) == 0x0100_000c else { continue }
|
|
53
|
+
guard let offset = file.be32(entry + 8), let size = file.be32(entry + 12) else { return nil }
|
|
54
|
+
return file.range(Int(offset), Int(size))
|
|
55
|
+
}
|
|
56
|
+
return nil
|
|
57
|
+
}
|
|
58
|
+
return file.le32(0) == 0xfeed_facf ? file : nil
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/// The SuperBlob `LC_CODE_SIGNATURE` points at.
|
|
62
|
+
private static func signature(_ macho: Bytes) -> Bytes? {
|
|
63
|
+
guard let count = macho.le32(16) else { return nil }
|
|
64
|
+
var command = 32
|
|
65
|
+
for _ in 0..<Int(min(count, 4096)) {
|
|
66
|
+
guard let kind = macho.le32(command), let size = macho.le32(command + 4), size >= 8 else { return nil }
|
|
67
|
+
if kind == 0x1d {
|
|
68
|
+
guard let offset = macho.le32(command + 8), let length = macho.le32(command + 12),
|
|
69
|
+
let blob = macho.range(Int(offset), Int(length)), blob.be32(0) == 0xfade_0cc0 else { return nil }
|
|
70
|
+
return blob
|
|
71
|
+
}
|
|
72
|
+
command += Int(size)
|
|
73
|
+
}
|
|
74
|
+
return nil
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private static func entitlement(_ superblob: Bytes) -> Bool? {
|
|
78
|
+
guard let count = superblob.be32(8), count <= 64 else { return nil }
|
|
79
|
+
for index in 0..<Int(count) {
|
|
80
|
+
let entry = 12 + index * 8
|
|
81
|
+
guard let slot = superblob.be32(entry), let offset = superblob.be32(entry + 4) else { return nil }
|
|
82
|
+
guard slot == 5 else { continue }
|
|
83
|
+
guard superblob.be32(Int(offset)) == 0xfade_7171, let length = superblob.be32(Int(offset) + 4), length >= 8,
|
|
84
|
+
let xml = superblob.range(Int(offset) + 8, Int(length) - 8),
|
|
85
|
+
let plist = try? PropertyListSerialization.propertyList(from: xml.slice, format: nil),
|
|
86
|
+
let entitlements = plist as? [String: Any] else { return nil }
|
|
87
|
+
return entitlements["get-task-allow"] as? Bool ?? false
|
|
88
|
+
}
|
|
89
|
+
return false
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/// Bounds-checked reads over a zero-based range of the file: hostile offsets return nil.
|
|
93
|
+
private struct Bytes {
|
|
94
|
+
let data: Data
|
|
95
|
+
let start: Int
|
|
96
|
+
let count: Int
|
|
97
|
+
init(data: Data) { self.data = data; start = 0; count = data.count }
|
|
98
|
+
private init(data: Data, start: Int, count: Int) { self.data = data; self.start = start; self.count = count }
|
|
99
|
+
|
|
100
|
+
var slice: Data { data.subdata(in: start..<(start + count)) }
|
|
101
|
+
func range(_ offset: Int, _ length: Int) -> Bytes? {
|
|
102
|
+
guard offset >= 0, length >= 0, offset <= count, length <= count - offset else { return nil }
|
|
103
|
+
return Bytes(data: data, start: start + offset, count: length)
|
|
104
|
+
}
|
|
105
|
+
func be32(_ offset: Int) -> UInt32? { word(offset).map { $0.reduce(0) { $0 << 8 | UInt32($1) } } }
|
|
106
|
+
func le32(_ offset: Int) -> UInt32? { word(offset).map { $0.reversed().reduce(0) { $0 << 8 | UInt32($1) } } }
|
|
107
|
+
private func word(_ offset: Int) -> [UInt8]? {
|
|
108
|
+
guard offset >= 0, offset <= count - 4 else { return nil }
|
|
109
|
+
return [UInt8](data[(start + offset)..<(start + offset + 4)])
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
#if canImport(Darwin)
|
|
3
|
+
import Darwin
|
|
4
|
+
#elseif canImport(Glibc)
|
|
5
|
+
import Glibc
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
/// Private transport for Core's blob keys. Object files contain the original bytes.
|
|
9
|
+
final class BlobFiles: Sendable {
|
|
10
|
+
struct Entry { let key: String; let size: UInt64 }
|
|
11
|
+
struct Page { let entries: [Entry]; let nextCursor: String? }
|
|
12
|
+
|
|
13
|
+
private let root: URL
|
|
14
|
+
|
|
15
|
+
init(directory: URL) { root = directory.appendingPathComponent("blobs", isDirectory: true) }
|
|
16
|
+
|
|
17
|
+
private static func valid(_ segment: Substring) -> Bool {
|
|
18
|
+
segment.utf8.first.map { (48...57).contains($0) || (97...122).contains($0) || $0 == 126 } == true
|
|
19
|
+
&& segment.utf8.allSatisfy { (48...57).contains($0) || (97...122).contains($0) || [45, 46, 95, 126].contains($0) }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private func directory(_ key: String, create: Bool) throws -> URL? {
|
|
23
|
+
let segments = key.isEmpty ? [] : key.split(separator: "/", omittingEmptySubsequences: false)
|
|
24
|
+
guard key.utf8.count <= 1024, segments.allSatisfy(Self.valid) else { throw CocoaError(.fileWriteInvalidFileName) }
|
|
25
|
+
var path = root
|
|
26
|
+
for segment in [""] + segments.map(String.init) {
|
|
27
|
+
if !segment.isEmpty { path.appendPathComponent(segment, isDirectory: true) }
|
|
28
|
+
if create {
|
|
29
|
+
do {
|
|
30
|
+
try FileManager.default.createDirectory(at: path, withIntermediateDirectories: false)
|
|
31
|
+
try sync(path.deletingLastPathComponent())
|
|
32
|
+
} catch let error as CocoaError where error.code == .fileWriteFileExists {}
|
|
33
|
+
}
|
|
34
|
+
do {
|
|
35
|
+
let facts = try path.resourceValues(forKeys: [.isDirectoryKey, .isSymbolicLinkKey])
|
|
36
|
+
guard facts.isDirectory == true, facts.isSymbolicLink != true else { throw CocoaError(.fileReadCorruptFile) }
|
|
37
|
+
} catch let error as CocoaError where error.code == .fileReadNoSuchFile && !create { return nil }
|
|
38
|
+
}
|
|
39
|
+
return path
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
func put(_ key: String, _ bytes: Data) throws {
|
|
43
|
+
guard !key.isEmpty, let dir = try directory(key, create: true) else { throw CocoaError(.fileWriteInvalidFileName) }
|
|
44
|
+
let temporary = dir.appendingPathComponent(".tmp-" + UUID().uuidString)
|
|
45
|
+
try bytes.write(to: temporary, options: .withoutOverwriting)
|
|
46
|
+
defer { try? FileManager.default.removeItem(at: temporary) }
|
|
47
|
+
try sync(temporary)
|
|
48
|
+
guard rename(temporary.path, dir.appendingPathComponent("object").path) == 0 else { throw CocoaError(.fileWriteUnknown) }
|
|
49
|
+
try sync(dir)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
func get(_ key: String) throws -> Data? {
|
|
53
|
+
guard !key.isEmpty, let dir = try directory(key, create: false) else { return nil }
|
|
54
|
+
let file = dir.appendingPathComponent("object")
|
|
55
|
+
do {
|
|
56
|
+
let facts = try file.resourceValues(forKeys: [.isRegularFileKey, .isSymbolicLinkKey])
|
|
57
|
+
guard facts.isRegularFile == true, facts.isSymbolicLink != true else { throw CocoaError(.fileReadCorruptFile) }
|
|
58
|
+
return try Data(contentsOf: file)
|
|
59
|
+
} catch let error as CocoaError where error.code == .fileReadNoSuchFile { return nil }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
func delete(_ key: String) throws {
|
|
63
|
+
guard !key.isEmpty, let dir = try directory(key, create: false) else { return }
|
|
64
|
+
if unlink(dir.appendingPathComponent("object").path) == 0 { try sync(dir) }
|
|
65
|
+
else if errno != ENOENT { throw CocoaError(.fileWriteUnknown) }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
func list(_ prefix: String, cursor: String?) throws -> Page {
|
|
69
|
+
let keys: Set<URLResourceKey> = [.isDirectoryKey, .isRegularFileKey, .isSymbolicLinkKey, .fileSizeKey]
|
|
70
|
+
var entries: [Entry] = []
|
|
71
|
+
func walk(_ dir: URL, key: String) throws {
|
|
72
|
+
for child in try FileManager.default.contentsOfDirectory(at: dir, includingPropertiesForKeys: Array(keys)) {
|
|
73
|
+
let name = child.lastPathComponent
|
|
74
|
+
let facts = try child.resourceValues(forKeys: keys)
|
|
75
|
+
if facts.isSymbolicLink == true { continue }
|
|
76
|
+
if name == "object", facts.isRegularFile == true, key.hasPrefix(prefix), cursor.map({ key > $0 }) ?? true {
|
|
77
|
+
guard let size = facts.fileSize, size >= 0 else { throw CocoaError(.fileReadCorruptFile) }
|
|
78
|
+
entries.append(Entry(key: key, size: UInt64(size)))
|
|
79
|
+
} else if facts.isDirectory == true, Self.valid(name[...]) {
|
|
80
|
+
let next = key.isEmpty ? name : key + "/" + name
|
|
81
|
+
if next.hasPrefix(prefix) || prefix.hasPrefix(next + "/") { try walk(child, key: next) }
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
let parent = prefix.lastIndex(of: "/").map { String(prefix[..<$0]) } ?? ""
|
|
86
|
+
if let dir = try directory(parent, create: false) { try walk(dir, key: parent) }
|
|
87
|
+
entries.sort { $0.key < $1.key }
|
|
88
|
+
let page = Array(entries.prefix(1_000))
|
|
89
|
+
return Page(entries: page, nextCursor: entries.count > page.count ? page.last?.key : nil)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/// Core has drained the exact owner scope before invoking this.
|
|
93
|
+
func purgeStaging(_ prefix: String) throws {
|
|
94
|
+
guard prefix.count > 1, prefix.hasSuffix("/") else { throw CocoaError(.fileWriteInvalidFileName) }
|
|
95
|
+
guard let dir = try directory(String(prefix.dropLast()), create: false) else { return }
|
|
96
|
+
try removeStagedFiles(dir)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private func removeStagedFiles(_ dir: URL) throws {
|
|
100
|
+
// The exact owner lease covers the no-follow check and subsequent unlink.
|
|
101
|
+
for name in try FileManager.default.contentsOfDirectory(atPath: dir.path) {
|
|
102
|
+
let child = dir.appendingPathComponent(name)
|
|
103
|
+
var info = stat()
|
|
104
|
+
guard lstat(child.path, &info) == 0 else {
|
|
105
|
+
if errno == ENOENT { continue }
|
|
106
|
+
throw CocoaError(.fileReadUnknown)
|
|
107
|
+
}
|
|
108
|
+
let type = info.st_mode & mode_t(S_IFMT)
|
|
109
|
+
if type == mode_t(S_IFREG), name.hasPrefix(".tmp-") {
|
|
110
|
+
guard unlink(child.path) == 0 || errno == ENOENT else { throw CocoaError(.fileWriteUnknown) }
|
|
111
|
+
} else if type == mode_t(S_IFDIR), Self.valid(name[...]) {
|
|
112
|
+
try removeStagedFiles(child)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
try sync(dir)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private func sync(_ path: URL) throws {
|
|
119
|
+
let fd = open(path.path, O_RDONLY)
|
|
120
|
+
guard fd >= 0 else { throw CocoaError(.fileWriteUnknown) }
|
|
121
|
+
defer { close(fd) }
|
|
122
|
+
guard fsync(fd) == 0 else { throw CocoaError(.fileWriteUnknown) }
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
/// Schema-7 context settings. Core owns defaults and validation.
|
|
4
|
+
struct ContextConfig: Sendable {
|
|
5
|
+
/// Target average input tokens per model call, 1...16_777_216.
|
|
6
|
+
var turnTokens: Int?
|
|
7
|
+
/// 0...0.5, default 0.25; controls memory inclusion; zero disables it. Ignored when memory is disabled.
|
|
8
|
+
var memoryShare: Double?
|
|
9
|
+
init(turnTokens: Int? = nil, memoryShare: Double? = nil) {
|
|
10
|
+
self.turnTokens = turnTokens
|
|
11
|
+
self.memoryShare = memoryShare
|
|
12
|
+
}
|
|
13
|
+
var json: JSON {
|
|
14
|
+
var value: JSON = .object([:])
|
|
15
|
+
if let turnTokens { value["turnTokens"] = .number(Double(turnTokens)) }
|
|
16
|
+
if let memoryShare { value["memoryShare"] = .number(memoryShare) }
|
|
17
|
+
return value
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/// Input size contracts (`limits`), in UTF-16 code units (`String.utf16.count`). An input over
|
|
22
|
+
/// one fails with `input_too_large` and is never truncated; `Croche.truncate` cuts text to fit.
|
|
23
|
+
/// Core owns defaults and validation.
|
|
24
|
+
struct LimitsConfig: Sendable {
|
|
25
|
+
/// Total user and app-event text of one send, 1_000...200_000 (default 32_000).
|
|
26
|
+
var userTextChars: Int?
|
|
27
|
+
/// Total app-state text of one send, 1_000...200_000 (default 32_000).
|
|
28
|
+
var appStateChars: Int?
|
|
29
|
+
/// One tool result's value as compact JSON, 1_000...1_000_000 (default 200_000). Over it,
|
|
30
|
+
/// the turn fails.
|
|
31
|
+
var toolResultChars: Int?
|
|
32
|
+
init(userTextChars: Int? = nil, appStateChars: Int? = nil, toolResultChars: Int? = nil) {
|
|
33
|
+
self.userTextChars = userTextChars
|
|
34
|
+
self.appStateChars = appStateChars
|
|
35
|
+
self.toolResultChars = toolResultChars
|
|
36
|
+
}
|
|
37
|
+
var json: JSON {
|
|
38
|
+
var value: JSON = .object([:])
|
|
39
|
+
if let userTextChars { value["userTextChars"] = .number(Double(userTextChars)) }
|
|
40
|
+
if let appStateChars { value["appStateChars"] = .number(Double(appStateChars)) }
|
|
41
|
+
if let toolResultChars { value["toolResultChars"] = .number(Double(toolResultChars)) }
|
|
42
|
+
return value
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/// Application memory settings. Core owns defaults and validation.
|
|
47
|
+
struct MemoryConfig: Sendable {
|
|
48
|
+
var enabled: Bool?
|
|
49
|
+
var policy: String?
|
|
50
|
+
init(enabled: Bool? = nil, policy: String? = nil) {
|
|
51
|
+
self.enabled = enabled
|
|
52
|
+
self.policy = policy
|
|
53
|
+
}
|
|
54
|
+
var json: JSON {
|
|
55
|
+
var value: JSON = .object([:])
|
|
56
|
+
if let enabled { value["enabled"] = .bool(enabled) }
|
|
57
|
+
if let policy { value["policy"] = .string(policy) }
|
|
58
|
+
return value
|
|
59
|
+
}
|
|
60
|
+
}
|