Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 38 lines 1.49 KB
Raw
1 import { Effect, Option } from 'effect';
2 import { APP_VERSION } from 'src/constants';
3 import { installSkillSafe } from 'src/effects/install-skill';
4 import { UpgradeBinary } from 'src/services/upgrade-binary';
5
6 /** The flags and argument of `composio upgrade`. */
7 export type UpgradeParams = {
8 readonly beta: boolean;
9 readonly version: Option.Option<string>;
10 };
11
12 const RELEASE_TAG_PREFIX = '@composio/cli@';
13
14 /**
15 * The release tag a version argument names: a full `@composio/cli@…` tag as given, otherwise the
16 * version (a leading `v` allowed, e.g. `v0.13.1`) under the CLI's tag prefix.
17 */
18 export const normalizeReleaseTag = (input: string): string => {
19 const trimmed = input.trim();
20 if (trimmed.startsWith(RELEASE_TAG_PREFIX)) return trimmed;
21 const stripped = trimmed.replace(/^v/, '');
22 return `${RELEASE_TAG_PREFIX}${stripped}`;
23 };
24
25 /**
26 * Replaces the running binary with the requested release, or the latest one on the chosen
27 * channel, then installs the skill of whichever release is now installed: the new one, else the
28 * requested one, else the running version's.
29 */
30 export const runUpgrade = ({ beta, version }: UpgradeParams) =>
31 Effect.gen(function* () {
32 const upgradeBinary = yield* UpgradeBinary;
33 const tag = Option.getOrUndefined(Option.map(version, normalizeReleaseTag));
34 const newReleaseTag = yield* upgradeBinary.upgrade({ prerelease: beta, tag });
35 yield* installSkillSafe({
36 releaseTag: newReleaseTag ?? tag ?? `${RELEASE_TAG_PREFIX}${APP_VERSION}`,
37 });
38 });