@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
|
@@ -1,142 +1,173 @@
|
|
|
1
1
|
import Foundation
|
|
2
|
+
#if canImport(UIKit)
|
|
3
|
+
import UIKit
|
|
4
|
+
#elseif canImport(AppKit)
|
|
5
|
+
import AppKit
|
|
6
|
+
#endif
|
|
2
7
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
// Private legacy image preparation still uses this; it is not an App API export.
|
|
9
|
+
enum ImageResolution: String, Sendable, Codable { case standard, high }
|
|
10
|
+
/** One ordered input element. Core owns all validation, defaults and admission. */
|
|
11
|
+
public enum SendElement: Sendable, Equatable {
|
|
12
|
+
/// Text, with its input kind. `nil` leaves the kind to Core.
|
|
13
|
+
case text(String, kind: InputKind? = nil)
|
|
14
|
+
/// An image.
|
|
15
|
+
case image(ImageInput)
|
|
16
|
+
func wireJSON() throws -> JSON {
|
|
17
|
+
switch self {
|
|
18
|
+
case .text(let text, let kind):
|
|
19
|
+
var fields: [String: JSON] = ["type": .string("text"), "text": .string(text)]
|
|
20
|
+
if let kind { fields["kind"] = try JSON(data: JSONEncoder().encode(kind)) }
|
|
21
|
+
return .object(fields)
|
|
22
|
+
case .image(let image): return try image.wireJSON()
|
|
23
|
+
}
|
|
17
24
|
}
|
|
18
25
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
public
|
|
24
|
-
|
|
26
|
+
// APP-API ImageInput: uri or bytes, alt.
|
|
27
|
+
/** One image element, supplied by URI or encoded bytes. */
|
|
28
|
+
public struct ImageInput: Sendable, Equatable {
|
|
29
|
+
/// The image's URI, when it was given by URI.
|
|
30
|
+
public let uri: String?
|
|
31
|
+
private let image: Data?
|
|
32
|
+
/// Alternative text for the image.
|
|
33
|
+
public let alt: String?
|
|
34
|
+
/// An image read from `uri` by the native host.
|
|
35
|
+
public init(uri: String, alt: String? = nil) {
|
|
36
|
+
self.uri = uri; image = nil; self.alt = alt
|
|
25
37
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
public
|
|
29
|
-
|
|
30
|
-
public let kind: InputKind
|
|
31
|
-
public let images: [InputImage]
|
|
32
|
-
public let context: JSON?
|
|
33
|
-
public let inputs: [StackedInput]
|
|
34
|
-
public init(id: String, text: String, kind: InputKind = .user, images: [InputImage] = [], context: JSON? = nil) {
|
|
35
|
-
self.init(id: id, text: text, kind: kind, images: images, inputs: [], context: context)
|
|
38
|
+
/// Encoded JPEG or PNG bytes. They are captured when the send is reserved; Core decodes and
|
|
39
|
+
/// sizes them through this platform's codec (ImageIO).
|
|
40
|
+
public init(image: Data, alt: String? = nil) {
|
|
41
|
+
uri = nil; self.image = image; self.alt = alt
|
|
36
42
|
}
|
|
37
|
-
|
|
38
|
-
|
|
43
|
+
#if canImport(UIKit) && canImport(ImageIO) && !CROCHE_SUBSCRIPTION_HOST
|
|
44
|
+
/// A UIImage, drawn upright and encoded once as PNG now; then the same as `init(image: Data)`.
|
|
45
|
+
public init(image: UIImage, alt: String? = nil) throws {
|
|
46
|
+
let format = UIGraphicsImageRendererFormat.default(); format.scale = 1
|
|
47
|
+
let upright = UIGraphicsImageRenderer(size: CGSize(width: image.size.width * image.scale, height: image.size.height * image.scale), format: format)
|
|
48
|
+
.image { _ in image.draw(in: CGRect(x: 0, y: 0, width: image.size.width * image.scale, height: image.size.height * image.scale)) }
|
|
49
|
+
self.init(image: try NativeImagePal.encodedPNG(upright.cgImage), alt: alt)
|
|
39
50
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
init(
|
|
43
|
-
|
|
51
|
+
#elseif canImport(AppKit) && canImport(ImageIO) && !CROCHE_SUBSCRIPTION_HOST
|
|
52
|
+
/// An NSImage, encoded once as PNG now; then the same as `init(image: Data)`.
|
|
53
|
+
public init(image: NSImage, alt: String? = nil) throws {
|
|
54
|
+
var rect = CGRect(origin: .zero, size: image.size)
|
|
55
|
+
self.init(image: try NativeImagePal.encodedPNG(image.cgImage(forProposedRect: &rect, context: nil, hints: nil)),
|
|
56
|
+
alt: alt)
|
|
44
57
|
}
|
|
58
|
+
#endif
|
|
59
|
+
/// Bytes to capture at the reserved send entry; nil for a URI.
|
|
60
|
+
var capturedBytes: Data? { image }
|
|
45
61
|
func wireJSON() throws -> JSON {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
var partFields: [String: JSON] = ["kind": try kindJSON(part.kind)]
|
|
53
|
-
if let text = part.text { partFields["text"] = .string(text) }
|
|
54
|
-
if !part.images.isEmpty { partFields["images"] = .array(part.images.map(\.value)) }
|
|
55
|
-
return .object(partFields)
|
|
56
|
-
})
|
|
57
|
-
if !text.isEmpty { fields["text"] = .string(text) }
|
|
58
|
-
if kind != .user { fields["kind"] = try kindJSON(kind) }
|
|
59
|
-
} else {
|
|
60
|
-
fields["text"] = .string(text); fields["kind"] = try kindJSON(kind)
|
|
61
|
-
}
|
|
62
|
-
if !images.isEmpty { fields["images"] = .array(images.map(\.value)) }
|
|
63
|
-
guard fields["inputs"] == nil || (fields["text"] == nil && fields["kind"] == nil && fields["images"] == nil) else {
|
|
64
|
-
throw CrocheError("invalid_input", "Send either text and kind (one input) or inputs (a stack), not both")
|
|
62
|
+
// Owned bytes ride beside the JSON as a capture at this element's index. The element names
|
|
63
|
+
// neither bytes nor a slot: Core joins the position and writes `image: null` itself.
|
|
64
|
+
if image != nil {
|
|
65
|
+
var fields: [String: JSON] = ["type": .string("image")]
|
|
66
|
+
if let alt { fields["alt"] = .string(alt) }
|
|
67
|
+
return .object(fields)
|
|
65
68
|
}
|
|
69
|
+
var fields: [String: JSON] = ["type": .string("image"), "uri": .string(uri!)]
|
|
70
|
+
if let alt { fields["alt"] = .string(alt) }
|
|
66
71
|
return .object(fields)
|
|
67
72
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
}
|
|
74
|
+
/** One request; only an absent id asks Core to generate its identity. */
|
|
75
|
+
public struct SendInput: Sendable, Equatable {
|
|
76
|
+
/// The input id. Sending the last accepted id again with the same content joins or returns that input; with
|
|
77
|
+
/// other content it fails with `idempotency_conflict`.
|
|
78
|
+
public let id: String?
|
|
79
|
+
/// The ordered text and image elements.
|
|
80
|
+
public let input: [SendElement]
|
|
81
|
+
/// Creates a send input.
|
|
82
|
+
public init(id: String? = nil, input: [SendElement]) { self.id = id; self.input = input }
|
|
83
|
+
func wireJSON() throws -> JSON {
|
|
84
|
+
var fields: [String: JSON] = ["input": .array(try input.map { try $0.wireJSON() })]
|
|
85
|
+
if let id { fields["id"] = .string(id) }
|
|
86
|
+
return .object(fields)
|
|
87
|
+
}
|
|
88
|
+
func coreJSON(options: SendOptions) throws -> JSON { try wireJSON() }
|
|
89
|
+
/// The image elements given as bytes, by their position in `input`.
|
|
90
|
+
func imageCaptures() -> [(element: Int, bytes: Data)] {
|
|
91
|
+
input.enumerated().compactMap { index, element in
|
|
92
|
+
if case .image(let image) = element, let bytes = image.capturedBytes { return (index, bytes) }
|
|
93
|
+
return nil
|
|
94
|
+
}
|
|
75
95
|
}
|
|
76
96
|
}
|
|
97
|
+
/// Options for one send.
|
|
77
98
|
public struct SendOptions: Sendable, Equatable {
|
|
99
|
+
/// A structured-output format for the reply, passed to Core unchanged.
|
|
78
100
|
public let responseFormat: JSON?
|
|
79
|
-
|
|
80
|
-
public init(responseFormat: JSON? = nil
|
|
81
|
-
|
|
82
|
-
|
|
101
|
+
/// Creates send options.
|
|
102
|
+
public init(responseFormat: JSON? = nil) { self.responseFormat = responseFormat }
|
|
103
|
+
}
|
|
104
|
+
/// What `request` waits for beyond the input's terminal result.
|
|
105
|
+
public enum RequestWait: Sendable {
|
|
106
|
+
/// Also wait until the agent is idle.
|
|
107
|
+
case idle
|
|
83
108
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
public struct RequestResult: Sendable, Equatable {
|
|
109
|
+
struct LegacyReceipt: Sendable, Equatable { public let requestId: String; public let status: LegacyInputStatus; public let seq: Int? }
|
|
110
|
+
struct LegacyRequestResult: Sendable, Equatable {
|
|
87
111
|
public let id: String
|
|
88
|
-
public let status:
|
|
89
|
-
public let messages: [
|
|
112
|
+
public let status: LegacyInputStatus
|
|
113
|
+
public let messages: [LegacyMessageEnd]
|
|
90
114
|
public let gap: Bool
|
|
91
115
|
public let legacy: Bool
|
|
92
116
|
// RequestResult.pending comes with the coordinated TS/Swift/Kotlin consuming-unit change.
|
|
93
117
|
}
|
|
118
|
+
/// A position in an instance's stream log, for ``SubscribeOptions/after``.
|
|
94
119
|
public struct Cursor: Sendable, Codable, Hashable {
|
|
120
|
+
/// The log the position belongs to.
|
|
95
121
|
public let logId: String
|
|
122
|
+
/// The last sequence number seen.
|
|
96
123
|
public let seq: Int
|
|
124
|
+
/// Creates a cursor.
|
|
97
125
|
public init(logId: String, seq: Int) { self.logId = logId; self.seq = seq }
|
|
98
126
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
127
|
+
struct LegacyStreamError: Sendable, Codable, Equatable { public let code: String; public let message: String; public let poisoned: Bool }
|
|
128
|
+
struct LegacyRuntimeError: Sendable, Codable, Hashable { public let code: String; public let message: String }
|
|
129
|
+
struct LegacyToolSource: Sendable, Codable, Equatable { public let command: String; public let callId: String }
|
|
130
|
+
struct LegacyImageSummary: Sendable, Codable, Equatable { public let alt: String?; public let mime: String?; public let bytes: Int? }
|
|
131
|
+
struct LegacyInputEvent: Sendable, Codable, Equatable {
|
|
104
132
|
public let seq: Int; public let firstSeq: Int; public let id: String; public let kind: InputKind
|
|
105
|
-
public let text: String?; public let images: [
|
|
106
|
-
public let error:
|
|
133
|
+
public let text: String?; public let images: [LegacyImageSummary]; public let status: LegacyInputStatus
|
|
134
|
+
public let error: LegacyRuntimeError?; public let at: Date
|
|
107
135
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
136
|
+
struct LegacyMessageStart: Sendable, Codable, Equatable { public let seq: Int; public let firstSeq: Int; public let id: String; public let at: Date }
|
|
137
|
+
struct LegacyMessageDelta: Sendable, Codable, Equatable { public let id: String; public let text: String }
|
|
138
|
+
struct LegacyMessageEnd: Sendable, Codable, Equatable {
|
|
111
139
|
public let seq: Int; public let firstSeq: Int; public let id: String
|
|
112
|
-
public let status:
|
|
113
|
-
public let inReplyTo: [String]; public let causedBy: [String]; public let error:
|
|
140
|
+
public let status: LegacyMessageStatus; public let text: String; public let markers: [String]; public let output: JSON?
|
|
141
|
+
public let inReplyTo: [String]; public let causedBy: [String]; public let error: LegacyRuntimeError?; public let at: Date
|
|
114
142
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
143
|
+
struct LegacyCleared: Sendable, Codable, Equatable { public let seq: Int; public let id: String; public let at: Date }
|
|
144
|
+
struct LegacyPage: Sendable, Equatable { public let messages: [LegacyRuntimeEvent]; public let reachedFloor: Bool; public let logId: String; public let clearedSeq: Int }
|
|
145
|
+
struct LegacyAppStreamEvent: Sendable, Codable, Equatable { public let seq: Int; public let id: String; public let name: String; public let data: JSON; public let source: LegacyToolSource; public let at: Date }
|
|
146
|
+
struct LegacyTurnEvent: Sendable, Codable, Equatable {
|
|
119
147
|
public let seq: Int; public let id: String; public let causedBy: [String]; public let inputs: [String]; public let purpose: String; public let usage: [String: Int]
|
|
120
|
-
public let costUsd: Double; public let costStatus:
|
|
148
|
+
public let costUsd: Double; public let costStatus: LegacyCostStatus; public let model: String; public let imagesOmitted: Int?; public let at: Date
|
|
121
149
|
}
|
|
122
|
-
|
|
123
|
-
public let status:
|
|
150
|
+
struct LegacyStateEvent: Sendable, Codable, Equatable {
|
|
151
|
+
public let status: LegacyAgentStatus; public let queued: Int; public let typing: Bool
|
|
124
152
|
/// What a running agent waits on: set exactly while `status` is `.running`, nil otherwise.
|
|
125
|
-
public let activity:
|
|
153
|
+
public let activity: LegacyAgentActivity?
|
|
126
154
|
/// With `.tool` only: the command keys the round runs, in call order. Never arguments.
|
|
127
155
|
public let tools: [String]?
|
|
128
|
-
public init(status:
|
|
156
|
+
public init(status: LegacyAgentStatus, queued: Int, typing: Bool, activity: LegacyAgentActivity? = nil, tools: [String]? = nil) {
|
|
129
157
|
self.status = status; self.queued = queued; self.typing = typing; self.activity = activity; self.tools = tools
|
|
130
158
|
}
|
|
131
159
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
case input(
|
|
138
|
-
case cleared(
|
|
139
|
-
case gap(
|
|
160
|
+
struct LegacyErrorEvent: Sendable, Codable, Equatable { public let seq: Int; public let id: String; public let code: String; public let message: String; public let inputs: [String]; public let at: Date }
|
|
161
|
+
struct LegacyGap: Sendable, Codable, Equatable { public let afterSeq: Int; public let throughSeq: Int; public let reason: LegacyGapReason }
|
|
162
|
+
struct LegacySnapshot: Sendable, Codable, Equatable { public let logId: String; public let state: LegacyStateEvent; public let streaming: LegacyStreaming? }
|
|
163
|
+
struct LegacyStreaming: Sendable, Codable, Equatable { public let messageId: String; public let firstSeq: Int; public let text: String }
|
|
164
|
+
enum LegacyRuntimeEvent: Sendable, Equatable {
|
|
165
|
+
case input(LegacyInputEvent), messageStart(LegacyMessageStart), messageDelta(LegacyMessageDelta), messageEnd(LegacyMessageEnd)
|
|
166
|
+
case cleared(LegacyCleared), page(LegacyPage), app(LegacyAppStreamEvent), turn(LegacyTurnEvent), state(LegacyStateEvent), error(LegacyErrorEvent)
|
|
167
|
+
case gap(LegacyGap), snapshot(LegacySnapshot), streamError(LegacyStreamError), replaced
|
|
168
|
+
/// An event type this SDK does not know (D-e: reader types are open): its type and every
|
|
169
|
+
/// other field, kept as they came. Ignore it, or read `fields`.
|
|
170
|
+
case unknown(type: String, fields: JSON = .object([:]))
|
|
140
171
|
public var seq: Int? {
|
|
141
172
|
switch self {
|
|
142
173
|
case .input(let v): v.seq
|
|
@@ -151,27 +182,39 @@ public enum RuntimeEvent: Sendable, Equatable {
|
|
|
151
182
|
}
|
|
152
183
|
}
|
|
153
184
|
|
|
185
|
+
/// Who an input's text comes from.
|
|
154
186
|
public enum InputKind: Sendable, Codable, Hashable {
|
|
155
|
-
|
|
187
|
+
/// Text the user wrote.
|
|
188
|
+
case user
|
|
189
|
+
/// An app event for the agent (`app_event`).
|
|
190
|
+
case appEvent
|
|
191
|
+
/// App state for the agent (`app_state`).
|
|
192
|
+
case appState
|
|
193
|
+
/// A kind this SDK does not know, kept as sent.
|
|
194
|
+
case unknown(String)
|
|
195
|
+
/// Decodes the wire string.
|
|
156
196
|
public init(from decoder: Decoder) throws {
|
|
157
197
|
let value = try decoder.singleValueContainer().decode(String.self)
|
|
158
198
|
switch value {
|
|
159
199
|
case "user": self = .user
|
|
160
|
-
case "
|
|
200
|
+
case "app_event": self = .appEvent
|
|
201
|
+
case "app_state": self = .appState
|
|
161
202
|
default: self = .unknown(value)
|
|
162
203
|
}
|
|
163
204
|
}
|
|
205
|
+
/// Encodes the wire string.
|
|
164
206
|
public func encode(to encoder: Encoder) throws {
|
|
165
207
|
var container = encoder.singleValueContainer()
|
|
166
208
|
switch self {
|
|
167
209
|
case .user: try container.encode("user")
|
|
168
|
-
case .
|
|
210
|
+
case .appEvent: try container.encode("app_event")
|
|
211
|
+
case .appState: try container.encode("app_state")
|
|
169
212
|
case .unknown(let value): try container.encode(value)
|
|
170
213
|
}
|
|
171
214
|
}
|
|
172
215
|
}
|
|
173
216
|
|
|
174
|
-
|
|
217
|
+
enum LegacyInputStatus: Sendable, Codable, Hashable {
|
|
175
218
|
case queued, seen, answered, noReply, failed, cancelled, settledBeforeUpgrade, unknown(String)
|
|
176
219
|
public init(from decoder: Decoder) throws {
|
|
177
220
|
let value = try decoder.singleValueContainer().decode(String.self)
|
|
@@ -201,7 +244,7 @@ public enum InputStatus: Sendable, Codable, Hashable {
|
|
|
201
244
|
}
|
|
202
245
|
}
|
|
203
246
|
|
|
204
|
-
|
|
247
|
+
enum LegacyMessageStatus: Sendable, Codable, Hashable {
|
|
205
248
|
case completed, failed, cancelled, interrupted, unknown(String)
|
|
206
249
|
public init(from decoder: Decoder) throws {
|
|
207
250
|
let value = try decoder.singleValueContainer().decode(String.self)
|
|
@@ -227,7 +270,7 @@ public enum MessageStatus: Sendable, Codable, Hashable {
|
|
|
227
270
|
|
|
228
271
|
/// The stream `state`'s `activity`: a model call, a summary call (held before the reply), or a
|
|
229
272
|
/// tool round. A value this SDK does not know yet decodes as `.unknown`, never a stream error.
|
|
230
|
-
|
|
273
|
+
enum LegacyAgentActivity: Sendable, Codable, Hashable {
|
|
231
274
|
case model, summary, tool, unknown(String)
|
|
232
275
|
public init(from decoder: Decoder) throws {
|
|
233
276
|
let value = try decoder.singleValueContainer().decode(String.self)
|
|
@@ -248,7 +291,7 @@ public enum AgentActivity: Sendable, Codable, Hashable {
|
|
|
248
291
|
}
|
|
249
292
|
}
|
|
250
293
|
}
|
|
251
|
-
|
|
294
|
+
enum LegacyAgentStatus: Sendable, Codable, Hashable {
|
|
252
295
|
case running, waiting, idle, unknown(String)
|
|
253
296
|
public init(from decoder: Decoder) throws {
|
|
254
297
|
let value = try decoder.singleValueContainer().decode(String.self)
|
|
@@ -270,7 +313,7 @@ public enum AgentStatus: Sendable, Codable, Hashable {
|
|
|
270
313
|
}
|
|
271
314
|
}
|
|
272
315
|
|
|
273
|
-
|
|
316
|
+
enum LegacyCostStatus: Sendable, Codable, Hashable {
|
|
274
317
|
case reported, estimated, none, unknown(String)
|
|
275
318
|
public init(from decoder: Decoder) throws {
|
|
276
319
|
let value = try decoder.singleValueContainer().decode(String.self)
|
|
@@ -292,7 +335,7 @@ public enum CostStatus: Sendable, Codable, Hashable {
|
|
|
292
335
|
}
|
|
293
336
|
}
|
|
294
337
|
|
|
295
|
-
|
|
338
|
+
enum LegacyGapReason: Sendable, Codable, Hashable {
|
|
296
339
|
case cleared, limit, unknown(String)
|
|
297
340
|
public init(from decoder: Decoder) throws {
|
|
298
341
|
let value = try decoder.singleValueContainer().decode(String.self)
|
|
@@ -312,34 +355,38 @@ public enum GapReason: Sendable, Codable, Hashable {
|
|
|
312
355
|
}
|
|
313
356
|
}
|
|
314
357
|
|
|
315
|
-
extension
|
|
358
|
+
extension LegacyInputStatus {
|
|
316
359
|
var terminal: Bool {
|
|
317
360
|
switch self { case .answered, .noReply, .failed, .cancelled, .settledBeforeUpgrade: true; default: false }
|
|
318
361
|
}
|
|
319
362
|
}
|
|
320
363
|
func clampedMaintenanceInterval(_ seconds: TimeInterval) throws -> TimeInterval {
|
|
321
|
-
guard seconds.isFinite else { throw
|
|
364
|
+
guard seconds.isFinite else { throw LegacyCrocheError("invalid_configuration", "maintenanceInterval must be finite") }
|
|
322
365
|
return max(1, seconds)
|
|
323
366
|
}
|
|
324
367
|
|
|
368
|
+
/// Options for `request`.
|
|
325
369
|
public struct RequestOptions: Sendable {
|
|
370
|
+
/// A structured-output format for the reply, passed to Core unchanged.
|
|
326
371
|
public var responseFormat: JSON?
|
|
372
|
+
/// `.idle` also waits until the agent is idle; `nil` returns at the input's terminal result.
|
|
327
373
|
public var wait: RequestWait?
|
|
374
|
+
/// Creates request options.
|
|
328
375
|
public init(responseFormat: JSON? = nil, wait: RequestWait? = nil) { self.responseFormat = responseFormat; self.wait = wait }
|
|
329
376
|
}
|
|
330
|
-
|
|
377
|
+
struct LegacySubscribeOptions: Sendable {
|
|
331
378
|
public var initialMessages: Int?
|
|
332
379
|
public var after: Cursor?
|
|
333
|
-
public var onEvent: @Sendable (
|
|
334
|
-
public init(initialMessages: Int? = nil, after: Cursor? = nil, onEvent: @escaping @Sendable (
|
|
380
|
+
public var onEvent: @Sendable (LegacyRuntimeEvent) async -> Void
|
|
381
|
+
public init(initialMessages: Int? = nil, after: Cursor? = nil, onEvent: @escaping @Sendable (LegacyRuntimeEvent) async -> Void) {
|
|
335
382
|
self.initialMessages = initialMessages; self.after = after; self.onEvent = onEvent
|
|
336
383
|
}
|
|
337
384
|
}
|
|
338
|
-
|
|
385
|
+
struct LegacyHistoryOptions: Sendable {
|
|
339
386
|
public var before: Int?
|
|
340
387
|
public var limit: Int
|
|
341
388
|
public init(before: Int? = nil, limit: Int) { self.before = before; self.limit = limit }
|
|
342
389
|
}
|
|
343
|
-
|
|
390
|
+
struct LegacyAppStreamEnd: Sendable, Equatable {
|
|
344
391
|
public let code: String
|
|
345
392
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
extension LegacyCroche {
|
|
4
|
+
/// The longest prefix of `text` that is at most `max` UTF-16 code units (the unit of the
|
|
5
|
+
/// `limits.*Chars` settings): text that fits comes back unchanged, a surrogate pair is never
|
|
6
|
+
/// split (so the result can be one unit short), and nothing is appended. Croche never
|
|
7
|
+
/// truncates an input itself: an input over a limit fails with `input_too_large`, so cut your
|
|
8
|
+
/// own text with this first. A negative `max` throws `invalid_input`.
|
|
9
|
+
static func truncate(_ text: String, max: Int) throws -> String {
|
|
10
|
+
do { return try ffiTruncate(text, Double(max)) } catch { throw LegacyCrocheError(error) }
|
|
11
|
+
}
|
|
12
|
+
}
|