@h1r-ai/croche-react-native 0.0.0-stage → 0.5.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 +32 -0
- package/README.md +475 -2
- package/THIRD-PARTY-NOTICES +5824 -0
- package/android/build.gradle +47 -0
- package/android/src/main/AndroidManifest.xml +8 -0
- package/android/src/main/java/dev/croche/reactnative/AgentMemory.kt +25 -0
- package/android/src/main/java/dev/croche/reactnative/CrocheRuntimeModule.kt +836 -0
- package/android/src/main/java/dev/croche/reactnative/CrocheRuntimePackage.kt +22 -0
- package/android/src/main/java/dev/croche/reactnative/ProjectAttestation.kt +17 -0
- package/android/src/test/java/dev/croche/reactnative/AgentMemoryTest.kt +49 -0
- package/android/src/test/java/dev/croche/reactnative/ProjectAttestationTest.kt +42 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/AndroidPlatform.kt +133 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapImageCodec.kt +47 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/CrocheProjectRecordProvider.kt +25 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/WorkManagerScheduler.kt +146 -0
- package/android/vendor/CrocheRuntimeSDK/consumer-rules.pro +9 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/AppStreamBranch.kt +110 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Control.kt +178 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Core.kt +12 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheRuntime.kt +405 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Effects.kt +195 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Host.kt +368 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Images.kt +161 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/NativeCoreStreamPort.kt +173 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Platform.kt +105 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectRecords.kt +87 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/SendEncoding.kt +27 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Storage.kt +181 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/StreamHub.kt +211 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/SubscriptionTypes.kt +74 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ffi/croche_ffi.kt +8316 -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 +28 -0
- package/ios/CrocheRuntimeBridge.swift +986 -0
- package/ios/RNCrocheRuntime.mm +221 -0
- package/ios/vendor/CrocheRuntimeSDK/Background.swift +59 -0
- package/ios/vendor/CrocheRuntimeSDK/Control.swift +192 -0
- package/ios/vendor/CrocheRuntimeSDK/Effects.swift +194 -0
- package/ios/vendor/CrocheRuntimeSDK/FFIStreamPort.swift +212 -0
- package/ios/vendor/CrocheRuntimeSDK/Host.swift +561 -0
- package/ios/vendor/CrocheRuntimeSDK/Images.swift +178 -0
- package/ios/vendor/CrocheRuntimeSDK/JSON.swift +63 -0
- package/ios/vendor/CrocheRuntimeSDK/Platform.swift +275 -0
- package/ios/vendor/CrocheRuntimeSDK/Runtime.swift +511 -0
- package/ios/vendor/CrocheRuntimeSDK/Storage.swift +345 -0
- package/ios/vendor/CrocheRuntimeSDK/StreamHub.swift +359 -0
- package/ios/vendor/CrocheRuntimeSDK/SubscriptionRuntime.swift +38 -0
- package/ios/vendor/CrocheRuntimeSDK/SubscriptionTypes.swift +323 -0
- package/ios/vendor/CrocheRuntimeSDK/croche_ffi.swift +5666 -0
- package/ios/vendor/croche_ffiFFI.xcframework/Info.plist +48 -0
- package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64/Headers/croche_ffiFFI.h +2006 -0
- package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64/Headers/module.modulemap +4 -0
- 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 +2006 -0
- package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64_x86_64-simulator/Headers/module.modulemap +4 -0
- package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64_x86_64-simulator/libcroche_ffi.a +0 -0
- package/package.json +40 -4
- package/scripts/vendor-native.sh +56 -0
- package/src/NativeCrocheRuntime.ts +162 -0
- package/src/index.ts +660 -0
- package/src/project-types.ts +35 -0
- package/src/project.ts +426 -0
- package/src/protocol.ts +28 -0
- package/src/types.ts +9 -0
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
public enum ImageResolution: String, Sendable, Codable { case standard, high }
|
|
4
|
+
public enum ImageMime: String, Sendable, Codable { case png, jpeg, webp, gif }
|
|
5
|
+
public struct InputImage: Sendable, Equatable {
|
|
6
|
+
let value: JSON
|
|
7
|
+
public init(data: Data, mime: ImageMime, alt: String? = nil, resolution: ImageResolution? = nil) {
|
|
8
|
+
var fields: [String: JSON] = ["data": .string(data.base64EncodedString()), "mime": .string("image/" + mime.rawValue)]
|
|
9
|
+
if let alt { fields["alt"] = .string(alt) }
|
|
10
|
+
if let resolution { fields["resolution"] = .string(resolution.rawValue) }
|
|
11
|
+
value = .object(fields)
|
|
12
|
+
}
|
|
13
|
+
public init(url: URL, alt: String? = nil) {
|
|
14
|
+
var fields: [String: JSON] = ["url": .string(url.absoluteString)]
|
|
15
|
+
if let alt { fields["alt"] = .string(alt) }
|
|
16
|
+
value = .object(fields)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
public struct StackedInput: Sendable, Equatable {
|
|
20
|
+
public let kind: InputKind
|
|
21
|
+
public let text: String?
|
|
22
|
+
public let images: [InputImage]
|
|
23
|
+
public init(kind: InputKind = .user, text: String? = nil, images: [InputImage] = []) {
|
|
24
|
+
self.kind = kind; self.text = text; self.images = images
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
public struct SendInput: Sendable, Equatable {
|
|
28
|
+
public let id: String
|
|
29
|
+
public let text: String
|
|
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)
|
|
36
|
+
}
|
|
37
|
+
public init(id: String, inputs: [StackedInput], context: JSON? = nil) {
|
|
38
|
+
self.init(id: id, text: "", kind: .user, images: [], inputs: inputs, context: context)
|
|
39
|
+
}
|
|
40
|
+
// Internal malformed-input construction for contract tests and fixture JSON;
|
|
41
|
+
// the public initializers select one form.
|
|
42
|
+
init(id: String, text: String, kind: InputKind, images: [InputImage], inputs: [StackedInput], context: JSON?) {
|
|
43
|
+
self.id = id; self.text = text; self.kind = kind; self.images = images; self.inputs = inputs; self.context = context
|
|
44
|
+
}
|
|
45
|
+
func wireJSON() throws -> JSON {
|
|
46
|
+
let encoder = JSONEncoder()
|
|
47
|
+
func kindJSON(_ kind: InputKind) throws -> JSON { try JSON(data: encoder.encode(kind)) }
|
|
48
|
+
var fields: [String: JSON] = ["id": .string(id)]
|
|
49
|
+
if let context { fields["context"] = context }
|
|
50
|
+
if !inputs.isEmpty {
|
|
51
|
+
fields["inputs"] = .array(try inputs.map { part in
|
|
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")
|
|
65
|
+
}
|
|
66
|
+
return .object(fields)
|
|
67
|
+
}
|
|
68
|
+
func coreJSON(options: SendOptions) throws -> JSON {
|
|
69
|
+
let value = try wireJSON()
|
|
70
|
+
#if CROCHE_SUBSCRIPTION_HOST
|
|
71
|
+
return value
|
|
72
|
+
#else
|
|
73
|
+
return Images.prepareInput(value, fallback: options.imageResolution)
|
|
74
|
+
#endif
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
public struct SendOptions: Sendable, Equatable {
|
|
78
|
+
public let responseFormat: JSON?
|
|
79
|
+
public let imageResolution: ImageResolution?
|
|
80
|
+
public init(responseFormat: JSON? = nil, imageResolution: ImageResolution? = nil) {
|
|
81
|
+
self.responseFormat = responseFormat; self.imageResolution = imageResolution
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
public enum RequestWait: Sendable { case idle }
|
|
85
|
+
public struct Receipt: Sendable, Equatable { public let id: String; public let status: InputStatus; public let seq: Int? }
|
|
86
|
+
public struct RequestResult: Sendable, Equatable {
|
|
87
|
+
public let id: String
|
|
88
|
+
public let status: InputStatus
|
|
89
|
+
public let messages: [MessageEnd]
|
|
90
|
+
public let gap: Bool
|
|
91
|
+
public let legacy: Bool
|
|
92
|
+
// RequestResult.pending comes with the coordinated TS/Swift/Kotlin consuming-unit change.
|
|
93
|
+
}
|
|
94
|
+
public struct Cursor: Sendable, Codable, Hashable {
|
|
95
|
+
public let logId: String
|
|
96
|
+
public let seq: Int
|
|
97
|
+
public init(logId: String, seq: Int) { self.logId = logId; self.seq = seq }
|
|
98
|
+
}
|
|
99
|
+
public struct StreamError: Sendable, Codable, Equatable { public let code: String; public let message: String; public let poisoned: Bool }
|
|
100
|
+
public struct RuntimeError: Sendable, Codable, Hashable { public let code: String; public let message: String }
|
|
101
|
+
public struct ToolSource: Sendable, Codable, Equatable { public let command: String; public let callId: String }
|
|
102
|
+
public struct ImageSummary: Sendable, Codable, Equatable { public let alt: String?; public let mime: String?; public let bytes: Int? }
|
|
103
|
+
public struct InputEvent: Sendable, Codable, Equatable {
|
|
104
|
+
public let seq: Int; public let firstSeq: Int; public let id: String; public let kind: InputKind
|
|
105
|
+
public let text: String?; public let images: [ImageSummary]; public let status: InputStatus
|
|
106
|
+
public let error: RuntimeError?; public let at: Date
|
|
107
|
+
}
|
|
108
|
+
public struct MessageStart: Sendable, Codable, Equatable { public let seq: Int; public let firstSeq: Int; public let id: String; public let at: Date }
|
|
109
|
+
public struct MessageDelta: Sendable, Codable, Equatable { public let id: String; public let text: String }
|
|
110
|
+
public struct MessageEnd: Sendable, Codable, Equatable {
|
|
111
|
+
public let seq: Int; public let firstSeq: Int; public let id: String
|
|
112
|
+
public let status: MessageStatus; public let text: String; public let markers: [String]; public let output: JSON?
|
|
113
|
+
public let inReplyTo: [String]; public let causedBy: [String]; public let error: RuntimeError?; public let at: Date
|
|
114
|
+
}
|
|
115
|
+
public struct Cleared: Sendable, Codable, Equatable { public let seq: Int; public let id: String; public let at: Date }
|
|
116
|
+
public struct Page: Sendable, Equatable { public let messages: [RuntimeEvent]; public let reachedFloor: Bool; public let logId: String; public let clearedSeq: Int }
|
|
117
|
+
public struct AppStreamEvent: Sendable, Codable, Equatable { public let seq: Int; public let id: String; public let name: String; public let data: JSON; public let source: ToolSource; public let at: Date }
|
|
118
|
+
public struct TurnEvent: Sendable, Codable, Equatable {
|
|
119
|
+
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: CostStatus; public let model: String; public let imagesOmitted: Int?; public let at: Date
|
|
121
|
+
}
|
|
122
|
+
public struct StateEvent: Sendable, Codable, Equatable {
|
|
123
|
+
public let status: AgentStatus; public let queued: Int; public let typing: Bool
|
|
124
|
+
/// What a running agent waits on: set exactly while `status` is `.running`, nil otherwise.
|
|
125
|
+
public let activity: AgentActivity?
|
|
126
|
+
/// With `.tool` only: the command keys the round runs, in call order. Never arguments.
|
|
127
|
+
public let tools: [String]?
|
|
128
|
+
public init(status: AgentStatus, queued: Int, typing: Bool, activity: AgentActivity? = nil, tools: [String]? = nil) {
|
|
129
|
+
self.status = status; self.queued = queued; self.typing = typing; self.activity = activity; self.tools = tools
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
public struct ErrorEvent: 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 }
|
|
133
|
+
public struct Gap: Sendable, Codable, Equatable { public let afterSeq: Int; public let throughSeq: Int; public let reason: GapReason }
|
|
134
|
+
public struct Snapshot: Sendable, Codable, Equatable { public let logId: String; public let state: StateEvent; public let streaming: Streaming? }
|
|
135
|
+
public struct Streaming: Sendable, Codable, Equatable { public let messageId: String; public let firstSeq: Int; public let text: String }
|
|
136
|
+
public enum RuntimeEvent: Sendable, Equatable {
|
|
137
|
+
case input(InputEvent), messageStart(MessageStart), messageDelta(MessageDelta), messageEnd(MessageEnd)
|
|
138
|
+
case cleared(Cleared), page(Page), app(AppStreamEvent), turn(TurnEvent), state(StateEvent), error(ErrorEvent)
|
|
139
|
+
case gap(Gap), snapshot(Snapshot), streamError(StreamError), replaced, unknown(type: String)
|
|
140
|
+
public var seq: Int? {
|
|
141
|
+
switch self {
|
|
142
|
+
case .input(let v): v.seq
|
|
143
|
+
case .messageStart(let v): v.seq
|
|
144
|
+
case .messageEnd(let v): v.seq
|
|
145
|
+
case .cleared(let v): v.seq
|
|
146
|
+
case .app(let v): v.seq
|
|
147
|
+
case .turn(let v): v.seq
|
|
148
|
+
case .error(let v): v.seq
|
|
149
|
+
default: nil
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
public enum InputKind: Sendable, Codable, Hashable {
|
|
155
|
+
case user, event, unknown(String)
|
|
156
|
+
public init(from decoder: Decoder) throws {
|
|
157
|
+
let value = try decoder.singleValueContainer().decode(String.self)
|
|
158
|
+
switch value {
|
|
159
|
+
case "user": self = .user
|
|
160
|
+
case "event": self = .event
|
|
161
|
+
default: self = .unknown(value)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
public func encode(to encoder: Encoder) throws {
|
|
165
|
+
var container = encoder.singleValueContainer()
|
|
166
|
+
switch self {
|
|
167
|
+
case .user: try container.encode("user")
|
|
168
|
+
case .event: try container.encode("event")
|
|
169
|
+
case .unknown(let value): try container.encode(value)
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
public enum InputStatus: Sendable, Codable, Hashable {
|
|
175
|
+
case queued, seen, answered, noReply, failed, cancelled, settledBeforeUpgrade, unknown(String)
|
|
176
|
+
public init(from decoder: Decoder) throws {
|
|
177
|
+
let value = try decoder.singleValueContainer().decode(String.self)
|
|
178
|
+
switch value {
|
|
179
|
+
case "queued": self = .queued
|
|
180
|
+
case "seen": self = .seen
|
|
181
|
+
case "answered": self = .answered
|
|
182
|
+
case "no_reply": self = .noReply
|
|
183
|
+
case "failed": self = .failed
|
|
184
|
+
case "cancelled": self = .cancelled
|
|
185
|
+
case "settled_before_upgrade": self = .settledBeforeUpgrade
|
|
186
|
+
default: self = .unknown(value)
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
public func encode(to encoder: Encoder) throws {
|
|
190
|
+
var container = encoder.singleValueContainer()
|
|
191
|
+
switch self {
|
|
192
|
+
case .queued: try container.encode("queued")
|
|
193
|
+
case .seen: try container.encode("seen")
|
|
194
|
+
case .answered: try container.encode("answered")
|
|
195
|
+
case .noReply: try container.encode("no_reply")
|
|
196
|
+
case .failed: try container.encode("failed")
|
|
197
|
+
case .cancelled: try container.encode("cancelled")
|
|
198
|
+
case .settledBeforeUpgrade: try container.encode("settled_before_upgrade")
|
|
199
|
+
case .unknown(let value): try container.encode(value)
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
public enum MessageStatus: Sendable, Codable, Hashable {
|
|
205
|
+
case completed, failed, cancelled, interrupted, unknown(String)
|
|
206
|
+
public init(from decoder: Decoder) throws {
|
|
207
|
+
let value = try decoder.singleValueContainer().decode(String.self)
|
|
208
|
+
switch value {
|
|
209
|
+
case "completed": self = .completed
|
|
210
|
+
case "failed": self = .failed
|
|
211
|
+
case "cancelled": self = .cancelled
|
|
212
|
+
case "interrupted": self = .interrupted
|
|
213
|
+
default: self = .unknown(value)
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
public func encode(to encoder: Encoder) throws {
|
|
217
|
+
var container = encoder.singleValueContainer()
|
|
218
|
+
switch self {
|
|
219
|
+
case .completed: try container.encode("completed")
|
|
220
|
+
case .failed: try container.encode("failed")
|
|
221
|
+
case .cancelled: try container.encode("cancelled")
|
|
222
|
+
case .interrupted: try container.encode("interrupted")
|
|
223
|
+
case .unknown(let value): try container.encode(value)
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/// The stream `state`'s `activity`: a model call, a summary call (held before the reply), or a
|
|
229
|
+
/// tool round. A value this SDK does not know yet decodes as `.unknown`, never a stream error.
|
|
230
|
+
public enum AgentActivity: Sendable, Codable, Hashable {
|
|
231
|
+
case model, summary, tool, unknown(String)
|
|
232
|
+
public init(from decoder: Decoder) throws {
|
|
233
|
+
let value = try decoder.singleValueContainer().decode(String.self)
|
|
234
|
+
switch value {
|
|
235
|
+
case "model": self = .model
|
|
236
|
+
case "summary": self = .summary
|
|
237
|
+
case "tool": self = .tool
|
|
238
|
+
default: self = .unknown(value)
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
public func encode(to encoder: Encoder) throws {
|
|
242
|
+
var container = encoder.singleValueContainer()
|
|
243
|
+
switch self {
|
|
244
|
+
case .model: try container.encode("model")
|
|
245
|
+
case .summary: try container.encode("summary")
|
|
246
|
+
case .tool: try container.encode("tool")
|
|
247
|
+
case .unknown(let value): try container.encode(value)
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
public enum AgentStatus: Sendable, Codable, Hashable {
|
|
252
|
+
case running, waiting, idle, unknown(String)
|
|
253
|
+
public init(from decoder: Decoder) throws {
|
|
254
|
+
let value = try decoder.singleValueContainer().decode(String.self)
|
|
255
|
+
switch value {
|
|
256
|
+
case "running": self = .running
|
|
257
|
+
case "waiting": self = .waiting
|
|
258
|
+
case "idle": self = .idle
|
|
259
|
+
default: self = .unknown(value)
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
public func encode(to encoder: Encoder) throws {
|
|
263
|
+
var container = encoder.singleValueContainer()
|
|
264
|
+
switch self {
|
|
265
|
+
case .running: try container.encode("running")
|
|
266
|
+
case .waiting: try container.encode("waiting")
|
|
267
|
+
case .idle: try container.encode("idle")
|
|
268
|
+
case .unknown(let value): try container.encode(value)
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
public enum CostStatus: Sendable, Codable, Hashable {
|
|
274
|
+
case reported, estimated, none, unknown(String)
|
|
275
|
+
public init(from decoder: Decoder) throws {
|
|
276
|
+
let value = try decoder.singleValueContainer().decode(String.self)
|
|
277
|
+
switch value {
|
|
278
|
+
case "reported": self = .reported
|
|
279
|
+
case "estimated": self = .estimated
|
|
280
|
+
case "none": self = .none
|
|
281
|
+
default: self = .unknown(value)
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
public func encode(to encoder: Encoder) throws {
|
|
285
|
+
var container = encoder.singleValueContainer()
|
|
286
|
+
switch self {
|
|
287
|
+
case .reported: try container.encode("reported")
|
|
288
|
+
case .estimated: try container.encode("estimated")
|
|
289
|
+
case .none: try container.encode("none")
|
|
290
|
+
case .unknown(let value): try container.encode(value)
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
public enum GapReason: Sendable, Codable, Hashable {
|
|
296
|
+
case cleared, limit, unknown(String)
|
|
297
|
+
public init(from decoder: Decoder) throws {
|
|
298
|
+
let value = try decoder.singleValueContainer().decode(String.self)
|
|
299
|
+
switch value {
|
|
300
|
+
case "cleared": self = .cleared
|
|
301
|
+
case "limit": self = .limit
|
|
302
|
+
default: self = .unknown(value)
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
public func encode(to encoder: Encoder) throws {
|
|
306
|
+
var container = encoder.singleValueContainer()
|
|
307
|
+
switch self {
|
|
308
|
+
case .cleared: try container.encode("cleared")
|
|
309
|
+
case .limit: try container.encode("limit")
|
|
310
|
+
case .unknown(let value): try container.encode(value)
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
extension InputStatus {
|
|
316
|
+
var terminal: Bool {
|
|
317
|
+
switch self { case .answered, .noReply, .failed, .cancelled, .settledBeforeUpgrade: true; default: false }
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
func clampedMaintenanceInterval(_ seconds: TimeInterval) throws -> TimeInterval {
|
|
321
|
+
guard seconds.isFinite else { throw CrocheError("invalid_configuration", "maintenanceInterval must be finite") }
|
|
322
|
+
return max(1, seconds)
|
|
323
|
+
}
|