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, 04:45 UTC
| 1 | import { |
| 2 | managedNightlyDeniedMessage, |
| 3 | managedUpdatesMessage, |
| 4 | type ManagedPolicyDocument, |
| 5 | } from "@t3tools/contracts"; |
| 6 | import type { CliReleaseChannel } from "@t3tools/shared/cliRelease"; |
| 7 | |
| 8 | /** |
| 9 | * The update mirror the policy sends updates to, or `undefined` for the public releases. It wins |
| 10 | * over the environment, which a user can set. |
| 11 | */ |
| 12 | export function managedUpdateMirror(document: ManagedPolicyDocument | undefined) { |
| 13 | const feedUrl = document?.limits?.updates?.feedUrl; |
| 14 | return feedUrl === undefined || document === undefined |
| 15 | ? undefined |
| 16 | : { organization: document.organization, feedUrl }; |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Why the managed policy refuses an update a user or maintainer asked for, or `undefined` when it |
| 21 | * allows it. The server never updates on its own, so `auto` allows every explicit request. |
| 22 | * Pass `targetChannel` when the caller picks the release; the desktop app gates its own channel. |
| 23 | */ |
| 24 | export function managedUpdateRefusal( |
| 25 | document: ManagedPolicyDocument | undefined, |
| 26 | targetChannel?: CliReleaseChannel, |
| 27 | ): string | undefined { |
| 28 | const updates = document?.limits?.updates; |
| 29 | if (document === undefined || updates === undefined) return undefined; |
| 30 | if (updates.mode === "off") return managedUpdatesMessage(document.organization); |
| 31 | if (updates.allowNightly === false && targetChannel !== undefined && targetChannel !== "stable") { |
| 32 | return managedNightlyDeniedMessage(document.organization); |
| 33 | } |
| 34 | return undefined; |
| 35 | } |