The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | import * as Schema from "effect/Schema"; |
| 2 | |
| 3 | import { |
| 4 | ForwardCompatibleArray, |
| 5 | IsoDateTime, |
| 6 | NonNegativeInt, |
| 7 | TrimmedNonEmptyString, |
| 8 | } from "./baseSchemas.ts"; |
| 9 | import { ProviderDriverKind, ProviderInstanceId } from "./providerInstance.ts"; |
| 10 | import { UsageLimitSourceId } from "./usageLimitSourceId.ts"; |
| 11 | |
| 12 | /** Stable per-provider ids let sparse updates merge with full probes. */ |
| 13 | export const ServerProviderUsageWindow = Schema.Struct({ |
| 14 | id: TrimmedNonEmptyString, |
| 15 | kind: Schema.Literals(["session", "weekly", "monthly", "other"]), |
| 16 | label: TrimmedNonEmptyString, |
| 17 | /** When present, this limit applies only to these provider model IDs. */ |
| 18 | modelIds: Schema.optional(Schema.Array(TrimmedNonEmptyString)), |
| 19 | providerIds: Schema.optional(Schema.Array(TrimmedNonEmptyString)), |
| 20 | usedPercent: Schema.Number.check(Schema.isBetween({ minimum: 0, maximum: 100 })), |
| 21 | resetsAt: Schema.optional(IsoDateTime), |
| 22 | windowDurationMins: Schema.optional(NonNegativeInt), |
| 23 | }); |
| 24 | export type ServerProviderUsageWindow = typeof ServerProviderUsageWindow.Type; |
| 25 | |
| 26 | /** One kind of banked reset, such as Claude's weekly reset or its Fable-only reset. */ |
| 27 | export const ServerProviderResetCreditOption = Schema.Struct({ |
| 28 | creditId: TrimmedNonEmptyString, |
| 29 | label: TrimmedNonEmptyString, |
| 30 | description: TrimmedNonEmptyString, |
| 31 | availableCount: NonNegativeInt, |
| 32 | expiresAt: Schema.optional(IsoDateTime), |
| 33 | }); |
| 34 | export type ServerProviderResetCreditOption = typeof ServerProviderResetCreditOption.Type; |
| 35 | |
| 36 | export const ServerProviderResetCredits = Schema.Struct({ |
| 37 | availableCount: NonNegativeInt, |
| 38 | nextExpiresAt: Schema.optional(IsoDateTime), |
| 39 | /** Pins hub redemption to the displayed credit, including retries from another client. */ |
| 40 | nextCreditId: Schema.optional(TrimmedNonEmptyString), |
| 41 | /** Present when resets differ in what they refill; redeem one by its `creditId`. */ |
| 42 | options: Schema.optional(ForwardCompatibleArray(ServerProviderResetCreditOption)), |
| 43 | }); |
| 44 | export type ServerProviderResetCredits = typeof ServerProviderResetCredits.Type; |
| 45 | |
| 46 | /** Clear bars for unavailable accounts; retain last good bars after a failed probe. */ |
| 47 | export const ServerProviderUsageLimits = Schema.Struct({ |
| 48 | checkedAt: IsoDateTime, |
| 49 | windows: ForwardCompatibleArray(ServerProviderUsageWindow), |
| 50 | /** A $0 monthly spend cap has no percentage, so it cannot be a window. */ |
| 51 | zeroSpendCap: Schema.optional(Schema.Boolean), |
| 52 | credentialFingerprint: Schema.optional(TrimmedNonEmptyString), |
| 53 | resetCredits: Schema.optional(ServerProviderResetCredits), |
| 54 | externalUsage: Schema.optional( |
| 55 | Schema.Struct({ |
| 56 | label: TrimmedNonEmptyString, |
| 57 | url: TrimmedNonEmptyString, |
| 58 | }), |
| 59 | ), |
| 60 | unavailable: Schema.optional( |
| 61 | Schema.Struct({ |
| 62 | reason: Schema.Literals(["unsupported", "probeFailed"]), |
| 63 | message: Schema.optional(TrimmedNonEmptyString), |
| 64 | }), |
| 65 | ), |
| 66 | }); |
| 67 | export type ServerProviderUsageLimits = typeof ServerProviderUsageLimits.Type; |
| 68 | |
| 69 | /** Partial updates merge windows by id; omitted windows remain unchanged. */ |
| 70 | export const ProviderUsageLimitsUpdate = Schema.Struct({ |
| 71 | windows: Schema.Array(ServerProviderUsageWindow), |
| 72 | }); |
| 73 | export type ProviderUsageLimitsUpdate = typeof ProviderUsageLimitsUpdate.Type; |
| 74 | |
| 75 | export const UsageLimitSourceAccount = Schema.Struct({ |
| 76 | id: TrimmedNonEmptyString, |
| 77 | driver: ProviderDriverKind, |
| 78 | email: Schema.optional(TrimmedNonEmptyString), |
| 79 | plan: Schema.optional(TrimmedNonEmptyString), |
| 80 | workspaceId: Schema.optional(TrimmedNonEmptyString), |
| 81 | /** The models the hub routes to this account. */ |
| 82 | models: Schema.optional(Schema.Array(TrimmedNonEmptyString)), |
| 83 | usageLimits: ServerProviderUsageLimits, |
| 84 | }); |
| 85 | export type UsageLimitSourceAccount = typeof UsageLimitSourceAccount.Type; |
| 86 | |
| 87 | export const UsageLimitSourceSnapshot = Schema.Struct({ |
| 88 | id: UsageLimitSourceId, |
| 89 | kind: Schema.Literal("cliproxy"), |
| 90 | label: TrimmedNonEmptyString, |
| 91 | /** Origin of the hub, which also serves the agents sent through it. */ |
| 92 | origin: Schema.optional(TrimmedNonEmptyString), |
| 93 | /** Origin and base path of the hub, which tell apart hubs served from one origin. */ |
| 94 | endpoint: Schema.optional(TrimmedNonEmptyString), |
| 95 | checkedAt: IsoDateTime, |
| 96 | accounts: ForwardCompatibleArray(UsageLimitSourceAccount), |
| 97 | error: Schema.optional(TrimmedNonEmptyString), |
| 98 | }); |
| 99 | export type UsageLimitSourceSnapshot = typeof UsageLimitSourceSnapshot.Type; |
| 100 | |
| 101 | export const UsageLimitSourceSnapshots = ForwardCompatibleArray(UsageLimitSourceSnapshot); |
| 102 | export type UsageLimitSourceSnapshots = typeof UsageLimitSourceSnapshots.Type; |
| 103 | |
| 104 | export const UsageLimitSourceConsumeResetCreditInput = Schema.Struct({ |
| 105 | sourceId: UsageLimitSourceId, |
| 106 | accountId: TrimmedNonEmptyString, |
| 107 | creditId: TrimmedNonEmptyString, |
| 108 | }); |
| 109 | export type UsageLimitSourceConsumeResetCreditInput = |
| 110 | typeof UsageLimitSourceConsumeResetCreditInput.Type; |
| 111 | |
| 112 | export const ProviderConsumeResetCreditInput = Schema.Union([ |
| 113 | Schema.Struct({ |
| 114 | instanceId: ProviderInstanceId, |
| 115 | creditId: Schema.optional(TrimmedNonEmptyString), |
| 116 | }), |
| 117 | UsageLimitSourceConsumeResetCreditInput, |
| 118 | ]); |
| 119 | export type ProviderConsumeResetCreditInput = typeof ProviderConsumeResetCreditInput.Type; |
| 120 | |
| 121 | export class UsageLimitSourceError extends Schema.TaggedError<UsageLimitSourceError>()( |
| 122 | "UsageLimitSourceError", |
| 123 | { detail: Schema.String }, |
| 124 | ) { |
| 125 | override get message(): string { |
| 126 | return this.detail; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | export const ProviderConsumeResetCreditOutcome = Schema.Literals([ |
| 131 | "reset", |
| 132 | "nothingToReset", |
| 133 | "noCredit", |
| 134 | "alreadyRedeemed", |
| 135 | ]); |
| 136 | export type ProviderConsumeResetCreditOutcome = typeof ProviderConsumeResetCreditOutcome.Type; |
| 137 | |
| 138 | export const ProviderConsumeResetCreditResult = Schema.Struct({ |
| 139 | outcome: ProviderConsumeResetCreditOutcome, |
| 140 | warning: Schema.optional(TrimmedNonEmptyString), |
| 141 | }); |
| 142 | export type ProviderConsumeResetCreditResult = typeof ProviderConsumeResetCreditResult.Type; |
| 143 | |
| 144 | export const UsageLimitsReport = Schema.Struct({ |
| 145 | createdAt: IsoDateTime, |
| 146 | accounts: Schema.Array( |
| 147 | Schema.Struct({ |
| 148 | id: TrimmedNonEmptyString, |
| 149 | driver: ProviderDriverKind, |
| 150 | label: TrimmedNonEmptyString, |
| 151 | plan: Schema.optional(TrimmedNonEmptyString), |
| 152 | email: Schema.optional(TrimmedNonEmptyString), |
| 153 | sourceLabel: Schema.optional(TrimmedNonEmptyString), |
| 154 | instanceId: Schema.optional(ProviderInstanceId), |
| 155 | resetCreditInput: Schema.optional(ProviderConsumeResetCreditInput), |
| 156 | displayName: Schema.optional(Schema.String), |
| 157 | accentColor: Schema.optional(Schema.String), |
| 158 | limits: ServerProviderUsageLimits, |
| 159 | }), |
| 160 | ), |
| 161 | notices: Schema.Array(Schema.String), |
| 162 | }); |
| 163 | export type UsageLimitsReport = typeof UsageLimitsReport.Type; |