@h1r-ai/croche-react-native 0.6.0 → 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 +32 -4
- package/THIRD-PARTY-NOTICES +899 -6
- package/android/src/androidTest/java/dev/croche/reactnative/WikiFileBridgeTest.kt +4 -3
- package/android/src/main/AndroidManifest.xml +0 -5
- package/android/src/main/java/dev/croche/reactnative/CoreDispatch.kt +33 -8
- package/android/src/main/java/dev/croche/reactnative/CoreWire.kt +139 -5
- package/android/src/main/java/dev/croche/reactnative/CrocheRuntimeModule.kt +5 -2
- package/android/src/main/java/dev/croche/reactnative/NativePal.kt +23 -6
- package/android/src/test/java/dev/croche/reactnative/AgentMemoryTest.kt +28 -6
- package/android/src/test/java/dev/croche/reactnative/BackgroundDelegationTest.kt +4 -11
- 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 +19 -4
- package/android/src/test/java/dev/croche/reactnative/ProjectAttestationTest.kt +2 -2
- 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/AndroidPlatform.kt +5 -3
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BackgroundWakeWorker.kt +4 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapDecodedImageCodec.kt +11 -11
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/BitmapImageCodec.kt +1 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidCoreHost.kt +11 -16
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidPublicPlatform.kt +3 -3
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidStateStore.kt +216 -0
- package/android/vendor/CrocheRuntimeSDK/android/dev/croche/android/pal/AndroidStoragePal.kt +45 -10
- package/android/vendor/CrocheRuntimeSDK/consumer-rules.pro +0 -3
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Adapters.kt +75 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/BindingFacts.kt +1 -1
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ContextConfig.kt +9 -23
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Core.kt +11 -2
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Croche.kt +83 -20
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheAgent.kt +54 -8
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheRuntime.kt +19 -360
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/CrocheTools.kt +79 -10
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Decision.kt +170 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/DecodedImageCodec.kt +8 -5
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Effects.kt +8 -1
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/EncodedImageCodec.kt +51 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/GeneratedAppStream.kt +426 -33
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Host.kt +1 -351
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/Images.kt +15 -29
- 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 +196 -10
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/PublicResults.kt +86 -3
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/RunTool.kt +33 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/SendEncoding.kt +1 -1
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/StateStore.kt +90 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/SubscriptionTypes.kt +68 -4
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ffi/croche_ffi.kt +3403 -6894
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/AppStoragePal.kt +89 -18
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreFactoryCalls.kt +1 -2
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreOptionsEncoding.kt +2 -2
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/CoreStreamCalls.kt +3 -3
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/ForeignCallbacks.kt +17 -18
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/ImageAdapterHost.kt +28 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/JvmCoreHost.kt +12 -14
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/JvmStateStore.kt +125 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/JvmStoragePal.kt +36 -6
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/NativeCoreInitialization.kt +21 -0
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/NativePlatform.kt +21 -6
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/PublicCalls.kt +16 -7
- 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/pal/AtomicKeyFiles.kt +25 -4
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/s7/pal/BlobFiles.kt +157 -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/react-native/src/core-native.d.ts +3 -0
- package/dist/react-native/src/core-native.js +148 -25
- package/dist/react-native/src/core-wire.d.ts +20 -3
- package/dist/rn-shared-build.json +8 -8
- package/dist/runtime/src/adapters.d.ts +8 -0
- package/dist/runtime/src/adapters.js +29 -0
- package/dist/runtime/src/agent.d.ts +53 -5
- package/dist/runtime/src/agent.js +69 -7
- package/dist/runtime/src/app-api.d.ts +307 -19
- package/dist/runtime/src/cancel.d.ts +2 -2
- package/dist/runtime/src/cancel.js +7 -4
- 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 +48 -35
- 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/croche.d.ts +64 -9
- package/dist/runtime/src/croche.js +78 -17
- package/dist/runtime/src/errors.d.ts +7 -0
- package/dist/runtime/src/errors.js +15 -1
- package/dist/runtime/src/generated/app-stream.d.ts +155 -1
- package/dist/runtime/src/generated/app-stream.js +7 -4
- 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 -21
- package/dist/runtime/src/index.native.js +2 -8
- package/dist/runtime/src/native-adapter.d.ts +1 -1
- package/dist/runtime/src/native-adapter.js +10 -4
- package/dist/runtime/src/pal/host.d.ts +3 -3
- package/dist/runtime/src/pal/host.js +34 -9
- package/dist/runtime/src/pal/platform.d.ts +11 -6
- 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/tools.d.ts +20 -4
- package/dist/runtime/src/tools.js +31 -7
- package/ios/CoreAgentTransport.swift +2 -2
- package/ios/CoreNativePal.swift +26 -21
- package/ios/CorePlatformTransport.swift +4 -4
- package/ios/CoreWireDispatch.swift +38 -8
- package/ios/CoreWireSupport.swift +179 -4
- package/ios/CrocheRuntimeBridge.swift +1 -1
- package/ios/ProjectPal.swift +15 -12
- package/ios/vendor/CrocheRuntimeSDK/BlobFiles.swift +124 -0
- package/ios/vendor/CrocheRuntimeSDK/ContextConfig.swift +2 -6
- package/ios/vendor/CrocheRuntimeSDK/EncodedImages.swift +85 -0
- package/ios/vendor/CrocheRuntimeSDK/FFIStreamPort.swift +1 -174
- package/ios/vendor/CrocheRuntimeSDK/GeneratedAppStream.swift +233 -4
- package/ios/vendor/CrocheRuntimeSDK/Host.swift +1 -399
- package/ios/vendor/CrocheRuntimeSDK/ImagePal.swift +3 -3
- package/ios/vendor/CrocheRuntimeSDK/InstancePayloadPurge.swift +88 -0
- package/ios/vendor/CrocheRuntimeSDK/JSON.swift +26 -10
- package/ios/vendor/CrocheRuntimeSDK/OpenOptions.swift +0 -155
- package/ios/vendor/CrocheRuntimeSDK/Platform.swift +1 -27
- package/ios/vendor/CrocheRuntimeSDK/PlatformBackground.swift +8 -4
- package/ios/vendor/CrocheRuntimeSDK/PlatformPal.swift +57 -21
- package/ios/vendor/CrocheRuntimeSDK/PlatformStateStore.swift +253 -0
- package/ios/vendor/CrocheRuntimeSDK/PlatformStorage.swift +96 -10
- package/ios/vendor/CrocheRuntimeSDK/Project.swift +3 -382
- package/ios/vendor/CrocheRuntimeSDK/Runtime.swift +1 -412
- package/ios/vendor/CrocheRuntimeSDK/RuntimeHTTPAdapter.swift +42 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Adapters.swift +110 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Agent.swift +86 -33
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Allowance.swift +20 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1BindingFacts.swift +1 -1
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Core.swift +12 -3
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Croche.swift +135 -56
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Decision.swift +146 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Events.swift +17 -8
- package/ios/vendor/CrocheRuntimeSDK/S1/S1HandleOwner.swift +58 -0
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Options.swift +184 -15
- package/ios/vendor/CrocheRuntimeSDK/S1/S1RunTool.swift +31 -3
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Storage.swift +131 -61
- package/ios/vendor/CrocheRuntimeSDK/S1/S1TestHooks.swift +10 -15
- package/ios/vendor/CrocheRuntimeSDK/S1/S1Tools.swift +86 -17
- 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 +3 -249
- package/ios/vendor/CrocheRuntimeSDK/SubscriptionTypes.swift +40 -8
- package/ios/vendor/CrocheRuntimeSDK/croche_ffi.swift +1720 -3883
- package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64/Headers/croche_ffiFFI.h +816 -1649
- 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 +816 -1649
- package/ios/vendor/croche_ffiFFI.xcframework/ios-arm64_x86_64-simulator/libcroche_ffi.a +2 -2
- package/package.json +3 -3
- package/scripts/README.md +1 -1
- package/scripts/check-swift-vendor-modules.sh +15 -0
- package/scripts/vendor-native.sh +4 -3
- 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 -113
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/NativeCoreStreamPort.kt +0 -201
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/ProjectPalRouting.kt +0 -25
- 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/StoragePal.kt +0 -18
- package/android/vendor/CrocheRuntimeSDK/core/dev/croche/StreamHub.kt +0 -252
- package/dist/runtime/src/pal/codec.d.ts +0 -15
- package/dist/runtime/src/pal/codec.js +0 -52
- package/ios/vendor/CrocheRuntimeSDK/Background.swift +0 -59
- package/ios/vendor/CrocheRuntimeSDK/StreamHub.swift +0 -496
- package/ios/vendor/CrocheRuntimeSDK/SubscriptionRuntime.swift +0 -44
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
package dev.croche
|
|
2
2
|
|
|
3
|
-
import com.google.gson
|
|
4
|
-
import java.io.File
|
|
5
|
-
import java.io.FileOutputStream
|
|
6
|
-
import java.nio.file.Files
|
|
7
|
-
import java.nio.file.StandardCopyOption.*
|
|
8
|
-
import java.nio.file.attribute.PosixFilePermissions
|
|
3
|
+
import com.google.gson.JsonObject
|
|
9
4
|
|
|
10
5
|
// Platform Abstraction Layer. The Rust Core decides; these perform what only the platform
|
|
11
6
|
// can: keep a credential in hardware-backed storage, and vouch for the app binary.
|
|
12
|
-
// See docs/
|
|
7
|
+
// See docs/hld/surface-and-hosts.md. Android implementations live in the android module.
|
|
13
8
|
|
|
14
9
|
/** Where the Runtime credential lives, apart from the general state file. load returns an
|
|
15
10
|
* object (empty when nothing is stored); save replaces the whole object atomically. */
|
|
16
|
-
interface RuntimeSecretStore {
|
|
11
|
+
internal interface RuntimeSecretStore {
|
|
17
12
|
fun load(): JsonObject
|
|
18
13
|
fun save(secrets: JsonObject)
|
|
19
14
|
/** Delete the credential item for real; an absent item is already removed. */
|
|
20
15
|
fun remove()
|
|
21
16
|
}
|
|
22
17
|
|
|
23
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* The platform's attestation of this app binary, bound to the client data hash.
|
|
20
|
+
*
|
|
21
|
+
* @property keyId Attestation key identifier, when supplied by the platform.
|
|
22
|
+
* @property token Proof token returned by the platform.
|
|
23
|
+
*/
|
|
24
24
|
data class RuntimeAttestation(val token: String, val keyId: String? = null)
|
|
25
25
|
|
|
26
|
+
/** Host provider of a device or app attestation for runtime registration. */
|
|
26
27
|
interface RuntimeAttestor {
|
|
27
28
|
/** "android-play-integrity" or "ios-app-attest"; declared to the Core in config. */
|
|
28
29
|
val platform: String
|
|
@@ -31,71 +32,6 @@ interface RuntimeAttestor {
|
|
|
31
32
|
fun attest(clientData: String, clientDataHash: String, cancellation: RuntimeCancellation): RuntimeAttestation
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
/**
|
|
35
|
-
* The OS's deferred work for the agent's scheduled notes while the app is not running (founder
|
|
36
|
-
* 17:14Z): WorkManager on Android (`dev.croche.android.WorkManagerScheduler`). The Runtime calls
|
|
37
|
-
* it with the earliest pending note after every change, at every open, and after every
|
|
38
|
-
* `deliverDue()`. The work it registers runs `deliverDue()`: inexact, never before that time. No
|
|
39
|
-
* exact alarms, notifications or permissions.
|
|
40
|
-
*/
|
|
41
|
-
interface RuntimeScheduler {
|
|
42
|
-
/** Replaces any earlier request with one at or after `earliestAtMs` (epoch ms). Idempotent:
|
|
43
|
-
* one request at a time, by a unique name. Throw `CrocheError("not_configured", ...)` when
|
|
44
|
-
* the app is not set up for it: the Runtime reports `schedule.degraded` with that code and
|
|
45
|
-
* still delivers while running and at the next open. */
|
|
46
|
-
fun schedule(earliestAtMs: Long)
|
|
47
|
-
/** Nothing is pending: withdraw the request. */
|
|
48
|
-
fun cancel()
|
|
49
|
-
/** A Runtime is opening with this scheduler. Throw `CrocheError("scheduler_conflict",
|
|
50
|
-
* ...)` to refuse it when its request name is already another open Runtime's: that name's
|
|
51
|
-
* runs could deliver through only one of them, including when the same scheduler object is
|
|
52
|
-
* given to a second Runtime. */
|
|
53
|
-
fun attach() {}
|
|
54
|
-
/** That Runtime closed (or failed to open): the name is free again. The Runtime calls this at
|
|
55
|
-
* most once per successful `attach`, however often it is closed. */
|
|
56
|
-
fun detach() {}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** A private file beside the state file. For hosts without a secret store (JVM servers,
|
|
60
|
-
* tests). On Android, use KeystoreSecretStore from the android module. */
|
|
61
|
-
class FileRuntimeSecretStore(private val file: File) : RuntimeSecretStore {
|
|
62
|
-
@Synchronized override fun load(): JsonObject {
|
|
63
|
-
if (!file.exists()) return JsonObject()
|
|
64
|
-
val saved = try { JsonParser.parseString(file.readText(Charsets.UTF_8)) }
|
|
65
|
-
catch (_: Exception) { throw CrocheError("corrupt_store", "Runtime credentials are unreadable; remove them to register again") }
|
|
66
|
-
if (!saved.isJsonObject) throw CrocheError("corrupt_store", "Runtime credentials must be an object")
|
|
67
|
-
return saved.asJsonObject
|
|
68
|
-
}
|
|
69
|
-
@Synchronized override fun remove() { Files.deleteIfExists(file.toPath()) }
|
|
70
|
-
@Synchronized override fun save(secrets: JsonObject) {
|
|
71
|
-
file.absoluteFile.parentFile.mkdirs()
|
|
72
|
-
val temporary = File.createTempFile("croche-secrets-", ".tmp", file.absoluteFile.parentFile)
|
|
73
|
-
try {
|
|
74
|
-
try { Files.setPosixFilePermissions(temporary.toPath(), PosixFilePermissions.fromString("rw-------")) }
|
|
75
|
-
catch (_: UnsupportedOperationException) {}
|
|
76
|
-
FileOutputStream(temporary).use { output -> output.write(secrets.toString().toByteArray(Charsets.UTF_8)); output.fd.sync() }
|
|
77
|
-
Files.move(temporary.toPath(), file.toPath(), ATOMIC_MOVE, REPLACE_EXISTING)
|
|
78
|
-
} finally { temporary.delete() }
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** One open Runtime per OS identity (a WorkManager name): the rule the OS schedulers share, kept
|
|
83
|
-
* in one place so the tests' schedulers run the same code as `WorkManagerScheduler` (Atlas, #323
|
|
84
|
-
* P1-2 and the NO at dc38bf0). `claim` is refused while the identity is held by anyone, the
|
|
85
|
-
* claiming object included: `create` claims once per Runtime, so one object given to two
|
|
86
|
-
* Runtimes is refused the second time. `release` frees it only for its holder. */
|
|
87
|
-
internal class SchedulerClaims(private val what: String) {
|
|
88
|
-
private val holders = HashMap<String, Any>()
|
|
89
|
-
@Synchronized fun claim(identity: String, by: Any) {
|
|
90
|
-
if (holders[identity] != null) {
|
|
91
|
-
throw CrocheError("scheduler_conflict", "Another open Runtime uses the $what \"$identity\"; give each Runtime its own, or close it first")
|
|
92
|
-
}
|
|
93
|
-
holders[identity] = by
|
|
94
|
-
}
|
|
95
|
-
@Synchronized fun release(identity: String, by: Any) { if (holders[identity] === by) holders.remove(identity) }
|
|
96
|
-
@Synchronized fun held(identity: String) = holders[identity] != null
|
|
97
|
-
}
|
|
98
|
-
|
|
99
35
|
/** Marks the React Native bridge's internal hooks: not part of the SDK's public API, not frozen,
|
|
100
36
|
* and replaced without notice. Interim until the public subscription for agent-initiated
|
|
101
37
|
* messages (F25 on #264) lands. */
|
|
@@ -2,38 +2,121 @@ package dev.croche
|
|
|
2
2
|
|
|
3
3
|
import com.google.gson.*
|
|
4
4
|
|
|
5
|
+
/** App and host configuration for opening a Croche session. */
|
|
5
6
|
data class OpenOptions(
|
|
7
|
+
/** Public project key identifying the Croche project. */
|
|
6
8
|
val projectKey: String,
|
|
9
|
+
/** Bundled project and agent configuration supplied to Core. */
|
|
7
10
|
val bundledConfig: JsonElement,
|
|
11
|
+
/** Optional user ID for the session. Core validates it for the selected access path. */
|
|
8
12
|
val user: String? = null,
|
|
13
|
+
/** Optional language preference supplied to Core. */
|
|
9
14
|
val language: String? = null,
|
|
15
|
+
/** Tool definitions registered by the app. */
|
|
10
16
|
val tools: List<ToolRegistration>? = null,
|
|
17
|
+
/** Wiki documents supplied with this session. */
|
|
11
18
|
val wiki: List<WikiDoc>? = null,
|
|
12
|
-
|
|
19
|
+
/** Host adapters to supply for this session. */
|
|
20
|
+
val adapters: List<Adapter>? = null,
|
|
13
21
|
/** Android Context; opaque to the common wrapper, never serialized as an object. */
|
|
14
22
|
val platform: Any? = null,
|
|
23
|
+
/** Optional credential for a trusted server host. */
|
|
15
24
|
val serverKey: String? = null,
|
|
16
|
-
|
|
25
|
+
/** Optional development key, used while developing the app. */
|
|
26
|
+
val developmentKey: String? = null,
|
|
27
|
+
/** Optional per-instance archive budgets. */
|
|
28
|
+
val archive: ArchiveOptions? = null,
|
|
29
|
+
/**
|
|
30
|
+
* The byte budget of each instance's live stream log, the screen record used for replay.
|
|
31
|
+
* Every storage size has a default and an app setting (founder 2026-11-19): null = omitted,
|
|
32
|
+
* and Core uses its default of 4 MiB. Core validates the value (2 MiB to 1 GiB); this SDK
|
|
33
|
+
* passes it through unchanged.
|
|
34
|
+
*/
|
|
35
|
+
val retentionBytes: Long? = null,
|
|
36
|
+
/** Total named-instance budget for this user, also used as the per-instance budget for finished turns waiting to seal. */
|
|
37
|
+
val instanceMaxBytes: Long? = null,
|
|
38
|
+
/**
|
|
39
|
+
* The app wiki's limits (founder 2026-11-19, B27): the largest document in markdown bytes
|
|
40
|
+
* (default 64 KiB; a larger one is refused, so split it) and the wiki's total (default
|
|
41
|
+
* 8 MiB). null = omitted; Core validates and applies the defaults.
|
|
42
|
+
*/
|
|
43
|
+
val wikiDocumentMaxBytes: Long? = null,
|
|
44
|
+
/** Total byte budget for the app wiki. Null uses the Core default of 8 MiB. */
|
|
45
|
+
val wikiMaxBytes: Long? = null,
|
|
46
|
+
/** App-wide input and scheduling guards for every agent (B27). Code-owned: a bundle cannot set them. */
|
|
47
|
+
val limits: LimitsOptions? = null,
|
|
17
48
|
) {
|
|
49
|
+
/** Return the type label without printing configuration or credentials. */
|
|
50
|
+
override fun toString(): String = "OpenOptions"
|
|
51
|
+
|
|
18
52
|
internal fun json() = JsonObject().apply {
|
|
19
53
|
addProperty("projectKey", projectKey); add("bundledConfig", bundledConfig.deepCopy())
|
|
20
54
|
user?.let { addProperty("user", it) }; language?.let { addProperty("language", it) }
|
|
21
|
-
serverKey?.let { addProperty("serverKey", it) };
|
|
55
|
+
serverKey?.let { addProperty("serverKey", it) }; developmentKey?.let { addProperty("developmentKey", it) }
|
|
56
|
+
archive?.let { add("archive", it.json()) }
|
|
57
|
+
retentionBytes?.let { addProperty("retentionBytes", it) }
|
|
58
|
+
instanceMaxBytes?.let { addProperty("instanceMaxBytes", it) }
|
|
59
|
+
wikiDocumentMaxBytes?.let { addProperty("wikiDocumentMaxBytes", it) }
|
|
60
|
+
wikiMaxBytes?.let { addProperty("wikiMaxBytes", it) }
|
|
61
|
+
limits?.let { add("limits", it.json()) }
|
|
62
|
+
adapters?.let { add("adapters", it.markers()) }
|
|
22
63
|
wiki?.let { docs -> add("wiki", JsonArray().apply { docs.forEach { add(it.json()) } }) }
|
|
23
64
|
platform?.let { add("platform", JsonNull.INSTANCE) }
|
|
24
65
|
}
|
|
25
66
|
}
|
|
26
67
|
|
|
27
|
-
/**
|
|
68
|
+
/** `OpenOptions.limits`: each null field is omitted and Core applies its default. */
|
|
69
|
+
data class LimitsOptions(
|
|
70
|
+
/** Total user and app-event text of one send, 1,000..200,000 UTF-16 units (default 32,000). */
|
|
71
|
+
val userTextChars: Long? = null,
|
|
72
|
+
/** Total app-state text of one send, 1,000..200,000 (default 32,000). */
|
|
73
|
+
val appStateChars: Long? = null,
|
|
74
|
+
/** One tool result's value as compact JSON, 1,000..1,000,000 (default 200,000). */
|
|
75
|
+
val toolResultChars: Long? = null,
|
|
76
|
+
/** Images per message or tool result, 1..16 (default 4). Image byte limits stay fixed. */
|
|
77
|
+
val turnImages: Long? = null,
|
|
78
|
+
/** Schedule notes pending at once, 1..20 (default 20). */
|
|
79
|
+
val pendingSchedules: Long? = null,
|
|
80
|
+
) {
|
|
81
|
+
internal fun json() = JsonObject().apply {
|
|
82
|
+
userTextChars?.let { addProperty("userTextChars", it) }
|
|
83
|
+
appStateChars?.let { addProperty("appStateChars", it) }
|
|
84
|
+
toolResultChars?.let { addProperty("toolResultChars", it) }
|
|
85
|
+
turnImages?.let { addProperty("turnImages", it) }
|
|
86
|
+
pendingSchedules?.let { addProperty("pendingSchedules", it) }
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* A patch is sent on every open; Core decides identity, conflicts and the effective config.
|
|
92
|
+
*
|
|
93
|
+
* @property config Optional instance-specific patch passed to Core on open.
|
|
94
|
+
* @property id Name of the conversation within the agent.
|
|
95
|
+
*/
|
|
28
96
|
data class Instance(val id: String, val config: JsonElement? = null) {
|
|
29
97
|
internal fun json() = JsonObject().apply { addProperty("id", id); config?.let { add("config", it.deepCopy()) } }
|
|
30
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Options for opening a conversation from an agent definition.
|
|
101
|
+
*
|
|
102
|
+
* @property instance Named conversation and its optional configuration patch.
|
|
103
|
+
* @property tools Tool scope for this agent handle.
|
|
104
|
+
* @property wiki Wiki scope for this agent handle.
|
|
105
|
+
*/
|
|
31
106
|
data class AgentOptions(val instance: Instance? = null, val tools: ToolSelection? = null, val wiki: WikiSelection? = null) {
|
|
32
107
|
internal fun json() = JsonObject().apply {
|
|
33
108
|
instance?.let { add("instance", it.json()) }; tools?.let { add("tools", it.json()) }; wiki?.let { add("wiki", it.json()) }
|
|
34
109
|
}
|
|
35
110
|
}
|
|
36
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Scoped configuration for one tool available to an agent.
|
|
114
|
+
*
|
|
115
|
+
* @property bind Optional bindings supplied for this scoped tool.
|
|
116
|
+
* @property commands Optional selection of command keys the agent can use.
|
|
117
|
+
* @property guide Optional guidance for using this tool in the current scope.
|
|
118
|
+
* @property tool Name of the registered tool.
|
|
119
|
+
*/
|
|
37
120
|
data class ToolEntry(val tool: String, val bind: JsonObject? = null, val commands: List<String>? = null, val guide: String? = null) {
|
|
38
121
|
internal fun json() = JsonObject().apply {
|
|
39
122
|
addProperty("tool", tool); bind?.let { add("bind", it.deepCopy()) }
|
|
@@ -41,30 +124,70 @@ data class ToolEntry(val tool: String, val bind: JsonObject? = null, val command
|
|
|
41
124
|
guide?.let { addProperty("guide", it) }
|
|
42
125
|
}
|
|
43
126
|
}
|
|
127
|
+
/** Controls which registered tools an agent can use. */
|
|
44
128
|
sealed interface ToolSelection {
|
|
129
|
+
/** Select all available tools. */
|
|
45
130
|
data object All : ToolSelection
|
|
131
|
+
/**
|
|
132
|
+
* Select the listed tools and their scoped settings.
|
|
133
|
+
*
|
|
134
|
+
* @property entries Tool entries included in the selection.
|
|
135
|
+
*/
|
|
46
136
|
data class Only(val entries: List<ToolEntry>) : ToolSelection
|
|
137
|
+
/** Encode the tool scope for Core as an all selector or a list of entries. */
|
|
47
138
|
fun json(): JsonElement = when (this) {
|
|
48
139
|
All -> JsonPrimitive("all")
|
|
49
140
|
is Only -> JsonArray().apply { entries.forEach { add(it.json()) } }
|
|
50
141
|
}
|
|
51
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Scoped wiki document and optional guidance for the agent.
|
|
145
|
+
*
|
|
146
|
+
* @property doc Path of the wiki document to include.
|
|
147
|
+
* @property guide Optional guidance for the agent on using this document.
|
|
148
|
+
*/
|
|
52
149
|
data class WikiEntry(val doc: String, val guide: String? = null) {
|
|
53
150
|
internal fun json() = JsonObject().apply { addProperty("doc", doc); guide?.let { addProperty("guide", it) } }
|
|
54
151
|
}
|
|
152
|
+
/** Controls which wiki documents are available to an agent. */
|
|
55
153
|
sealed interface WikiSelection {
|
|
154
|
+
/** Select all available wiki documents. */
|
|
56
155
|
data object All : WikiSelection
|
|
156
|
+
/**
|
|
157
|
+
* Select the listed documents and any guidance supplied for them.
|
|
158
|
+
*
|
|
159
|
+
* @property entries Document entries included in the selection.
|
|
160
|
+
*/
|
|
57
161
|
data class Only(val entries: List<WikiEntry>) : WikiSelection
|
|
162
|
+
/** Encode the wiki scope for Core as an all selector or a list of entries. */
|
|
58
163
|
fun json(): JsonElement = when (this) {
|
|
59
164
|
All -> JsonPrimitive("all")
|
|
60
165
|
is Only -> JsonArray().apply { entries.forEach { add(it.json()) } }
|
|
61
166
|
}
|
|
62
167
|
}
|
|
168
|
+
/** A wiki document supplied inline or addressed by a file. */
|
|
63
169
|
sealed interface WikiDoc {
|
|
170
|
+
/** Path used to identify the document in the wiki. */
|
|
64
171
|
val path: String
|
|
172
|
+
/** Description supplied with the document. */
|
|
65
173
|
val description: String
|
|
174
|
+
/**
|
|
175
|
+
* A wiki document supplied as Markdown text.
|
|
176
|
+
*
|
|
177
|
+
* @property description Description supplied for this document.
|
|
178
|
+
* @property markdown Markdown content supplied by the app.
|
|
179
|
+
* @property path Path used to identify the document in the wiki.
|
|
180
|
+
*/
|
|
66
181
|
data class Markdown(override val path: String, override val description: String, val markdown: String) : WikiDoc
|
|
182
|
+
/**
|
|
183
|
+
* A wiki document whose content comes from a file.
|
|
184
|
+
*
|
|
185
|
+
* @property description Description supplied for this document.
|
|
186
|
+
* @property file File location passed to Core to load the document.
|
|
187
|
+
* @property path Path used to identify the document in the wiki.
|
|
188
|
+
*/
|
|
67
189
|
data class File(override val path: String, override val description: String, val file: String) : WikiDoc
|
|
190
|
+
/** Encode the document as a Markdown or file descriptor for Core. */
|
|
68
191
|
fun json() = JsonObject().apply {
|
|
69
192
|
addProperty("path", path); addProperty("description", description)
|
|
70
193
|
when (val doc = this@WikiDoc) {
|
|
@@ -73,29 +196,63 @@ sealed interface WikiDoc {
|
|
|
73
196
|
}
|
|
74
197
|
}
|
|
75
198
|
}
|
|
76
|
-
/**
|
|
199
|
+
/**
|
|
200
|
+
* Separate second argument to Croche.open; Core validates the recover string.
|
|
201
|
+
*
|
|
202
|
+
* @property recover Recovery mode passed to Core for opening a handle that supports deletion and close.
|
|
203
|
+
*/
|
|
77
204
|
data class RecoveryOptions(val recover: String) {
|
|
78
205
|
internal fun json() = JsonObject().apply { addProperty("recover", recover) }
|
|
79
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* Limits deletion to one agent or one conversation. With neither field, the deletion is user-wide.
|
|
209
|
+
*
|
|
210
|
+
* @property agent Agent whose local data is selected for deletion.
|
|
211
|
+
* @property instance Named conversation within the selected agent.
|
|
212
|
+
*/
|
|
80
213
|
data class DeleteDataOptions(val agent: String? = null, val instance: String? = null) {
|
|
81
214
|
internal fun json() = JsonObject().apply { agent?.let { addProperty("agent", it) }; instance?.let { addProperty("instance", it) } }
|
|
82
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Response options for a request that waits for a terminal result.
|
|
218
|
+
*
|
|
219
|
+
* @property responseFormat Optional format supplied to Core for structured output.
|
|
220
|
+
* @property wait Extra completion condition. Null returns when the request is terminal.
|
|
221
|
+
*/
|
|
83
222
|
data class RequestOptions(val responseFormat: JsonObject? = null, val wait: RequestWait? = null) {
|
|
84
223
|
internal fun json() = JsonObject().apply {
|
|
85
224
|
responseFormat?.let { add("responseFormat", it.deepCopy()) }; wait?.let { addProperty("wait", it.name.lowercase()) }
|
|
86
225
|
}
|
|
87
226
|
}
|
|
88
|
-
|
|
227
|
+
/**
|
|
228
|
+
* @property onEvent Called with each event for this subscription. Update the transcript and controls from it together.
|
|
229
|
+
*
|
|
230
|
+
* @property after Resume after this cursor in its stream log.
|
|
231
|
+
* @property initialMessages Number of recent messages to replay on attach. Null uses Core's default.
|
|
232
|
+
*/
|
|
233
|
+
data class SubscribeOptions(val initialMessages: Int? = null, val after: Cursor? = null,
|
|
89
234
|
val onEvent: suspend (AppStreamContract.AgentEvent) -> Unit) {
|
|
90
235
|
internal fun json() = JsonObject().apply {
|
|
91
236
|
initialMessages?.let { addProperty("initialMessages", it) }
|
|
92
237
|
after?.let { add("after", JsonObject().apply { addProperty("logId", it.logId); addProperty("seq", it.seq) }) }
|
|
93
|
-
deltaMs?.let { addProperty("deltaMs", it) }
|
|
94
238
|
}
|
|
95
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Selects a page of retained transcript events to send to a subscription.
|
|
242
|
+
*
|
|
243
|
+
* @property before Exclusive sequence bound for older events. Null requests the latest page.
|
|
244
|
+
* @property limit Requested page size.
|
|
245
|
+
*/
|
|
96
246
|
data class HistoryOptions(val before: Long? = null, val limit: Int) {
|
|
97
247
|
internal fun json() = JsonObject().apply { before?.let { addProperty("before", it) }; addProperty("limit", limit) }
|
|
98
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* Optional time bounds and limit for looking up scheduled wakes.
|
|
251
|
+
*
|
|
252
|
+
* @property after Inclusive lower bound in epoch milliseconds. Pass the previous result's next value to continue.
|
|
253
|
+
* @property before Upper time bound in epoch milliseconds.
|
|
254
|
+
* @property limit Requested maximum number of wakes.
|
|
255
|
+
*/
|
|
99
256
|
data class WakeQuery(val before: Long? = null, val after: Long? = null, val limit: Int? = null) {
|
|
100
257
|
internal fun json() = JsonObject().apply {
|
|
101
258
|
before?.let { addProperty("before", it) }; after?.let { addProperty("after", it) }; limit?.let { addProperty("limit", it) }
|
|
@@ -105,13 +262,42 @@ data class WakeQuery(val before: Long? = null, val after: Long? = null, val limi
|
|
|
105
262
|
* Core's background notification, forwarded unchanged. A skipped event's known reasons are
|
|
106
263
|
* `storage_unavailable` and `os_registration_failed`; future reasons remain readable strings.
|
|
107
264
|
* OS registration failure has only type/reason/at and never contains host failure details.
|
|
265
|
+
*
|
|
266
|
+
* @property at Event timestamp, when supplied.
|
|
267
|
+
* @property fields Complete notification object received from Core.
|
|
268
|
+
* @property reason Background deferral or skip reason, when supplied.
|
|
269
|
+
* @property type Notification type sent to the background sink.
|
|
108
270
|
*/
|
|
109
271
|
data class BackgroundEvent(val type: String, val at: String?, val reason: String?, val fields: JsonObject)
|
|
110
272
|
|
|
111
|
-
/**
|
|
112
|
-
|
|
273
|
+
/**
|
|
274
|
+
* @property sink Let the app react when scheduled work was delivered or could not run.
|
|
275
|
+
* @property storage Use the same store as the app uses when opening Croche.
|
|
276
|
+
*
|
|
277
|
+
* @property adapters Host adapters for the background run. Use the same storage as the foreground session.
|
|
278
|
+
*/
|
|
279
|
+
data class BackgroundOptions(val sink: ((BackgroundEvent) -> Unit)? = null, val adapters: List<Adapter>? = null)
|
|
113
280
|
|
|
114
|
-
/**
|
|
281
|
+
/**
|
|
282
|
+
* Connection details for attaching a debugger.
|
|
283
|
+
*
|
|
284
|
+
* @property token Debugger access token.
|
|
285
|
+
* @property url Endpoint for the debugger connection.
|
|
286
|
+
*/
|
|
115
287
|
data class DebugAttachOptions(val url: String, val token: String) {
|
|
116
288
|
internal fun json() = JsonObject().apply { addProperty("url", url); addProperty("token", token) }
|
|
117
289
|
}
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* App-wide host policy; each instance has its own byte budget. Core validates.
|
|
294
|
+
*
|
|
295
|
+
* @property maxBytes History byte budget for each agent instance. Null uses the Core default of 8 MiB.
|
|
296
|
+
* @property notesMaxBytes Shared archive byte budget for retired summary pieces and saved memory facts per instance. Null uses the Core default of 4 MiB.
|
|
297
|
+
*/
|
|
298
|
+
data class ArchiveOptions(val maxBytes: Long? = null, val notesMaxBytes: Long? = null) {
|
|
299
|
+
internal fun json() = JsonObject().apply {
|
|
300
|
+
maxBytes?.let { addProperty("maxBytes", it) }
|
|
301
|
+
notesMaxBytes?.let { addProperty("notesMaxBytes", it) }
|
|
302
|
+
}
|
|
303
|
+
}
|
|
@@ -2,18 +2,101 @@ package dev.croche
|
|
|
2
2
|
|
|
3
3
|
import com.google.gson.*
|
|
4
4
|
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Debugger attachment and the capabilities Core reports. New capability values can appear.
|
|
7
|
+
*
|
|
8
|
+
* @property capabilities Capabilities that Core reports for the attached debugger.
|
|
9
|
+
* @property debuggerId Identifier returned for the attached debugger.
|
|
10
|
+
*/
|
|
6
11
|
data class AttachedDebugger(val debuggerId: String, val capabilities: List<String>)
|
|
12
|
+
/**
|
|
13
|
+
* A scheduled wake for a user.
|
|
14
|
+
*
|
|
15
|
+
* @property at Scheduled wake time in epoch milliseconds.
|
|
16
|
+
* @property user User ID associated with the wake, if present.
|
|
17
|
+
*/
|
|
7
18
|
data class Wake(val user: String?, val at: Long)
|
|
19
|
+
/**
|
|
20
|
+
* Page of scheduled wakes returned by the host query.
|
|
21
|
+
*
|
|
22
|
+
* @property next Continue the query using this epoch-millisecond value as the after bound, when present.
|
|
23
|
+
* @property wakes Scheduled wakes included in this result.
|
|
24
|
+
*/
|
|
8
25
|
data class WakeTimes(val wakes: List<Wake>, val next: Long?)
|
|
26
|
+
/**
|
|
27
|
+
* One owner whose due background work could not be completed in this run.
|
|
28
|
+
*
|
|
29
|
+
* @property agent Agent ID for the deferred work.
|
|
30
|
+
* @property code Machine-readable reason work was deferred.
|
|
31
|
+
* @property instance Named instance for the deferred work, if any.
|
|
32
|
+
* @property message Human-readable deferral description.
|
|
33
|
+
* @property user User ID for the deferred work, if present.
|
|
34
|
+
*/
|
|
9
35
|
data class DeliveryDeferred(val user: String?, val agent: String, val instance: String?, val code: String, val message: String)
|
|
36
|
+
/**
|
|
37
|
+
* Result of a background delivery run.
|
|
38
|
+
*
|
|
39
|
+
* @property deferred Agents and instances whose due work was deferred, with reasons.
|
|
40
|
+
* @property delivered Number of usage reports the runtime delivered in this run.
|
|
41
|
+
* @property ran Whether Core reports that the delivery pass ran.
|
|
42
|
+
*/
|
|
10
43
|
data class DueDelivery(val ran: Boolean, val delivered: Int, val deferred: List<DeliveryDeferred>)
|
|
44
|
+
/**
|
|
45
|
+
* One saved memory item returned by the memory list.
|
|
46
|
+
*
|
|
47
|
+
* @property fields All fields from Core's JSON item, including fields the Kotlin wrapper does not project individually.
|
|
48
|
+
* @property id Item ID used to select the fact for deletion.
|
|
49
|
+
* @property text Saved text for this item.
|
|
50
|
+
*/
|
|
11
51
|
data class MemoryItem(val id: String, val text: String, val fields: Map<String, JsonElement>)
|
|
52
|
+
/**
|
|
53
|
+
* The options of every paged public list: `listAttachments`, `memory.list` and `wiki.list`.
|
|
54
|
+
* `limit` is a positive integer; a page holds at most 128 items, which is also the default.
|
|
55
|
+
* `cursor` is the cursor of the previous page of the same list.
|
|
56
|
+
*
|
|
57
|
+
* @property cursor Cursor returned by the previous page of the same list.
|
|
58
|
+
* @property limit Requested number of items, capped at 128. Null uses 128.
|
|
59
|
+
*/
|
|
60
|
+
data class ListOptions(val limit: Int? = null, val cursor: String? = null) {
|
|
61
|
+
internal fun json(): String = JsonObject().also { fields ->
|
|
62
|
+
limit?.let { fields.addProperty("limit", it) }
|
|
63
|
+
cursor?.let { fields.addProperty("cursor", it) }
|
|
64
|
+
}.toString()
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* One page of a public list, in the list's stable order. `cursor` is present only when more
|
|
68
|
+
* items follow: pass it back to the same list to continue strictly past this page.
|
|
69
|
+
*
|
|
70
|
+
* @property cursor Opaque cursor to pass back to this list when another page is available.
|
|
71
|
+
* @property items Items returned in this page.
|
|
72
|
+
*/
|
|
73
|
+
data class Page<T>(val items: List<T>, val cursor: String? = null)
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* How Croche Cloud verified this installation (`croche.verification()`, founder 2026-11-22 02:31:47Z). Verification is
|
|
77
|
+
* not access: a withheld key leaves it unchanged. [status]: attested, server, development, unverified, or unknown (not
|
|
78
|
+
* registered yet, or Cloud did not say). [lastAttestation]: the device-side code of the last attestor attempt without a
|
|
79
|
+
* usable proof; null does not mean Cloud accepted a proof. Strings match TS/RN and Swift; the set is open.
|
|
80
|
+
*
|
|
81
|
+
* @property lastAttestation Device-side code from the last attestor attempt that did not produce usable proof, if present.
|
|
82
|
+
* @property status Open-ended installation verification status reported by Core.
|
|
83
|
+
*/
|
|
84
|
+
data class Verification(val status: String, val lastAttestation: String?)
|
|
12
85
|
|
|
13
86
|
/** Known reply fields are projected; unknown fields never prevent a read. */
|
|
14
87
|
internal object PublicResults {
|
|
88
|
+
fun attachment(json: String): AppStreamContract.Attachment = Gson().fromJson(json, AppStreamContract.Attachment::class.java)
|
|
89
|
+
/** Core's `{items, cursor?}` reply, each item read by `item`. */
|
|
90
|
+
private fun <T> page(json: String, item: (JsonElement) -> T): Page<T> = objectValue(json).let { reply ->
|
|
91
|
+
Page(reply.getAsJsonArray("items").map(item), reply.get("cursor")?.takeUnless { it.isJsonNull }?.asString)
|
|
92
|
+
}
|
|
93
|
+
fun attachments(json: String): Page<AppStreamContract.Attachment> = page(json) { attachment(it.toString()) }
|
|
94
|
+
fun attachmentData(json: String): AttachmentData = Gson().fromJson(json, AttachmentData::class.java)
|
|
15
95
|
private fun objectValue(json: String) = JsonParser.parseString(json).asJsonObject
|
|
16
96
|
private fun JsonObject.optionalLong(key: String) = get(key)?.takeUnless { it.isJsonNull }?.asLong
|
|
97
|
+
fun verification(json: String): Verification = objectValue(json).let {
|
|
98
|
+
Verification(it.get("status").asString, it.get("lastAttestation")?.takeUnless { v -> v.isJsonNull }?.asString)
|
|
99
|
+
}
|
|
17
100
|
fun wakes(json: String): WakeTimes = objectValue(json).let { value ->
|
|
18
101
|
WakeTimes(value.getAsJsonArray("wakes").map { entry -> entry.asJsonObject.let {
|
|
19
102
|
Wake(it.get("user")?.takeUnless { user -> user.isJsonNull }?.asString, it.get("at").asLong)
|
|
@@ -30,12 +113,12 @@ internal object PublicResults {
|
|
|
30
113
|
fun debug(json: String): AttachedDebugger = objectValue(json).let {
|
|
31
114
|
AttachedDebugger(it.get("debuggerId").asString, it.getAsJsonArray("capabilities").map { v -> v.asString })
|
|
32
115
|
}
|
|
33
|
-
fun memories(json: String):
|
|
116
|
+
fun memories(json: String): Page<MemoryItem> = page(json) { entry ->
|
|
34
117
|
val value = entry.asJsonObject
|
|
35
118
|
MemoryItem(value.get("id").asString, value.get("text").asString,
|
|
36
119
|
value.entrySet().associate { it.key to it.value.deepCopy() })
|
|
37
120
|
}
|
|
38
|
-
fun wiki(json: String):
|
|
121
|
+
fun wiki(json: String): Page<WikiDoc> = page(json) { entry ->
|
|
39
122
|
val value = entry.asJsonObject
|
|
40
123
|
val path = value.get("path").asString; val description = value.get("description").asString
|
|
41
124
|
if (value.has("markdown")) WikiDoc.Markdown(path, description, value.get("markdown").asString)
|
|
@@ -6,11 +6,44 @@ import dev.croche.s7.publicCall
|
|
|
6
6
|
|
|
7
7
|
/** The same envelope as TS; all outcomes and costs are supplied by Core. */
|
|
8
8
|
sealed interface RunToolResult {
|
|
9
|
+
/**
|
|
10
|
+
* A successful app tool result.
|
|
11
|
+
*
|
|
12
|
+
* @property attachments Descriptors for files produced by the tool.
|
|
13
|
+
* @property id ID used to correlate the result to the app call.
|
|
14
|
+
* @property output JSON value returned by the tool.
|
|
15
|
+
* @property costStatus Status of the cost observation for this run.
|
|
16
|
+
* @property cost Recorded cost in credits, or null when unavailable.
|
|
17
|
+
*/
|
|
9
18
|
data class Ok(val id: String, val output: JsonElement, val attachments: List<AppStreamContract.Attachment>,
|
|
10
19
|
val cost: Double?, val costStatus: String) : RunToolResult
|
|
20
|
+
/**
|
|
21
|
+
* The tool ran to a failed result.
|
|
22
|
+
*
|
|
23
|
+
* @property category Group used to decide how the app should handle the error.
|
|
24
|
+
* @property code Machine-readable failure code.
|
|
25
|
+
* @property id ID used to correlate the result to the app call.
|
|
26
|
+
* @property message Human-readable failure description.
|
|
27
|
+
* @property costStatus Status of the cost observation for this run.
|
|
28
|
+
* @property cost Recorded cost in credits, or null when unavailable.
|
|
29
|
+
*/
|
|
11
30
|
data class Failed(val id: String, val code: String, val category: ErrorCategory, val message: String,
|
|
12
31
|
val cost: Double?, val costStatus: String) : RunToolResult
|
|
32
|
+
/**
|
|
33
|
+
* An operation for which Core could not recover a result.
|
|
34
|
+
*
|
|
35
|
+
* @property category Group used to decide how the app should handle the failure.
|
|
36
|
+
* @property code Machine-readable reason the result could not be recovered.
|
|
37
|
+
* @property id ID used to correlate the result to the app call.
|
|
38
|
+
* @property message Human-readable reason the result could not be recovered.
|
|
39
|
+
*/
|
|
13
40
|
data class Lost(val id: String, val code: String, val category: ErrorCategory, val message: String) : RunToolResult
|
|
41
|
+
/**
|
|
42
|
+
* A tool result whose status this SDK does not recognize.
|
|
43
|
+
*
|
|
44
|
+
* @property fields Original JSON result, preserved for inspection.
|
|
45
|
+
* @property status Original status string.
|
|
46
|
+
*/
|
|
14
47
|
data class Unknown(val status: String, val fields: JsonElement) : RunToolResult
|
|
15
48
|
}
|
|
16
49
|
|
|
@@ -14,7 +14,7 @@ internal fun SendInput.encoded(options: SendOptions = SendOptions()): JsonObject
|
|
|
14
14
|
element.kind?.let { addProperty("kind", it.rawValue) }
|
|
15
15
|
}
|
|
16
16
|
is ImageInput -> {
|
|
17
|
-
// Bytes never enter JSON: only the image type/alt, bytes in
|
|
17
|
+
// Bytes never enter JSON: only the image type/alt, bytes in CoreAttachmentInput.
|
|
18
18
|
addProperty("type", "image")
|
|
19
19
|
if (element.uri != null) addProperty("uri", element.uri)
|
|
20
20
|
element.alt?.let { addProperty("alt", it) }
|