|
1 | | -import { PrimeAgentSettings, ProviderDriverKind, type ServerProvider } from "@t3tools/contracts"; |
| 1 | +import { |
| 2 | + PrimeAgentSettings, |
| 3 | + ProviderDriverKind, |
| 4 | + type ServerProvider, |
| 5 | + type ServerProviderDistribution, |
| 6 | +} from "@t3tools/contracts"; |
2 | 7 | import { HostProcessPlatform } from "@t3tools/shared/hostProcess"; |
3 | 8 | import { resolveCommandPath } from "@t3tools/shared/shell"; |
4 | 9 | import * as Crypto from "effect/Crypto"; |
@@ -32,6 +37,12 @@ import { readPrimeAgentBackends, readPrimeAgentCapacity } from "../primeAgentBac |
32 | 37 | const PRIME_AGENT_TURN_END_CAPACITY_FRESH_MS = 60_000; |
33 | 38 | import { makePrimeAgentDaemonAdapter } from "../prime/PrimeAgentDaemonAdapter.ts"; |
34 | 39 | import { negotiatePrimeAgentBackend } from "../prime/PrimeAgentBackendSelection.ts"; |
| 40 | +import { locatePrimeAgentPublicPackage } from "../prime/PrimeAgentDaemonBridge.ts"; |
| 41 | +import { |
| 42 | + inspectPrimeAgentDistribution, |
| 43 | + makeLatestPrimePublicationLoader, |
| 44 | + makePrimeDistributionNetworkDependencies, |
| 45 | +} from "../prime/PrimeAgentDistributionVerifier.ts"; |
35 | 46 | import { makePrimeAgentDaemonManager } from "../prime/PrimeAgentDaemonManager.ts"; |
36 | 47 | import { |
37 | 48 | defaultProviderContinuationIdentity, |
@@ -137,6 +148,67 @@ export const PrimeAgentDriver: ProviderDriver<PrimeAgentSettings, PrimeAgentDriv |
137 | 148 | continuationGroupKey: continuationIdentity.continuationKey, |
138 | 149 | }); |
139 | 150 | const effectiveConfig = { ...config, enabled } satisfies PrimeAgentSettings; |
| 151 | + const loadLatestVerifiedPublication = makeLatestPrimePublicationLoader( |
| 152 | + makePrimeDistributionNetworkDependencies({ |
| 153 | + tufCachePath: path.join(serverConfig.stateDir, "sigstore-tuf"), |
| 154 | + }), |
| 155 | + ); |
| 156 | + const inspectDistribution = ( |
| 157 | + snapshot: ServerProvider, |
| 158 | + enableUpdateChecks: boolean | undefined, |
| 159 | + ): Effect.Effect<ServerProviderDistribution> => { |
| 160 | + if (!snapshot.enabled || !snapshot.installed) { |
| 161 | + return Effect.succeed({ |
| 162 | + classification: "stock-or-custom" as const, |
| 163 | + channel: null, |
| 164 | + buildId: null, |
| 165 | + sequence: null, |
| 166 | + latestBuildId: null, |
| 167 | + latestSequence: null, |
| 168 | + updateAvailable: false, |
| 169 | + checkedAt: snapshot.checkedAt, |
| 170 | + message: "This Prime installation is maintained manually.", |
| 171 | + }); |
| 172 | + } |
| 173 | + return Effect.gen(function* () { |
| 174 | + const executablePath = path.resolve( |
| 175 | + yield* resolveCommandPath(effectiveConfig.binaryPath || "prime-agent", { |
| 176 | + env: processEnv, |
| 177 | + }), |
| 178 | + ); |
| 179 | + const publicPackage = yield* locatePrimeAgentPublicPackage(executablePath); |
| 180 | + return yield* Effect.promise(() => |
| 181 | + inspectPrimeAgentDistribution( |
| 182 | + { |
| 183 | + stateDir: serverConfig.stateDir, |
| 184 | + instanceId, |
| 185 | + packageRoot: publicPackage.packageRoot, |
| 186 | + platform: hostPlatform, |
| 187 | + checkedAt: snapshot.checkedAt, |
| 188 | + ...(enableUpdateChecks === undefined ? {} : { enableUpdateChecks }), |
| 189 | + }, |
| 190 | + { loadLatestVerifiedPublication }, |
| 191 | + ), |
| 192 | + ); |
| 193 | + }).pipe( |
| 194 | + Effect.catchCause(() => |
| 195 | + Effect.succeed({ |
| 196 | + classification: "stock-or-custom" as const, |
| 197 | + channel: null, |
| 198 | + buildId: null, |
| 199 | + sequence: null, |
| 200 | + latestBuildId: null, |
| 201 | + latestSequence: null, |
| 202 | + updateAvailable: false, |
| 203 | + checkedAt: snapshot.checkedAt, |
| 204 | + message: |
| 205 | + "Pylon could not inspect the selected Prime distribution; Prime remains ready and manually maintained.", |
| 206 | + }), |
| 207 | + ), |
| 208 | + Effect.provideService(FileSystem.FileSystem, fileSystem), |
| 209 | + Effect.provideService(Path.Path, path), |
| 210 | + ); |
| 211 | + }; |
140 | 212 | const maintenanceCapabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(UPDATE, { |
141 | 213 | binaryPath: effectiveConfig.binaryPath, |
142 | 214 | env: processEnv, |
@@ -286,6 +358,7 @@ export const PrimeAgentDriver: ProviderDriver<PrimeAgentSettings, PrimeAgentDriv |
286 | 358 | snapshot: currentSnapshot, |
287 | 359 | maintenanceCapabilities, |
288 | 360 | enableProviderUpdateChecks: settings.enableProviderUpdateChecks, |
| 361 | + distribution: inspectDistribution(currentSnapshot, settings.enableProviderUpdateChecks), |
289 | 362 | publishSnapshot, |
290 | 363 | httpClient, |
291 | 364 | }), |
|
0 commit comments