@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
|
@@ -1,92 +1,99 @@
|
|
|
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
|
+
case text(String, kind: InputKind? = nil)
|
|
13
|
+
case image(ImageInput)
|
|
14
|
+
func wireJSON() throws -> JSON {
|
|
15
|
+
switch self {
|
|
16
|
+
case .text(let text, let kind):
|
|
17
|
+
var fields: [String: JSON] = ["type": .string("text"), "text": .string(text)]
|
|
18
|
+
if let kind { fields["kind"] = try JSON(data: JSONEncoder().encode(kind)) }
|
|
19
|
+
return .object(fields)
|
|
20
|
+
case .image(let image): return try image.wireJSON()
|
|
21
|
+
}
|
|
17
22
|
}
|
|
18
23
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
public let
|
|
22
|
-
|
|
23
|
-
public
|
|
24
|
-
|
|
24
|
+
/** One image element, supplied by URI or encoded bytes (APP-API ImageInput: uri or bytes, alt). */
|
|
25
|
+
public struct ImageInput: Sendable, Equatable {
|
|
26
|
+
public let uri: String?
|
|
27
|
+
private let image: Data?
|
|
28
|
+
public let alt: String?
|
|
29
|
+
public init(uri: String, alt: String? = nil) {
|
|
30
|
+
self.uri = uri; image = nil; self.alt = alt
|
|
25
31
|
}
|
|
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)
|
|
32
|
+
/// Encoded JPEG or PNG bytes. They are captured when the send is reserved; Core decodes and
|
|
33
|
+
/// sizes them through this platform's codec (ImageIO).
|
|
34
|
+
public init(image: Data, alt: String? = nil) {
|
|
35
|
+
uri = nil; self.image = image; self.alt = alt
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
#if canImport(UIKit) && canImport(ImageIO) && !CROCHE_SUBSCRIPTION_HOST
|
|
38
|
+
/// A UIImage, drawn upright and encoded once as PNG now; then the same as `init(image: Data)`.
|
|
39
|
+
public init(image: UIImage, alt: String? = nil) throws {
|
|
40
|
+
let format = UIGraphicsImageRendererFormat.default(); format.scale = 1
|
|
41
|
+
let upright = UIGraphicsImageRenderer(size: CGSize(width: image.size.width * image.scale, height: image.size.height * image.scale), format: format)
|
|
42
|
+
.image { _ in image.draw(in: CGRect(x: 0, y: 0, width: image.size.width * image.scale, height: image.size.height * image.scale)) }
|
|
43
|
+
self.init(image: try NativeImagePal.encodedPNG(upright.cgImage), alt: alt)
|
|
39
44
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
init(
|
|
43
|
-
|
|
45
|
+
#elseif canImport(AppKit) && canImport(ImageIO) && !CROCHE_SUBSCRIPTION_HOST
|
|
46
|
+
/// An NSImage, encoded once as PNG now; then the same as `init(image: Data)`.
|
|
47
|
+
public init(image: NSImage, alt: String? = nil) throws {
|
|
48
|
+
var rect = CGRect(origin: .zero, size: image.size)
|
|
49
|
+
self.init(image: try NativeImagePal.encodedPNG(image.cgImage(forProposedRect: &rect, context: nil, hints: nil)),
|
|
50
|
+
alt: alt)
|
|
44
51
|
}
|
|
52
|
+
#endif
|
|
53
|
+
/// Bytes to capture at the reserved send entry; nil for a URI.
|
|
54
|
+
var capturedBytes: Data? { image }
|
|
45
55
|
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")
|
|
56
|
+
// Owned bytes ride beside the JSON as a capture at this element's index. The element names
|
|
57
|
+
// neither bytes nor a slot: Core joins the position and writes `image: null` itself.
|
|
58
|
+
if image != nil {
|
|
59
|
+
var fields: [String: JSON] = ["type": .string("image")]
|
|
60
|
+
if let alt { fields["alt"] = .string(alt) }
|
|
61
|
+
return .object(fields)
|
|
65
62
|
}
|
|
63
|
+
var fields: [String: JSON] = ["type": .string("image"), "uri": .string(uri!)]
|
|
64
|
+
if let alt { fields["alt"] = .string(alt) }
|
|
66
65
|
return .object(fields)
|
|
67
66
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
}
|
|
68
|
+
/** One request; only an absent id asks Core to generate its identity. */
|
|
69
|
+
public struct SendInput: Sendable, Equatable {
|
|
70
|
+
public let id: String?
|
|
71
|
+
public let input: [SendElement]
|
|
72
|
+
public init(id: String? = nil, input: [SendElement]) { self.id = id; self.input = input }
|
|
73
|
+
func wireJSON() throws -> JSON {
|
|
74
|
+
var fields: [String: JSON] = ["input": .array(try input.map { try $0.wireJSON() })]
|
|
75
|
+
if let id { fields["id"] = .string(id) }
|
|
76
|
+
return .object(fields)
|
|
77
|
+
}
|
|
78
|
+
func coreJSON(options: SendOptions) throws -> JSON { try wireJSON() }
|
|
79
|
+
/// The image elements given as bytes, by their position in `input`.
|
|
80
|
+
func imageCaptures() -> [(element: Int, bytes: Data)] {
|
|
81
|
+
input.enumerated().compactMap { index, element in
|
|
82
|
+
if case .image(let image) = element, let bytes = image.capturedBytes { return (index, bytes) }
|
|
83
|
+
return nil
|
|
84
|
+
}
|
|
75
85
|
}
|
|
76
86
|
}
|
|
77
87
|
public struct SendOptions: Sendable, Equatable {
|
|
78
88
|
public let responseFormat: JSON?
|
|
79
|
-
public
|
|
80
|
-
public init(responseFormat: JSON? = nil, imageResolution: ImageResolution? = nil) {
|
|
81
|
-
self.responseFormat = responseFormat; self.imageResolution = imageResolution
|
|
82
|
-
}
|
|
89
|
+
public init(responseFormat: JSON? = nil) { self.responseFormat = responseFormat }
|
|
83
90
|
}
|
|
84
91
|
public enum RequestWait: Sendable { case idle }
|
|
85
|
-
|
|
86
|
-
|
|
92
|
+
struct LegacyReceipt: Sendable, Equatable { public let requestId: String; public let status: LegacyInputStatus; public let seq: Int? }
|
|
93
|
+
struct LegacyRequestResult: Sendable, Equatable {
|
|
87
94
|
public let id: String
|
|
88
|
-
public let status:
|
|
89
|
-
public let messages: [
|
|
95
|
+
public let status: LegacyInputStatus
|
|
96
|
+
public let messages: [LegacyMessageEnd]
|
|
90
97
|
public let gap: Bool
|
|
91
98
|
public let legacy: Bool
|
|
92
99
|
// RequestResult.pending comes with the coordinated TS/Swift/Kotlin consuming-unit change.
|
|
@@ -96,47 +103,50 @@ public struct Cursor: Sendable, Codable, Hashable {
|
|
|
96
103
|
public let seq: Int
|
|
97
104
|
public init(logId: String, seq: Int) { self.logId = logId; self.seq = seq }
|
|
98
105
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
106
|
+
struct LegacyStreamError: Sendable, Codable, Equatable { public let code: String; public let message: String; public let poisoned: Bool }
|
|
107
|
+
struct LegacyRuntimeError: Sendable, Codable, Hashable { public let code: String; public let message: String }
|
|
108
|
+
struct LegacyToolSource: Sendable, Codable, Equatable { public let command: String; public let callId: String }
|
|
109
|
+
struct LegacyImageSummary: Sendable, Codable, Equatable { public let alt: String?; public let mime: String?; public let bytes: Int? }
|
|
110
|
+
struct LegacyInputEvent: Sendable, Codable, Equatable {
|
|
104
111
|
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:
|
|
112
|
+
public let text: String?; public let images: [LegacyImageSummary]; public let status: LegacyInputStatus
|
|
113
|
+
public let error: LegacyRuntimeError?; public let at: Date
|
|
107
114
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
115
|
+
struct LegacyMessageStart: Sendable, Codable, Equatable { public let seq: Int; public let firstSeq: Int; public let id: String; public let at: Date }
|
|
116
|
+
struct LegacyMessageDelta: Sendable, Codable, Equatable { public let id: String; public let text: String }
|
|
117
|
+
struct LegacyMessageEnd: Sendable, Codable, Equatable {
|
|
111
118
|
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:
|
|
119
|
+
public let status: LegacyMessageStatus; public let text: String; public let markers: [String]; public let output: JSON?
|
|
120
|
+
public let inReplyTo: [String]; public let causedBy: [String]; public let error: LegacyRuntimeError?; public let at: Date
|
|
114
121
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
122
|
+
struct LegacyCleared: Sendable, Codable, Equatable { public let seq: Int; public let id: String; public let at: Date }
|
|
123
|
+
struct LegacyPage: Sendable, Equatable { public let messages: [LegacyRuntimeEvent]; public let reachedFloor: Bool; public let logId: String; public let clearedSeq: Int }
|
|
124
|
+
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 }
|
|
125
|
+
struct LegacyTurnEvent: Sendable, Codable, Equatable {
|
|
119
126
|
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:
|
|
127
|
+
public let costUsd: Double; public let costStatus: LegacyCostStatus; public let model: String; public let imagesOmitted: Int?; public let at: Date
|
|
121
128
|
}
|
|
122
|
-
|
|
123
|
-
public let status:
|
|
129
|
+
struct LegacyStateEvent: Sendable, Codable, Equatable {
|
|
130
|
+
public let status: LegacyAgentStatus; public let queued: Int; public let typing: Bool
|
|
124
131
|
/// What a running agent waits on: set exactly while `status` is `.running`, nil otherwise.
|
|
125
|
-
public let activity:
|
|
132
|
+
public let activity: LegacyAgentActivity?
|
|
126
133
|
/// With `.tool` only: the command keys the round runs, in call order. Never arguments.
|
|
127
134
|
public let tools: [String]?
|
|
128
|
-
public init(status:
|
|
135
|
+
public init(status: LegacyAgentStatus, queued: Int, typing: Bool, activity: LegacyAgentActivity? = nil, tools: [String]? = nil) {
|
|
129
136
|
self.status = status; self.queued = queued; self.typing = typing; self.activity = activity; self.tools = tools
|
|
130
137
|
}
|
|
131
138
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
case input(
|
|
138
|
-
case cleared(
|
|
139
|
-
case gap(
|
|
139
|
+
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 }
|
|
140
|
+
struct LegacyGap: Sendable, Codable, Equatable { public let afterSeq: Int; public let throughSeq: Int; public let reason: LegacyGapReason }
|
|
141
|
+
struct LegacySnapshot: Sendable, Codable, Equatable { public let logId: String; public let state: LegacyStateEvent; public let streaming: LegacyStreaming? }
|
|
142
|
+
struct LegacyStreaming: Sendable, Codable, Equatable { public let messageId: String; public let firstSeq: Int; public let text: String }
|
|
143
|
+
enum LegacyRuntimeEvent: Sendable, Equatable {
|
|
144
|
+
case input(LegacyInputEvent), messageStart(LegacyMessageStart), messageDelta(LegacyMessageDelta), messageEnd(LegacyMessageEnd)
|
|
145
|
+
case cleared(LegacyCleared), page(LegacyPage), app(LegacyAppStreamEvent), turn(LegacyTurnEvent), state(LegacyStateEvent), error(LegacyErrorEvent)
|
|
146
|
+
case gap(LegacyGap), snapshot(LegacySnapshot), streamError(LegacyStreamError), replaced
|
|
147
|
+
/// An event type this SDK does not know (D-e: reader types are open): its type and every
|
|
148
|
+
/// other field, kept as they came. Ignore it, or read `fields`.
|
|
149
|
+
case unknown(type: String, fields: JSON = .object([:]))
|
|
140
150
|
public var seq: Int? {
|
|
141
151
|
switch self {
|
|
142
152
|
case .input(let v): v.seq
|
|
@@ -152,12 +162,13 @@ public enum RuntimeEvent: Sendable, Equatable {
|
|
|
152
162
|
}
|
|
153
163
|
|
|
154
164
|
public enum InputKind: Sendable, Codable, Hashable {
|
|
155
|
-
case user,
|
|
165
|
+
case user, appEvent, appState, unknown(String)
|
|
156
166
|
public init(from decoder: Decoder) throws {
|
|
157
167
|
let value = try decoder.singleValueContainer().decode(String.self)
|
|
158
168
|
switch value {
|
|
159
169
|
case "user": self = .user
|
|
160
|
-
case "
|
|
170
|
+
case "app_event": self = .appEvent
|
|
171
|
+
case "app_state": self = .appState
|
|
161
172
|
default: self = .unknown(value)
|
|
162
173
|
}
|
|
163
174
|
}
|
|
@@ -165,13 +176,14 @@ public enum InputKind: Sendable, Codable, Hashable {
|
|
|
165
176
|
var container = encoder.singleValueContainer()
|
|
166
177
|
switch self {
|
|
167
178
|
case .user: try container.encode("user")
|
|
168
|
-
case .
|
|
179
|
+
case .appEvent: try container.encode("app_event")
|
|
180
|
+
case .appState: try container.encode("app_state")
|
|
169
181
|
case .unknown(let value): try container.encode(value)
|
|
170
182
|
}
|
|
171
183
|
}
|
|
172
184
|
}
|
|
173
185
|
|
|
174
|
-
|
|
186
|
+
enum LegacyInputStatus: Sendable, Codable, Hashable {
|
|
175
187
|
case queued, seen, answered, noReply, failed, cancelled, settledBeforeUpgrade, unknown(String)
|
|
176
188
|
public init(from decoder: Decoder) throws {
|
|
177
189
|
let value = try decoder.singleValueContainer().decode(String.self)
|
|
@@ -201,7 +213,7 @@ public enum InputStatus: Sendable, Codable, Hashable {
|
|
|
201
213
|
}
|
|
202
214
|
}
|
|
203
215
|
|
|
204
|
-
|
|
216
|
+
enum LegacyMessageStatus: Sendable, Codable, Hashable {
|
|
205
217
|
case completed, failed, cancelled, interrupted, unknown(String)
|
|
206
218
|
public init(from decoder: Decoder) throws {
|
|
207
219
|
let value = try decoder.singleValueContainer().decode(String.self)
|
|
@@ -227,7 +239,7 @@ public enum MessageStatus: Sendable, Codable, Hashable {
|
|
|
227
239
|
|
|
228
240
|
/// The stream `state`'s `activity`: a model call, a summary call (held before the reply), or a
|
|
229
241
|
/// tool round. A value this SDK does not know yet decodes as `.unknown`, never a stream error.
|
|
230
|
-
|
|
242
|
+
enum LegacyAgentActivity: Sendable, Codable, Hashable {
|
|
231
243
|
case model, summary, tool, unknown(String)
|
|
232
244
|
public init(from decoder: Decoder) throws {
|
|
233
245
|
let value = try decoder.singleValueContainer().decode(String.self)
|
|
@@ -248,7 +260,7 @@ public enum AgentActivity: Sendable, Codable, Hashable {
|
|
|
248
260
|
}
|
|
249
261
|
}
|
|
250
262
|
}
|
|
251
|
-
|
|
263
|
+
enum LegacyAgentStatus: Sendable, Codable, Hashable {
|
|
252
264
|
case running, waiting, idle, unknown(String)
|
|
253
265
|
public init(from decoder: Decoder) throws {
|
|
254
266
|
let value = try decoder.singleValueContainer().decode(String.self)
|
|
@@ -270,7 +282,7 @@ public enum AgentStatus: Sendable, Codable, Hashable {
|
|
|
270
282
|
}
|
|
271
283
|
}
|
|
272
284
|
|
|
273
|
-
|
|
285
|
+
enum LegacyCostStatus: Sendable, Codable, Hashable {
|
|
274
286
|
case reported, estimated, none, unknown(String)
|
|
275
287
|
public init(from decoder: Decoder) throws {
|
|
276
288
|
let value = try decoder.singleValueContainer().decode(String.self)
|
|
@@ -292,7 +304,7 @@ public enum CostStatus: Sendable, Codable, Hashable {
|
|
|
292
304
|
}
|
|
293
305
|
}
|
|
294
306
|
|
|
295
|
-
|
|
307
|
+
enum LegacyGapReason: Sendable, Codable, Hashable {
|
|
296
308
|
case cleared, limit, unknown(String)
|
|
297
309
|
public init(from decoder: Decoder) throws {
|
|
298
310
|
let value = try decoder.singleValueContainer().decode(String.self)
|
|
@@ -312,13 +324,13 @@ public enum GapReason: Sendable, Codable, Hashable {
|
|
|
312
324
|
}
|
|
313
325
|
}
|
|
314
326
|
|
|
315
|
-
extension
|
|
327
|
+
extension LegacyInputStatus {
|
|
316
328
|
var terminal: Bool {
|
|
317
329
|
switch self { case .answered, .noReply, .failed, .cancelled, .settledBeforeUpgrade: true; default: false }
|
|
318
330
|
}
|
|
319
331
|
}
|
|
320
332
|
func clampedMaintenanceInterval(_ seconds: TimeInterval) throws -> TimeInterval {
|
|
321
|
-
guard seconds.isFinite else { throw
|
|
333
|
+
guard seconds.isFinite else { throw LegacyCrocheError("invalid_configuration", "maintenanceInterval must be finite") }
|
|
322
334
|
return max(1, seconds)
|
|
323
335
|
}
|
|
324
336
|
|
|
@@ -327,19 +339,22 @@ public struct RequestOptions: Sendable {
|
|
|
327
339
|
public var wait: RequestWait?
|
|
328
340
|
public init(responseFormat: JSON? = nil, wait: RequestWait? = nil) { self.responseFormat = responseFormat; self.wait = wait }
|
|
329
341
|
}
|
|
330
|
-
|
|
342
|
+
struct LegacySubscribeOptions: Sendable {
|
|
331
343
|
public var initialMessages: Int?
|
|
332
344
|
public var after: Cursor?
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
345
|
+
/// How Core batches `messageDelta`. Nil = omitted: Core applies its platform default. The SDK
|
|
346
|
+
/// sets none and passes a value (0 included) to Core unchanged.
|
|
347
|
+
public var deltaMs: Int?
|
|
348
|
+
public var onEvent: @Sendable (LegacyRuntimeEvent) async -> Void
|
|
349
|
+
public init(initialMessages: Int? = nil, after: Cursor? = nil, deltaMs: Int? = nil, onEvent: @escaping @Sendable (LegacyRuntimeEvent) async -> Void) {
|
|
350
|
+
self.initialMessages = initialMessages; self.after = after; self.deltaMs = deltaMs; self.onEvent = onEvent
|
|
336
351
|
}
|
|
337
352
|
}
|
|
338
|
-
|
|
353
|
+
struct LegacyHistoryOptions: Sendable {
|
|
339
354
|
public var before: Int?
|
|
340
355
|
public var limit: Int
|
|
341
356
|
public init(before: Int? = nil, limit: Int) { self.before = before; self.limit = limit }
|
|
342
357
|
}
|
|
343
|
-
|
|
358
|
+
struct LegacyAppStreamEnd: Sendable, Equatable {
|
|
344
359
|
public let code: String
|
|
345
360
|
}
|
|
@@ -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
|
+
}
|