| 1 | import * as Schema from "effect/Schema"; |
| 2 | |
| 3 | import { |
| 4 | AuthSessionId, |
| 5 | EnvironmentId, |
| 6 | RpcClientId, |
| 7 | ThreadId, |
| 8 | TrimmedNonEmptyString, |
| 9 | } from "./baseSchemas.ts"; |
| 10 | import { ProviderInstanceId } from "./providerInstance.ts"; |
| 11 | |
| 12 | export const BackgroundBooleanState = Schema.Literals(["true", "false", "unknown"]); |
| 13 | export type BackgroundBooleanState = typeof BackgroundBooleanState.Type; |
| 14 | |
| 15 | export const HostPowerThermalState = Schema.Literals([ |
| 16 | "unknown", |
| 17 | "nominal", |
| 18 | "fair", |
| 19 | "serious", |
| 20 | "critical", |
| 21 | ]); |
| 22 | export type HostPowerThermalState = typeof HostPowerThermalState.Type; |
| 23 | |
| 24 | export const HostPowerSource = Schema.Literals([ |
| 25 | "unknown", |
| 26 | "node-macos-shell", |
| 27 | "node-macos-native", |
| 28 | "node-linux", |
| 29 | "node-windows", |
| 30 | "electron-main", |
| 31 | ]); |
| 32 | export type HostPowerSource = typeof HostPowerSource.Type; |
| 33 | |
| 34 | export const HostPowerSnapshot = Schema.Struct({ |
| 35 | source: HostPowerSource, |
| 36 | idle: BackgroundBooleanState, |
| 37 | idleSeconds: Schema.NullOr(Schema.Number), |
| 38 | locked: BackgroundBooleanState, |
| 39 | suspended: Schema.Boolean, |
| 40 | onBattery: BackgroundBooleanState, |
| 41 | lowPowerMode: BackgroundBooleanState, |
| 42 | thermalState: HostPowerThermalState, |
| 43 | stale: Schema.Boolean, |
| 44 | updatedAt: Schema.DateTimeUtc, |
| 45 | }); |
| 46 | export type HostPowerSnapshot = typeof HostPowerSnapshot.Type; |
| 47 | |
| 48 | export const BackgroundScope = Schema.Union([ |
| 49 | Schema.Struct({ type: Schema.Literal("server-config") }), |
| 50 | Schema.Struct({ |
| 51 | type: Schema.Literal("provider-status"), |
| 52 | instanceId: Schema.optionalKey(ProviderInstanceId), |
| 53 | }), |
| 54 | Schema.Struct({ type: Schema.Literal("vcs-status"), cwd: Schema.String }), |
| 55 | Schema.Struct({ type: Schema.Literal("git-refs"), cwd: Schema.String }), |
| 56 | Schema.Struct({ type: Schema.Literal("diagnostics") }), |
| 57 | Schema.Struct({ type: Schema.Literal("thread"), threadId: ThreadId }), |
| 58 | ]); |
| 59 | export type BackgroundScope = typeof BackgroundScope.Type; |
| 60 | |
| 61 | export const ClientKind = Schema.Literals(["web", "desktop-renderer", "mobile", "unknown"]); |
| 62 | export type ClientKind = typeof ClientKind.Type; |
| 63 | |
| 64 | export const ClientActivityClientId = TrimmedNonEmptyString.check(Schema.isMaxLength(128)); |
| 65 | export type ClientActivityClientId = typeof ClientActivityClientId.Type; |
| 66 | |
| 67 | export const ClientActivityReportInput = Schema.Struct({ |
| 68 | environmentId: Schema.optionalKey(EnvironmentId), |
| 69 | clientId: ClientActivityClientId, |
| 70 | clientKind: ClientKind, |
| 71 | visible: Schema.Boolean, |
| 72 | focused: Schema.Boolean, |
| 73 | recentlyInteracted: Schema.Boolean, |
| 74 | appState: Schema.optionalKey(Schema.Literals(["active", "inactive", "background", "unknown"])), |
| 75 | lowPowerMode: Schema.optionalKey(BackgroundBooleanState), |
| 76 | batteryState: Schema.optionalKey(Schema.Literals(["unknown", "unplugged", "charging", "full"])), |
| 77 | networkType: Schema.optionalKey(Schema.String), |
| 78 | scopes: Schema.Array(BackgroundScope), |
| 79 | ttlMs: Schema.optionalKey(Schema.Number), |
| 80 | observedAt: Schema.DateTimeUtc, |
| 81 | }); |
| 82 | export type ClientActivityReportInput = typeof ClientActivityReportInput.Type; |
| 83 | |
| 84 | export const ClientActivityLease = Schema.Struct({ |
| 85 | sessionId: AuthSessionId, |
| 86 | rpcClientId: RpcClientId, |
| 87 | clientId: ClientActivityClientId, |
| 88 | clientKind: ClientKind, |
| 89 | visible: Schema.Boolean, |
| 90 | focused: Schema.Boolean, |
| 91 | recentlyInteracted: Schema.Boolean, |
| 92 | appState: Schema.optionalKey(Schema.Literals(["active", "inactive", "background", "unknown"])), |
| 93 | lowPowerMode: Schema.optionalKey(BackgroundBooleanState), |
| 94 | batteryState: Schema.optionalKey(Schema.Literals(["unknown", "unplugged", "charging", "full"])), |
| 95 | networkType: Schema.optionalKey(Schema.String), |
| 96 | scopes: Schema.Array(BackgroundScope), |
| 97 | updatedAt: Schema.DateTimeUtc, |
| 98 | expiresAt: Schema.DateTimeUtc, |
| 99 | }); |
| 100 | export type ClientActivityLease = typeof ClientActivityLease.Type; |
| 101 | |
| 102 | export const BackgroundPolicySnapshot = Schema.Struct({ |
| 103 | hostPower: HostPowerSnapshot, |
| 104 | leases: Schema.Array(ClientActivityLease), |
| 105 | activeForegroundLeaseCount: Schema.Number, |
| 106 | activeScopeKeys: Schema.Array(Schema.String), |
| 107 | shouldRunOpportunisticWork: Schema.Boolean, |
| 108 | updatedAt: Schema.DateTimeUtc, |
| 109 | }); |
| 110 | export type BackgroundPolicySnapshot = typeof BackgroundPolicySnapshot.Type; |