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 49 lines 1.64 KB
Raw
1 import { Effect, Match, Data } from 'effect';
2 import { NodeOs } from '../services/node-os';
3
4 /**
5 * Platform and architecture detection types
6 */
7 export type PlatformArch = {
8 platform: 'darwin' | 'linux' | 'windows';
9 arch: 'x64' | 'aarch64';
10 };
11
12 export class UnsupportedPlatformError extends Data.TaggedError('UnsupportedPlatformError')<{
13 readonly platform: string;
14 readonly arch: string;
15 }> {}
16
17 /**
18 * Detect current platform and architecture
19 */
20 export const detectPlatform: Effect.Effect<PlatformArch, UnsupportedPlatformError, NodeOs> =
21 Effect.gen(function* () {
22 const nodeOs = yield* NodeOs;
23 const rawPlatform = nodeOs.platform;
24 const rawArch: string = nodeOs.arch;
25
26 const platform: PlatformArch['platform'] = yield* Match.value(rawPlatform).pipe(
27 Match.when('darwin', () => Effect.succeed('darwin' as const)),
28 Match.when('linux', () => Effect.succeed('linux' as const)),
29 Match.when('win32', () =>
30 rawArch === 'x64'
31 ? Effect.succeed('windows' as const)
32 : Effect.fail(new UnsupportedPlatformError({ platform: rawPlatform, arch: rawArch }))
33 ),
34 Match.orElse(() =>
35 Effect.fail(new UnsupportedPlatformError({ platform: rawPlatform, arch: rawArch }))
36 )
37 );
38
39 const arch = yield* Match.value(rawArch).pipe(
40 Match.when('x64', () => Effect.succeed('x64' as const)),
41 Match.when('arm64', () => Effect.succeed('aarch64' as const)),
42 Match.when('aarch64', () => Effect.succeed('aarch64' as const)),
43 Match.orElse(() =>
44 Effect.fail(new UnsupportedPlatformError({ platform: rawPlatform, arch: rawArch }))
45 )
46 );
47
48 return { platform, arch };
49 });