@h1r-ai/croche-react-native 0.5.5 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -458
- package/THIRD-PARTY-NOTICES +7 -8
- package/android/build.gradle +6 -1
- package/android/src/androidTest/java/dev/croche/reactnative/WikiFileBridgeTest.kt +125 -0
- package/android/src/main/java/dev/croche/reactnative/CoreDispatch.kt +81 -0
- package/android/src/main/java/dev/croche/reactnative/CoreWire.kt +83 -0
- package/android/src/main/java/dev/croche/reactnative/CrocheRuntimeModule.kt +45 -824
- package/android/src/main/java/dev/croche/reactnative/NativePal.kt +51 -0
- package/android/src/main/java/dev/croche/reactnative/RNHostPal.kt +9 -0
- package/android/src/test/java/dev/croche/reactnative/AgentMemoryTest.kt +42 -41
- package/android/src/test/java/dev/croche/reactnative/BackgroundDelegationTest.kt +71 -0
- package/android/src/test/java/dev/croche/reactnative/OpenForwardingFixture.kt +29 -0
- package/android/src/test/java/dev/croche/reactnative/ProjectAttestationTest.kt +19 -32
- package/android/src/test/java/dev/croche/reactnative/ProjectHandlerStagesTest.kt +32 -0
- package/android/src/test/java/dev/croche/reactnative/ProjectRecoveryTest.kt +12 -0
- package/android/src/test/java/dev/croche/reactnative/ProjectTimeZoneTest.kt +11 -15
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/AndroidEventSink.kt +27 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/AndroidPlatform.kt +6 -6
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BackgroundRegistration.kt +16 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BackgroundWakeWorker.kt +51 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapDecodedImageCodec.kt +162 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapImageInput.kt +15 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapOrientation.kt +40 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapPalCodec.kt +66 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/WorkManagerScheduler.kt +8 -8
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidAssetPal.kt +30 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidCoreFactory.kt +35 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidCoreHost.kt +121 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidMainDispatcher.kt +17 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidPublicPlatform.kt +17 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidS2Pal.kt +14 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidStoragePal.kt +73 -0
- package/android/vendor/CrocheRuntimeSDK/consumer-rules.pro +9 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/AppStreamBranch.kt +5 -2
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/BindingFacts.kt +29 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ContextConfig.kt +45 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Core.kt +16 -1
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Croche.kt +60 -105
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheAgent.kt +47 -107
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheRuntime.kt +41 -40
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheTools.kt +67 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/DecodedImageCodec.kt +20 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Effects.kt +18 -20
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/GeneratedAppStream.kt +322 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Host.kt +71 -34
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ImagePal.kt +183 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Images.kt +9 -7
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/NativeCoreStreamPort.kt +47 -19
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Platform.kt +5 -5
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectPalRouting.kt +1 -1
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectRecords.kt +9 -9
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectTypes.kt +108 -37
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/PublicResults.kt +44 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ReaderValues.kt +73 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/RunTool.kt +40 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/SendEncoding.kt +23 -21
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Storage.kt +8 -8
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/StoragePal.kt +18 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/StreamHub.kt +50 -25
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/SubscriptionTypes.kt +22 -22
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ffi/croche_ffi.kt +8285 -2159
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/AppEventSink.kt +34 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/AppStoragePal.kt +25 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/BackgroundOsRegistration.kt +35 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/BackgroundSink.kt +37 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreDefinitionCalls.kt +35 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreFactoryCalls.kt +31 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreOptionsEncoding.kt +41 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreStreamCalls.kt +35 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/ForeignCallbacks.kt +128 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/JvmCoreHost.kt +72 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/JvmStoragePal.kt +34 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/LifecycleBinding.kt +18 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/NativePlatform.kt +45 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/PalCallbacks.kt +27 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/PlainToolJson.kt +56 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/PublicCalls.kt +34 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/ScopeJson.kt +29 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/ToolCompletionEncoding.kt +29 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/AtomicKeyFiles.kt +79 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/DirectHttpPal.kt +223 -0
- package/android/vendor/jniLibs/arm64-v8a/libcroche_ffi.so +0 -0
- package/android/vendor/jniLibs/armeabi-v7a/libcroche_ffi.so +0 -0
- package/android/vendor/jniLibs/x86_64/libcroche_ffi.so +0 -0
- package/dist/package.json +1 -0
- package/dist/react-native/src/NativeCrocheRuntime.d.ts +16 -0
- package/dist/react-native/src/NativeCrocheRuntime.js +2 -0
- package/dist/react-native/src/core-native.d.ts +3 -0
- package/dist/react-native/src/core-native.js +193 -0
- package/dist/react-native/src/core-wire.d.ts +38 -0
- package/dist/react-native/src/core-wire.js +1 -0
- package/dist/react-native/src/native-module.d.ts +8 -0
- package/dist/react-native/src/native-module.js +53 -0
- package/dist/rn-shared-build.json +16 -0
- package/dist/runtime/src/agent.d.ts +43 -0
- package/dist/runtime/src/agent.js +75 -0
- package/dist/runtime/src/app-api.d.ts +284 -0
- package/dist/runtime/src/app-api.js +1 -0
- package/dist/runtime/src/cancel.d.ts +9 -0
- package/dist/runtime/src/cancel.js +24 -0
- package/dist/runtime/src/core/port.d.ts +234 -0
- package/dist/runtime/src/core/port.js +1 -0
- package/dist/runtime/src/core/wasm.d.ts +1 -0
- package/dist/runtime/src/core/wasm.js +2 -0
- package/dist/runtime/src/croche.d.ts +42 -0
- package/dist/runtime/src/croche.js +111 -0
- package/dist/runtime/src/errors.d.ts +26 -0
- package/dist/runtime/src/errors.js +49 -0
- package/dist/runtime/src/events.d.ts +5 -0
- package/dist/runtime/src/events.js +31 -0
- package/dist/runtime/src/generated/app-stream.d.ts +174 -0
- package/dist/runtime/src/generated/app-stream.js +124 -0
- package/dist/runtime/src/index.native.d.ts +21 -0
- package/dist/runtime/src/index.native.js +8 -0
- package/dist/runtime/src/json.d.ts +13 -0
- package/dist/runtime/src/json.js +120 -0
- package/dist/runtime/src/native-adapter.d.ts +3 -0
- package/dist/runtime/src/native-adapter.js +24 -0
- package/dist/runtime/src/pal/codec.d.ts +15 -0
- package/dist/runtime/src/pal/codec.js +52 -0
- package/dist/runtime/src/pal/host.d.ts +5 -0
- package/dist/runtime/src/pal/host.js +35 -0
- package/dist/runtime/src/pal/platform.d.ts +16 -0
- package/dist/runtime/src/pal/platform.js +7 -0
- package/dist/runtime/src/rn-entry.d.ts +1 -0
- package/dist/runtime/src/rn-entry.js +4 -0
- package/dist/runtime/src/run-tool.d.ts +33 -0
- package/dist/runtime/src/run-tool.js +7 -0
- package/dist/runtime/src/tools.d.ts +19 -0
- package/dist/runtime/src/tools.js +70 -0
- package/ios/CoreAgentTransport.swift +14 -0
- package/ios/CoreDeliveryTransport.swift +58 -0
- package/ios/CoreNativePal.swift +93 -0
- package/ios/CorePlatformTransport.swift +44 -0
- package/ios/CoreWireDispatch.swift +92 -0
- package/ios/CoreWireSupport.swift +111 -0
- package/ios/CrocheRuntimeBridge.swift +34 -994
- package/ios/ProjectPal.swift +46 -0
- package/ios/RNCrocheRuntime.mm +18 -201
- package/ios/vendor/CrocheRuntimeSDK/AppBuildFacts.swift +112 -0
- package/ios/vendor/CrocheRuntimeSDK/Background.swift +11 -11
- package/ios/vendor/CrocheRuntimeSDK/ContextConfig.swift +64 -0
- package/ios/vendor/CrocheRuntimeSDK/DirectHTTP.swift +258 -0
- package/ios/vendor/CrocheRuntimeSDK/Effects.swift +17 -17
- package/ios/vendor/CrocheRuntimeSDK/FFIStreamPort.swift +85 -43
- package/ios/vendor/CrocheRuntimeSDK/GeneratedAppStream.swift +443 -0
- package/ios/vendor/CrocheRuntimeSDK/Host.swift +122 -61
- package/ios/vendor/CrocheRuntimeSDK/ImagePal.swift +410 -0
- package/ios/vendor/CrocheRuntimeSDK/Images.swift +10 -9
- package/ios/vendor/CrocheRuntimeSDK/JSON.swift +4 -4
- package/ios/vendor/CrocheRuntimeSDK/Offload.swift +24 -0
- package/ios/vendor/CrocheRuntimeSDK/OpenOptions.swift +37 -36
- package/ios/vendor/CrocheRuntimeSDK/Platform.swift +35 -35
- package/ios/vendor/CrocheRuntimeSDK/PlatformBackground.swift +285 -0
- package/ios/vendor/CrocheRuntimeSDK/PlatformPal.swift +266 -0
- package/ios/vendor/CrocheRuntimeSDK/PlatformStorage.swift +195 -0
- package/ios/vendor/CrocheRuntimeSDK/Project.swift +209 -95
- package/ios/vendor/CrocheRuntimeSDK/Runtime.swift +97 -123
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Agent.swift +195 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1BindingFacts.swift +33 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Core.swift +161 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Croche.swift +234 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Events.swift +28 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Options.swift +177 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1RunTool.swift +61 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Storage.swift +95 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1TestHooks.swift +105 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Tools.swift +209 -0
- package/ios/vendor/CrocheRuntimeSDK/Storage.swift +52 -52
- package/ios/vendor/CrocheRuntimeSDK/StreamHub.swift +180 -137
- package/ios/vendor/CrocheRuntimeSDK/SubscriptionRuntime.swift +16 -10
- package/ios/vendor/CrocheRuntimeSDK/SubscriptionTypes.swift +131 -116
- package/ios/vendor/CrocheRuntimeSDK/Truncate.swift +12 -0
- package/ios/vendor/CrocheRuntimeSDK/croche_ffi.swift +7209 -2803
- package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64/Headers/croche_ffiFFI.h +1342 -218
- package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64/libcroche_ffi.a +0 -0
- package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64_x86_64-simulator/Headers/croche_ffiFFI.h +1342 -218
- package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64_x86_64-simulator/libcroche_ffi.a +0 -0
- package/package.json +18 -8
- package/scripts/README.md +11 -0
- package/scripts/build-shared.mjs +46 -0
- package/scripts/build.mjs +11 -0
- package/scripts/vendor-native.sh +5 -4
- package/src/NativeCrocheRuntime.ts +12 -159
- package/android/src/main/java/dev/croche/reactnative/AgentMemory.kt +0 -25
- package/android/src/main/java/dev/croche/reactnative/ProjectAttestation.kt +0 -17
- package/android/src/main/java/dev/croche/reactnative/ProjectTimeZone.kt +0 -14
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Control.kt +0 -178
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectBinding.kt +0 -79
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectPlatform.kt +0 -46
- package/ios/vendor/CrocheRuntimeSDK/Control.swift +0 -192
- package/src/index.ts +0 -664
- package/src/project-types.ts +0 -35
- package/src/project.ts +0 -434
- package/src/protocol.ts +0 -28
- package/src/types.ts +0 -9
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
// GENERATED by scripts/generate-app-stream.mjs from the Rust app contract. Do not edit.
|
|
2
|
+
import Foundation
|
|
3
|
+
|
|
4
|
+
public enum AppStreamContract {
|
|
5
|
+
public enum InputDisposition: Codable, Sendable, Hashable {
|
|
6
|
+
case queued
|
|
7
|
+
case seen
|
|
8
|
+
case answered
|
|
9
|
+
case noReply
|
|
10
|
+
case failed
|
|
11
|
+
case cancelled
|
|
12
|
+
case unknown(type: String, fields: JSON)
|
|
13
|
+
public var rawValue: String {
|
|
14
|
+
switch self {
|
|
15
|
+
case .queued: return "queued"
|
|
16
|
+
case .seen: return "seen"
|
|
17
|
+
case .answered: return "answered"
|
|
18
|
+
case .noReply: return "no_reply"
|
|
19
|
+
case .failed: return "failed"
|
|
20
|
+
case .cancelled: return "cancelled"
|
|
21
|
+
case .unknown(let type, _): return type
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
public init(from decoder: Decoder) throws {
|
|
25
|
+
let value = try decoder.singleValueContainer().decode(String.self)
|
|
26
|
+
switch value {
|
|
27
|
+
case "queued": self = .queued
|
|
28
|
+
case "seen": self = .seen
|
|
29
|
+
case "answered": self = .answered
|
|
30
|
+
case "no_reply": self = .noReply
|
|
31
|
+
case "failed": self = .failed
|
|
32
|
+
case "cancelled": self = .cancelled
|
|
33
|
+
default: self = .unknown(type: value, fields: .string(value))
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
public func encode(to encoder: Encoder) throws {
|
|
37
|
+
var value = encoder.singleValueContainer()
|
|
38
|
+
try value.encode(rawValue)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
public enum InputKind: Codable, Sendable, Hashable {
|
|
42
|
+
case user
|
|
43
|
+
case appEvent
|
|
44
|
+
case appState
|
|
45
|
+
case unknown(type: String, fields: JSON)
|
|
46
|
+
public var rawValue: String {
|
|
47
|
+
switch self {
|
|
48
|
+
case .user: return "user"
|
|
49
|
+
case .appEvent: return "app_event"
|
|
50
|
+
case .appState: return "app_state"
|
|
51
|
+
case .unknown(let type, _): return type
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
public init(from decoder: Decoder) throws {
|
|
55
|
+
let value = try decoder.singleValueContainer().decode(String.self)
|
|
56
|
+
switch value {
|
|
57
|
+
case "user": self = .user
|
|
58
|
+
case "app_event": self = .appEvent
|
|
59
|
+
case "app_state": self = .appState
|
|
60
|
+
default: self = .unknown(type: value, fields: .string(value))
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
public func encode(to encoder: Encoder) throws {
|
|
64
|
+
var value = encoder.singleValueContainer()
|
|
65
|
+
try value.encode(rawValue)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
public enum MessageStatus: Codable, Sendable, Hashable {
|
|
69
|
+
case completed
|
|
70
|
+
case failed
|
|
71
|
+
case cancelled
|
|
72
|
+
case interrupted
|
|
73
|
+
case unknown(type: String, fields: JSON)
|
|
74
|
+
public var rawValue: String {
|
|
75
|
+
switch self {
|
|
76
|
+
case .completed: return "completed"
|
|
77
|
+
case .failed: return "failed"
|
|
78
|
+
case .cancelled: return "cancelled"
|
|
79
|
+
case .interrupted: return "interrupted"
|
|
80
|
+
case .unknown(let type, _): return type
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
public init(from decoder: Decoder) throws {
|
|
84
|
+
let value = try decoder.singleValueContainer().decode(String.self)
|
|
85
|
+
switch value {
|
|
86
|
+
case "completed": self = .completed
|
|
87
|
+
case "failed": self = .failed
|
|
88
|
+
case "cancelled": self = .cancelled
|
|
89
|
+
case "interrupted": self = .interrupted
|
|
90
|
+
default: self = .unknown(type: value, fields: .string(value))
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
public func encode(to encoder: Encoder) throws {
|
|
94
|
+
var value = encoder.singleValueContainer()
|
|
95
|
+
try value.encode(rawValue)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
public enum AgentStatus: Codable, Sendable, Hashable {
|
|
99
|
+
case idle
|
|
100
|
+
case running
|
|
101
|
+
case waiting
|
|
102
|
+
case unknown(type: String, fields: JSON)
|
|
103
|
+
public var rawValue: String {
|
|
104
|
+
switch self {
|
|
105
|
+
case .idle: return "idle"
|
|
106
|
+
case .running: return "running"
|
|
107
|
+
case .waiting: return "waiting"
|
|
108
|
+
case .unknown(let type, _): return type
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
public init(from decoder: Decoder) throws {
|
|
112
|
+
let value = try decoder.singleValueContainer().decode(String.self)
|
|
113
|
+
switch value {
|
|
114
|
+
case "idle": self = .idle
|
|
115
|
+
case "running": self = .running
|
|
116
|
+
case "waiting": self = .waiting
|
|
117
|
+
default: self = .unknown(type: value, fields: .string(value))
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
public func encode(to encoder: Encoder) throws {
|
|
121
|
+
var value = encoder.singleValueContainer()
|
|
122
|
+
try value.encode(rawValue)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
public enum TurnPurpose: Codable, Sendable, Hashable {
|
|
126
|
+
case summary
|
|
127
|
+
case unknown(type: String, fields: JSON)
|
|
128
|
+
public var rawValue: String {
|
|
129
|
+
switch self {
|
|
130
|
+
case .summary: return "summary"
|
|
131
|
+
case .unknown(let type, _): return type
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
public init(from decoder: Decoder) throws {
|
|
135
|
+
let value = try decoder.singleValueContainer().decode(String.self)
|
|
136
|
+
switch value {
|
|
137
|
+
case "summary": self = .summary
|
|
138
|
+
default: self = .unknown(type: value, fields: .string(value))
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
public func encode(to encoder: Encoder) throws {
|
|
142
|
+
var value = encoder.singleValueContainer()
|
|
143
|
+
try value.encode(rawValue)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
public enum MemoryOp: Codable, Sendable, Hashable {
|
|
147
|
+
case delete
|
|
148
|
+
case clear
|
|
149
|
+
case enabled
|
|
150
|
+
case unknown(type: String, fields: JSON)
|
|
151
|
+
public var rawValue: String {
|
|
152
|
+
switch self {
|
|
153
|
+
case .delete: return "delete"
|
|
154
|
+
case .clear: return "clear"
|
|
155
|
+
case .enabled: return "enabled"
|
|
156
|
+
case .unknown(let type, _): return type
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
public init(from decoder: Decoder) throws {
|
|
160
|
+
let value = try decoder.singleValueContainer().decode(String.self)
|
|
161
|
+
switch value {
|
|
162
|
+
case "delete": self = .delete
|
|
163
|
+
case "clear": self = .clear
|
|
164
|
+
case "enabled": self = .enabled
|
|
165
|
+
default: self = .unknown(type: value, fields: .string(value))
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
public func encode(to encoder: Encoder) throws {
|
|
169
|
+
var value = encoder.singleValueContainer()
|
|
170
|
+
try value.encode(rawValue)
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
public struct Attachment: Codable, Sendable {
|
|
174
|
+
public let id: String
|
|
175
|
+
public let kind: String
|
|
176
|
+
public let origin: String
|
|
177
|
+
public let mediaType: String
|
|
178
|
+
public let bytes: UInt64
|
|
179
|
+
public let sha256: String
|
|
180
|
+
public let width: UInt64?
|
|
181
|
+
public let height: UInt64?
|
|
182
|
+
public let alt: String?
|
|
183
|
+
public let callId: String?
|
|
184
|
+
public let deleted: Bool?
|
|
185
|
+
public let deletedReason: String?
|
|
186
|
+
}
|
|
187
|
+
public struct EventError: Codable, Sendable {
|
|
188
|
+
public let code: String
|
|
189
|
+
public let category: ErrorCategory
|
|
190
|
+
public let message: String
|
|
191
|
+
/// Integer seconds, present only on the hourly app-paid rate_limited refusal.
|
|
192
|
+
public let retryAfter: UInt64?
|
|
193
|
+
}
|
|
194
|
+
public struct SendReceipt: Codable, Sendable {
|
|
195
|
+
public let requestId: String
|
|
196
|
+
public let status: InputDisposition
|
|
197
|
+
public let seq: UInt64
|
|
198
|
+
public let error: EventError?
|
|
199
|
+
}
|
|
200
|
+
public struct RequestResult: Codable, Sendable {
|
|
201
|
+
public let id: String
|
|
202
|
+
public let status: InputDisposition
|
|
203
|
+
public let messages: [MessageEnd]
|
|
204
|
+
public let gap: Bool?
|
|
205
|
+
public let error: EventError?
|
|
206
|
+
}
|
|
207
|
+
public struct InputEvent: Codable, Sendable {
|
|
208
|
+
public let id: String
|
|
209
|
+
public let seq: UInt64
|
|
210
|
+
public let firstSeq: UInt64
|
|
211
|
+
public let kind: InputKind
|
|
212
|
+
public let status: InputDisposition
|
|
213
|
+
public let at: String
|
|
214
|
+
public let text: String?
|
|
215
|
+
public let error: EventError?
|
|
216
|
+
}
|
|
217
|
+
public struct MessageStart: Codable, Sendable {
|
|
218
|
+
public let id: String
|
|
219
|
+
public let seq: UInt64
|
|
220
|
+
public let firstSeq: UInt64
|
|
221
|
+
public let at: String
|
|
222
|
+
}
|
|
223
|
+
public struct MessageDelta: Codable, Sendable {
|
|
224
|
+
public let id: String
|
|
225
|
+
public let text: String
|
|
226
|
+
}
|
|
227
|
+
public struct MessageEnd: Codable, Sendable {
|
|
228
|
+
public let id: String
|
|
229
|
+
public let seq: UInt64
|
|
230
|
+
public let firstSeq: UInt64
|
|
231
|
+
public let at: String
|
|
232
|
+
public let status: MessageStatus
|
|
233
|
+
public let text: String
|
|
234
|
+
public let markers: [String]
|
|
235
|
+
public let causedBy: [String]
|
|
236
|
+
public let inReplyTo: [String]
|
|
237
|
+
public let output: JSON?
|
|
238
|
+
public let error: EventError?
|
|
239
|
+
}
|
|
240
|
+
public struct TurnEvent: Codable, Sendable {
|
|
241
|
+
public let id: String
|
|
242
|
+
public let inputs: [String]
|
|
243
|
+
public let causedBy: [String]
|
|
244
|
+
public let usage: JSON
|
|
245
|
+
public let cost: Double?
|
|
246
|
+
public let costStatus: String
|
|
247
|
+
public let model: String
|
|
248
|
+
public let at: String
|
|
249
|
+
public let purpose: TurnPurpose?
|
|
250
|
+
/// Reported serving-provider label; absent when unavailable. Diagnostic only; never changes pricing or settlement.
|
|
251
|
+
public let provider: String?
|
|
252
|
+
}
|
|
253
|
+
public struct ToolEvent: Codable, Sendable {
|
|
254
|
+
public let id: String
|
|
255
|
+
public let seq: UInt64
|
|
256
|
+
public let firstSeq: UInt64
|
|
257
|
+
public let origin: String
|
|
258
|
+
public let causedBy: [String]
|
|
259
|
+
public let tool: String
|
|
260
|
+
public let key: String
|
|
261
|
+
public let args: JSON
|
|
262
|
+
public let status: String
|
|
263
|
+
public let cost: Double?
|
|
264
|
+
public let costStatus: String
|
|
265
|
+
public let startedAt: String
|
|
266
|
+
public let at: String
|
|
267
|
+
public let requestedBy: String?
|
|
268
|
+
public let delivered: JSON?
|
|
269
|
+
public let outputs: JSON?
|
|
270
|
+
}
|
|
271
|
+
public struct StateEvent: Codable, Sendable {
|
|
272
|
+
public let status: AgentStatus
|
|
273
|
+
public let queued: UInt64
|
|
274
|
+
public let typing: Bool
|
|
275
|
+
public let activity: String?
|
|
276
|
+
public let tools: [String]?
|
|
277
|
+
}
|
|
278
|
+
public struct SnapshotEvent: Codable, Sendable {
|
|
279
|
+
public let logId: String
|
|
280
|
+
public let state: JSON
|
|
281
|
+
public let streaming: JSON
|
|
282
|
+
}
|
|
283
|
+
public struct PageEvent: Codable, Sendable {
|
|
284
|
+
public let messages: [AgentEvent]
|
|
285
|
+
public let reachedFloor: Bool
|
|
286
|
+
public let logId: String
|
|
287
|
+
public let clearedSeq: UInt64
|
|
288
|
+
}
|
|
289
|
+
public struct ClearedEvent: Codable, Sendable {
|
|
290
|
+
public let id: String
|
|
291
|
+
public let at: String
|
|
292
|
+
}
|
|
293
|
+
public struct MemoryEvent: Codable, Sendable {
|
|
294
|
+
public let id: String
|
|
295
|
+
public let op: MemoryOp
|
|
296
|
+
public let at: String
|
|
297
|
+
public let item: String?
|
|
298
|
+
public let enabled: Bool?
|
|
299
|
+
public let removed: UInt64?
|
|
300
|
+
}
|
|
301
|
+
public struct GapEvent: Codable, Sendable {
|
|
302
|
+
public let afterSeq: UInt64
|
|
303
|
+
public let throughSeq: UInt64
|
|
304
|
+
public let reason: String
|
|
305
|
+
}
|
|
306
|
+
public struct SubscriptionError: Codable, Sendable {
|
|
307
|
+
public let code: String
|
|
308
|
+
public let message: String
|
|
309
|
+
public let poisoned: Bool?
|
|
310
|
+
}
|
|
311
|
+
public struct ReplacedEvent: Codable, Sendable {
|
|
312
|
+
|
|
313
|
+
}
|
|
314
|
+
public indirect enum AgentEvent: Codable, Sendable {
|
|
315
|
+
case input(InputEvent)
|
|
316
|
+
case messageStart(MessageStart)
|
|
317
|
+
case messageDelta(MessageDelta)
|
|
318
|
+
case messageEnd(MessageEnd)
|
|
319
|
+
case turn(TurnEvent)
|
|
320
|
+
case tool(ToolEvent)
|
|
321
|
+
case state(StateEvent)
|
|
322
|
+
case snapshot(SnapshotEvent)
|
|
323
|
+
case page(PageEvent)
|
|
324
|
+
case cleared(ClearedEvent)
|
|
325
|
+
case memory(MemoryEvent)
|
|
326
|
+
case gap(GapEvent)
|
|
327
|
+
case error(SubscriptionError)
|
|
328
|
+
case replaced(ReplacedEvent)
|
|
329
|
+
case unknown(type: String, fields: [String: JSON])
|
|
330
|
+
private enum Tag: String, CodingKey { case type }
|
|
331
|
+
private struct FieldKey: CodingKey {
|
|
332
|
+
let stringValue: String
|
|
333
|
+
var intValue: Int? { nil }
|
|
334
|
+
init(stringValue: String) { self.stringValue = stringValue }
|
|
335
|
+
init?(intValue: Int) { nil }
|
|
336
|
+
}
|
|
337
|
+
public init(from decoder: Decoder) throws {
|
|
338
|
+
let tag = try decoder.container(keyedBy: Tag.self).decode(String.self, forKey: .type)
|
|
339
|
+
switch tag {
|
|
340
|
+
case "input": self = .input(try InputEvent(from: decoder))
|
|
341
|
+
case "message.start": self = .messageStart(try MessageStart(from: decoder))
|
|
342
|
+
case "message.delta": self = .messageDelta(try MessageDelta(from: decoder))
|
|
343
|
+
case "message.end": self = .messageEnd(try MessageEnd(from: decoder))
|
|
344
|
+
case "turn": self = .turn(try TurnEvent(from: decoder))
|
|
345
|
+
case "tool": self = .tool(try ToolEvent(from: decoder))
|
|
346
|
+
case "state": self = .state(try StateEvent(from: decoder))
|
|
347
|
+
case "snapshot": self = .snapshot(try SnapshotEvent(from: decoder))
|
|
348
|
+
case "page": self = .page(try PageEvent(from: decoder))
|
|
349
|
+
case "cleared": self = .cleared(try ClearedEvent(from: decoder))
|
|
350
|
+
case "memory": self = .memory(try MemoryEvent(from: decoder))
|
|
351
|
+
case "gap": self = .gap(try GapEvent(from: decoder))
|
|
352
|
+
case "error": self = .error(try SubscriptionError(from: decoder))
|
|
353
|
+
case "replaced": self = .replaced(try ReplacedEvent(from: decoder))
|
|
354
|
+
default:
|
|
355
|
+
let value = try JSON(from: decoder)
|
|
356
|
+
self = .unknown(type: tag, fields: value.object ?? [:])
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
public func encode(to encoder: Encoder) throws {
|
|
360
|
+
var container = encoder.container(keyedBy: Tag.self)
|
|
361
|
+
switch self {
|
|
362
|
+
case .input(let value):
|
|
363
|
+
try value.encode(to: encoder)
|
|
364
|
+
try container.encode("input", forKey: .type)
|
|
365
|
+
case .messageStart(let value):
|
|
366
|
+
try value.encode(to: encoder)
|
|
367
|
+
try container.encode("message.start", forKey: .type)
|
|
368
|
+
case .messageDelta(let value):
|
|
369
|
+
try value.encode(to: encoder)
|
|
370
|
+
try container.encode("message.delta", forKey: .type)
|
|
371
|
+
case .messageEnd(let value):
|
|
372
|
+
try value.encode(to: encoder)
|
|
373
|
+
try container.encode("message.end", forKey: .type)
|
|
374
|
+
case .turn(let value):
|
|
375
|
+
try value.encode(to: encoder)
|
|
376
|
+
try container.encode("turn", forKey: .type)
|
|
377
|
+
case .tool(let value):
|
|
378
|
+
try value.encode(to: encoder)
|
|
379
|
+
try container.encode("tool", forKey: .type)
|
|
380
|
+
case .state(let value):
|
|
381
|
+
try value.encode(to: encoder)
|
|
382
|
+
try container.encode("state", forKey: .type)
|
|
383
|
+
case .snapshot(let value):
|
|
384
|
+
try value.encode(to: encoder)
|
|
385
|
+
try container.encode("snapshot", forKey: .type)
|
|
386
|
+
case .page(let value):
|
|
387
|
+
try value.encode(to: encoder)
|
|
388
|
+
try container.encode("page", forKey: .type)
|
|
389
|
+
case .cleared(let value):
|
|
390
|
+
try value.encode(to: encoder)
|
|
391
|
+
try container.encode("cleared", forKey: .type)
|
|
392
|
+
case .memory(let value):
|
|
393
|
+
try value.encode(to: encoder)
|
|
394
|
+
try container.encode("memory", forKey: .type)
|
|
395
|
+
case .gap(let value):
|
|
396
|
+
try value.encode(to: encoder)
|
|
397
|
+
try container.encode("gap", forKey: .type)
|
|
398
|
+
case .error(let value):
|
|
399
|
+
try value.encode(to: encoder)
|
|
400
|
+
try container.encode("error", forKey: .type)
|
|
401
|
+
case .replaced(let value):
|
|
402
|
+
try value.encode(to: encoder)
|
|
403
|
+
try container.encode("replaced", forKey: .type)
|
|
404
|
+
case .unknown(let type, let fields):
|
|
405
|
+
// Keyed, like the known cases: a single-value write after the keyed container
|
|
406
|
+
// drops the fields on Linux Foundation (Keel #861 08:40Z).
|
|
407
|
+
var any = encoder.container(keyedBy: FieldKey.self)
|
|
408
|
+
for (key, value) in fields where key != "type" { try any.encode(value, forKey: FieldKey(stringValue: key)) }
|
|
409
|
+
try container.encode(type, forKey: .type)
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
public enum ErrorCategory: String, Codable, Sendable {
|
|
414
|
+
case offline
|
|
415
|
+
case allowance
|
|
416
|
+
case paused
|
|
417
|
+
case setup
|
|
418
|
+
case closed
|
|
419
|
+
case invalid
|
|
420
|
+
case `internal`
|
|
421
|
+
}
|
|
422
|
+
static func errorCategory(_ code: String) -> ErrorCategory {
|
|
423
|
+
if code.range(of: "^http_[1-5][0-9]{2}$", options: .regularExpression) != nil { return .offline }
|
|
424
|
+
switch code {
|
|
425
|
+
case "offline", "network_error", "request_timeout", "gateway_unavailable", "invalid_cloud_response", "stale_control", "http_<status>": return .offline
|
|
426
|
+
case "account_credit_exhausted", "project_budget_exhausted", "user_allowance_exhausted", "development_allowance_exhausted", "unverified_allowance_exhausted", "gateway_key_exhausted", "provider_credit_unavailable": return .allowance
|
|
427
|
+
case "usage_paused", "runtime_blocked", "project_access_disabled", "account_disabled", "server_key_revoked", "debug_token_revoked", "rate_limited", "provider_rate_limited": return .paused
|
|
428
|
+
case "allowance_grants_disabled", "invalid_configuration", "model_missing", "model_withdrawn", "model_unavailable", "project_key_unknown", "server_key_invalid", "debug_token_invalid", "user_required", "gateway_key_rejected", "gateway_unsupported", "schema_unsupported", "capability_unsupported", "invalid_snapshot", "snapshot_mismatch", "invalid_tool", "invalid_wiki", "installation_unverified", "attestation_required", "attestation_rejected", "attestation_unverifiable", "attestation_failed", "attestation_unavailable", "attestation_unsupported", "attestation_timeout", "recovery_required", "host_unavailable", "core_unavailable": return .setup
|
|
429
|
+
case "outcome_unknown", "closed", "target_closed", "runtime_detached", "cancelled", "interrupted", "preempted", "aborted", "observation_lost", "store_busy", "instance_busy": return .closed
|
|
430
|
+
case "invalid_input", "input_too_large", "invalid_memory", "invalid_response_format", "invalid_request", "tool_unauthorized", "agent_conflict", "unknown_id", "idempotency_conflict", "identity_conflict", "busy", "queue_full", "cursor_reset", "context_limit", "output_limit", "iteration_limit", "structured_output_unsupported": return .invalid
|
|
431
|
+
case "failure_unrecorded", "internal", "asset_read_failed", "stream_incomplete", "provider_error", "provider_rejected", "invalid_provider_response", "invalid_response", "output_too_large", "output_invalid", "empty_response", "unexpected_tool_call", "storage_error", "store_refused", "store_full", "corrupt_store", "store_too_new", "fresh_reservation_lost", "archive_unavailable", "archive_error", "host_error", "host_unresponsive", "thread_unavailable", "core_error", "invalid_abi", "no_lock", "handler_failed", "subscriber_overflow": return .internal
|
|
432
|
+
default: return .internal
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
static func representationErrorCategory(_ code: String) -> ErrorCategory {
|
|
436
|
+
switch code {
|
|
437
|
+
case "invalid_configuration": return .setup
|
|
438
|
+
case "invalid_input": return .invalid
|
|
439
|
+
case "invalid_tool_result": return .invalid
|
|
440
|
+
default: return errorCategory(code)
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|