@h1r-ai/croche-react-native 0.5.5 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -458
- package/THIRD-PARTY-NOTICES +7 -8
- package/android/build.gradle +6 -1
- package/android/src/androidTest/java/dev/croche/reactnative/WikiFileBridgeTest.kt +125 -0
- package/android/src/main/java/dev/croche/reactnative/CoreDispatch.kt +81 -0
- package/android/src/main/java/dev/croche/reactnative/CoreWire.kt +83 -0
- package/android/src/main/java/dev/croche/reactnative/CrocheRuntimeModule.kt +45 -824
- package/android/src/main/java/dev/croche/reactnative/NativePal.kt +51 -0
- package/android/src/main/java/dev/croche/reactnative/RNHostPal.kt +9 -0
- package/android/src/test/java/dev/croche/reactnative/AgentMemoryTest.kt +42 -41
- package/android/src/test/java/dev/croche/reactnative/BackgroundDelegationTest.kt +71 -0
- package/android/src/test/java/dev/croche/reactnative/OpenForwardingFixture.kt +29 -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/vendor/CrocheRuntimeSDK/android/dev/croche/android/AndroidEventSink.kt +27 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/AndroidPlatform.kt +6 -6
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BackgroundRegistration.kt +16 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BackgroundWakeWorker.kt +51 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapDecodedImageCodec.kt +162 -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/WorkManagerScheduler.kt +8 -8
- 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 +121 -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/AndroidStoragePal.kt +73 -0
- package/android/vendor/CrocheRuntimeSDK/consumer-rules.pro +9 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/AppStreamBranch.kt +5 -2
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/BindingFacts.kt +29 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ContextConfig.kt +45 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Core.kt +16 -1
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Croche.kt +60 -105
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheAgent.kt +47 -107
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheRuntime.kt +41 -40
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheTools.kt +67 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/DecodedImageCodec.kt +20 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Effects.kt +18 -20
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/GeneratedAppStream.kt +322 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Host.kt +71 -34
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ImagePal.kt +183 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Images.kt +9 -7
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/NativeCoreStreamPort.kt +47 -19
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Platform.kt +5 -5
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectPalRouting.kt +1 -1
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectRecords.kt +9 -9
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectTypes.kt +108 -37
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/PublicResults.kt +44 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ReaderValues.kt +73 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/RunTool.kt +40 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/SendEncoding.kt +23 -21
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Storage.kt +8 -8
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/StoragePal.kt +18 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/StreamHub.kt +50 -25
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/SubscriptionTypes.kt +22 -22
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ffi/croche_ffi.kt +8285 -2159
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/AppEventSink.kt +34 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/AppStoragePal.kt +25 -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 +31 -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 +128 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/JvmCoreHost.kt +72 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/JvmStoragePal.kt +34 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/LifecycleBinding.kt +18 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/NativePlatform.kt +45 -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 +34 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/ScopeJson.kt +29 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/ToolCompletionEncoding.kt +29 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/AtomicKeyFiles.kt +79 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/DirectHttpPal.kt +223 -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/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 +3 -0
- package/dist/react-native/src/core-native.js +193 -0
- package/dist/react-native/src/core-wire.d.ts +38 -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/agent.d.ts +43 -0
- package/dist/runtime/src/agent.js +75 -0
- package/dist/runtime/src/app-api.d.ts +284 -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 +24 -0
- package/dist/runtime/src/core/port.d.ts +234 -0
- package/dist/runtime/src/core/port.js +1 -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 +42 -0
- package/dist/runtime/src/croche.js +111 -0
- package/dist/runtime/src/errors.d.ts +26 -0
- package/dist/runtime/src/errors.js +49 -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 +174 -0
- package/dist/runtime/src/generated/app-stream.js +124 -0
- package/dist/runtime/src/index.native.d.ts +21 -0
- package/dist/runtime/src/index.native.js +8 -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 +24 -0
- package/dist/runtime/src/pal/codec.d.ts +15 -0
- package/dist/runtime/src/pal/codec.js +52 -0
- package/dist/runtime/src/pal/host.d.ts +5 -0
- package/dist/runtime/src/pal/host.js +35 -0
- package/dist/runtime/src/pal/platform.d.ts +16 -0
- package/dist/runtime/src/pal/platform.js +7 -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 +19 -0
- package/dist/runtime/src/tools.js +70 -0
- package/ios/CoreAgentTransport.swift +14 -0
- package/ios/CoreDeliveryTransport.swift +58 -0
- package/ios/CoreNativePal.swift +93 -0
- package/ios/CorePlatformTransport.swift +44 -0
- package/ios/CoreWireDispatch.swift +92 -0
- package/ios/CoreWireSupport.swift +111 -0
- package/ios/CrocheRuntimeBridge.swift +34 -994
- package/ios/ProjectPal.swift +46 -0
- package/ios/RNCrocheRuntime.mm +18 -201
- package/ios/vendor/CrocheRuntimeSDK/AppBuildFacts.swift +112 -0
- package/ios/vendor/CrocheRuntimeSDK/Background.swift +11 -11
- package/ios/vendor/CrocheRuntimeSDK/ContextConfig.swift +64 -0
- package/ios/vendor/CrocheRuntimeSDK/DirectHTTP.swift +258 -0
- package/ios/vendor/CrocheRuntimeSDK/Effects.swift +17 -17
- package/ios/vendor/CrocheRuntimeSDK/FFIStreamPort.swift +85 -43
- package/ios/vendor/CrocheRuntimeSDK/GeneratedAppStream.swift +443 -0
- package/ios/vendor/CrocheRuntimeSDK/Host.swift +122 -61
- package/ios/vendor/CrocheRuntimeSDK/ImagePal.swift +410 -0
- package/ios/vendor/CrocheRuntimeSDK/Images.swift +10 -9
- package/ios/vendor/CrocheRuntimeSDK/JSON.swift +4 -4
- package/ios/vendor/CrocheRuntimeSDK/Offload.swift +24 -0
- package/ios/vendor/CrocheRuntimeSDK/OpenOptions.swift +37 -36
- package/ios/vendor/CrocheRuntimeSDK/Platform.swift +35 -35
- package/ios/vendor/CrocheRuntimeSDK/PlatformBackground.swift +285 -0
- package/ios/vendor/CrocheRuntimeSDK/PlatformPal.swift +266 -0
- package/ios/vendor/CrocheRuntimeSDK/PlatformStorage.swift +195 -0
- package/ios/vendor/CrocheRuntimeSDK/Project.swift +209 -95
- package/ios/vendor/CrocheRuntimeSDK/Runtime.swift +97 -123
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Agent.swift +195 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1BindingFacts.swift +33 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Core.swift +161 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Croche.swift +234 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Events.swift +28 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Options.swift +177 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1RunTool.swift +61 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Storage.swift +95 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1TestHooks.swift +105 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Tools.swift +209 -0
- package/ios/vendor/CrocheRuntimeSDK/Storage.swift +52 -52
- package/ios/vendor/CrocheRuntimeSDK/StreamHub.swift +180 -137
- package/ios/vendor/CrocheRuntimeSDK/SubscriptionRuntime.swift +16 -10
- package/ios/vendor/CrocheRuntimeSDK/SubscriptionTypes.swift +131 -116
- package/ios/vendor/CrocheRuntimeSDK/Truncate.swift +12 -0
- package/ios/vendor/CrocheRuntimeSDK/croche_ffi.swift +7209 -2803
- package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64/Headers/croche_ffiFFI.h +1342 -218
- 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 +1342 -218
- 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/vendor-native.sh +5 -4
- 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/core/dev/croche/Control.kt +0 -178
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectBinding.kt +0 -79
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectPlatform.kt +0 -46
- package/ios/vendor/CrocheRuntimeSDK/Control.swift +0 -192
- 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,46 @@
|
|
|
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
|
+
init(_ base: any HostPal) { self.base = base }
|
|
8
|
+
func streamPlatform() -> HostStreamPlatform { base.streamPlatform() }
|
|
9
|
+
func imageCodecAvailable() -> Bool { base.imageCodecAvailable() }
|
|
10
|
+
func readImage(request: PalImageReadRequest, cancel: CancelToken) throws -> Data { try base.readImage(request: request, cancel: cancel) }
|
|
11
|
+
func prepareImage(source: PalImageBytes, plan: PalImagePreparePlan, cancel: CancelToken) throws -> PalImageBytes { try base.prepareImage(source: source, plan: plan, cancel: cancel) }
|
|
12
|
+
func releaseImage(capture: String) { base.releaseImage(capture: capture) }
|
|
13
|
+
func decodeImage(bytes: Data, options: PalImageDecodeOptions, cancel: CancelToken) throws -> PalDecodedImage { try base.decodeImage(bytes: bytes, options: options, cancel: cancel) }
|
|
14
|
+
func renderImage(request: PalImageRenderRequest, cancel: CancelToken) throws -> Data { try base.renderImage(request: request, cancel: cancel) }
|
|
15
|
+
func releaseDecodedImage(handle: String) { base.releaseDecodedImage(handle: handle) }
|
|
16
|
+
func http(request: PalHttpRequest, sink: HttpSink, cancel: CancelToken) throws { try base.http(request: request, sink: sink, cancel: cancel) }
|
|
17
|
+
func resolve(host: String, cancel: CancelToken) throws -> [String] { try base.resolve(host: host, cancel: cancel) }
|
|
18
|
+
func platformFacts() -> PalPlatformFacts { base.platformFacts() }
|
|
19
|
+
func readAsset(path: String) throws -> Data? { try base.readAsset(path: path) }
|
|
20
|
+
func list(prefix: String) throws -> [String] { try base.list(prefix: prefix) }
|
|
21
|
+
func read(key: String) throws -> String? { try base.read(key: key) }
|
|
22
|
+
func write(key: String, value: String) throws { try base.write(key: key, value: value) }
|
|
23
|
+
func readSecret(key: String) throws -> String? { try base.readSecret(key: key) }
|
|
24
|
+
func writeSecret(key: String, value: String) throws { try base.writeSecret(key: key, value: value) }
|
|
25
|
+
func remove(key: String) throws { try base.remove(key: key) }
|
|
26
|
+
func removeSecret(key: String) throws { try base.removeSecret(key: key) }
|
|
27
|
+
func lock(key: String) throws -> PalLockOutcome { try base.lock(key: key) }
|
|
28
|
+
func unlock(key: String) throws { try base.unlock(key: key) }
|
|
29
|
+
func storeIdentity() -> String { base.storeIdentity() }
|
|
30
|
+
func tool(invocation: String, cancel: CancelToken) throws -> ToolOutput { try base.tool(invocation: invocation, cancel: cancel) }
|
|
31
|
+
func attest(request: String, timeoutMs: UInt64) throws -> String { try base.attest(request: request, timeoutMs: timeoutMs) }
|
|
32
|
+
func nowMs() -> Double { base.nowMs() }
|
|
33
|
+
func utcOffsetMinutes(atMs: Double) -> Int64 { base.utcOffsetMinutes(atMs: atMs) }
|
|
34
|
+
func random() -> String { base.random() }
|
|
35
|
+
func wake(atMs: Double?) { base.wake(atMs: atMs) }
|
|
36
|
+
func schedule(entries: String) throws { try base.schedule(entries: entries) }
|
|
37
|
+
func registerBackground(identifier: String, wake: CoreBackgroundWake) throws {
|
|
38
|
+
try base.registerBackground(identifier: identifier, wake: wake)
|
|
39
|
+
}
|
|
40
|
+
func archiveAppendLine(entry: String, line: String) throws { try base.archiveAppendLine(entry: entry, line: line) }
|
|
41
|
+
func archiveReadLines(entry: String) throws -> [String] { try base.archiveReadLines(entry: entry) }
|
|
42
|
+
func archiveReplaceLines(entry: String, lines: [String]) throws { try base.archiveReplaceLines(entry: entry, lines: lines) }
|
|
43
|
+
func archiveRemove(entry: String) throws { try base.archiveRemove(entry: entry) }
|
|
44
|
+
func archiveEntries(prefix: String) throws -> [ArchiveEntry] { try base.archiveEntries(prefix: prefix) }
|
|
45
|
+
func storageCapability() -> StorageCapability { base.storageCapability() }
|
|
46
|
+
}
|
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
|
+
}
|
|
@@ -11,30 +11,30 @@ import BackgroundTasks
|
|
|
11
11
|
/// enable Background Modes > Background fetch, and call `registerHandler` before
|
|
12
12
|
/// `application(_:didFinishLaunchingWithOptions:)` returns. Without the Info.plist entry a request
|
|
13
13
|
/// is refused, and the Runtime reports `schedule.degraded` with reason `not_configured`.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
final class AppRefreshScheduler: RuntimeScheduler, @unchecked Sendable {
|
|
15
|
+
let identifier: String
|
|
16
|
+
init(identifier: String) { self.identifier = identifier }
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
func schedule(earliest: Date) throws {
|
|
19
19
|
let request = BGAppRefreshTaskRequest(identifier: identifier)
|
|
20
20
|
request.earliestBeginDate = earliest
|
|
21
21
|
do { try BGTaskScheduler.shared.submit(request) }
|
|
22
22
|
catch let error as BGTaskScheduler.Error where error.code == .notPermitted {
|
|
23
|
-
throw
|
|
23
|
+
throw LegacyCrocheError("not_configured", "Add \(identifier) to BGTaskSchedulerPermittedIdentifiers and enable Background fetch")
|
|
24
24
|
} catch let error as BGTaskScheduler.Error where error.code == .unavailable {
|
|
25
|
-
throw
|
|
25
|
+
throw LegacyCrocheError("background_unavailable", "Background App Refresh is off or unavailable here")
|
|
26
26
|
} catch {
|
|
27
|
-
throw
|
|
27
|
+
throw LegacyCrocheError("schedule_failed", "BGTaskScheduler refused the request")
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
func cancel() { BGTaskScheduler.shared.cancel(taskRequestWithIdentifier: identifier) }
|
|
31
31
|
|
|
32
32
|
/// One open Runtime per identifier: a run delivers through the one Runtime its identifier
|
|
33
33
|
/// names (Atlas, #323 P1-2). This scheduler object is no exception: `create` attaches once per
|
|
34
34
|
/// Runtime, so a second attach while the identifier is held is refused, whoever holds it
|
|
35
35
|
/// (Atlas, #323 at dc38bf0). Close-and-reuse stays valid.
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
func attach() throws { try Self.claims.claim(identifier, by: self) }
|
|
37
|
+
func detach() { Self.claims.release(identifier, by: self) }
|
|
38
38
|
private static let claims = SchedulerClaims(what: "task identifier")
|
|
39
39
|
|
|
40
40
|
/// Registers what runs when iOS launches the task: `runtime` returns the app's Runtime
|
|
@@ -42,7 +42,7 @@ public final class AppRefreshScheduler: RuntimeScheduler, @unchecked Sendable {
|
|
|
42
42
|
/// iOS ends the background time first, the delivery turn is cancelled and its notes stay
|
|
43
43
|
/// pending. Call once, before `application(_:didFinishLaunchingWithOptions:)` returns.
|
|
44
44
|
@discardableResult
|
|
45
|
-
|
|
45
|
+
func registerHandler(runtime: @escaping @Sendable () async throws -> AgentEngine) -> Bool {
|
|
46
46
|
BGTaskScheduler.shared.register(forTaskWithIdentifier: identifier, using: nil) { task in
|
|
47
47
|
let granted = GrantedTask(task)
|
|
48
48
|
let delivery = BackgroundDelivery(open: runtime)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
/// Schema-6 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
|
+
/// Hard input-token cap per model call, independent of the model's own window, 1...16_777_216.
|
|
10
|
+
var maxTokens: Int?
|
|
11
|
+
init(turnTokens: Int? = nil, memoryShare: Double? = nil, maxTokens: Int? = nil) {
|
|
12
|
+
self.turnTokens = turnTokens
|
|
13
|
+
self.memoryShare = memoryShare
|
|
14
|
+
self.maxTokens = maxTokens
|
|
15
|
+
}
|
|
16
|
+
var json: JSON {
|
|
17
|
+
var value: JSON = .object([:])
|
|
18
|
+
if let turnTokens { value["turnTokens"] = .number(Double(turnTokens)) }
|
|
19
|
+
if let memoryShare { value["memoryShare"] = .number(memoryShare) }
|
|
20
|
+
if let maxTokens { value["maxTokens"] = .number(Double(maxTokens)) }
|
|
21
|
+
return value
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/// Input size contracts (`limits`), in UTF-16 code units (`String.utf16.count`). An input over
|
|
26
|
+
/// one fails with `input_too_large` and is never truncated; `Croche.truncate` cuts text to fit.
|
|
27
|
+
/// Core owns defaults and validation.
|
|
28
|
+
struct LimitsConfig: Sendable {
|
|
29
|
+
/// Total user and app-event text of one send, 1_000...200_000 (default 32_000).
|
|
30
|
+
var userTextChars: Int?
|
|
31
|
+
/// Total app-state text of one send, 1_000...200_000 (default 32_000).
|
|
32
|
+
var appStateChars: Int?
|
|
33
|
+
/// One tool result's value as compact JSON, 1_000...1_000_000 (default 200_000). Over it,
|
|
34
|
+
/// the turn fails.
|
|
35
|
+
var toolResultChars: Int?
|
|
36
|
+
init(userTextChars: Int? = nil, appStateChars: Int? = nil, toolResultChars: Int? = nil) {
|
|
37
|
+
self.userTextChars = userTextChars
|
|
38
|
+
self.appStateChars = appStateChars
|
|
39
|
+
self.toolResultChars = toolResultChars
|
|
40
|
+
}
|
|
41
|
+
var json: JSON {
|
|
42
|
+
var value: JSON = .object([:])
|
|
43
|
+
if let userTextChars { value["userTextChars"] = .number(Double(userTextChars)) }
|
|
44
|
+
if let appStateChars { value["appStateChars"] = .number(Double(appStateChars)) }
|
|
45
|
+
if let toolResultChars { value["toolResultChars"] = .number(Double(toolResultChars)) }
|
|
46
|
+
return value
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/// Application memory settings. Core owns defaults and validation.
|
|
51
|
+
struct MemoryConfig: Sendable {
|
|
52
|
+
var enabled: Bool?
|
|
53
|
+
var policy: String?
|
|
54
|
+
init(enabled: Bool? = nil, policy: String? = nil) {
|
|
55
|
+
self.enabled = enabled
|
|
56
|
+
self.policy = policy
|
|
57
|
+
}
|
|
58
|
+
var json: JSON {
|
|
59
|
+
var value: JSON = .object([:])
|
|
60
|
+
if let enabled { value["enabled"] = .bool(enabled) }
|
|
61
|
+
if let policy { value["policy"] = .string(policy) }
|
|
62
|
+
return value
|
|
63
|
+
}
|
|
64
|
+
}
|