Skip to content

Commit f83095f

Browse files
ENG-36 Support Intel build for mac, not just Apple Silicon (#1710)
* fix(portal): download relevant device agent per macOS chip on portal * fix(portal): fix portal build issue * fix(portal): add log for testing * fix(portal): add log for testing --------- Co-authored-by: chasprowebdev <chasgarciaprowebdev@gmail.com>
1 parent 221069b commit f83095f

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

apps/portal/src/app/api/download-agent/route.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
getReadmeContent,
1212
getScriptFilename,
1313
} from './scripts';
14+
import type { SupportedOS } from './types';
1415

1516
export const runtime = 'nodejs';
1617
export const dynamic = 'force-dynamic';
@@ -39,9 +40,10 @@ export async function GET(req: NextRequest) {
3940
orgId: string;
4041
employeeId: string;
4142
userId: string;
42-
os: 'macos' | 'windows';
43+
os: SupportedOS;
4344
};
44-
45+
console.log(os);
46+
4547
// Hardcoded device marker paths used by the setup scripts
4648
const fleetDevicePathMac = '/Users/Shared/.fleet';
4749
const fleetDevicePathWindows = 'C:\\ProgramData\\CompAI\\Fleet';
@@ -52,10 +54,10 @@ export async function GET(req: NextRequest) {
5254
}
5355

5456
// For macOS, serve the DMG directly. For Windows, create a zip with script and installer.
55-
if (os === 'macos') {
57+
if (os === 'macos' || os === 'macos-intel') {
5658
try {
5759
// Direct DMG download for macOS
58-
const macosPackageFilename = 'Comp AI Agent-1.0.0-arm64.dmg';
60+
const macosPackageFilename = os === 'macos' ? 'Comp AI Agent-1.0.0-arm64.dmg' : 'Comp AI Agent-1.0.0.dmg';
5961
const packageKey = `macos/${macosPackageFilename}`;
6062

6163
const getObjectCommand = new GetObjectCommand({

apps/portal/src/app/api/download-agent/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type SupportedOS = 'macos' | 'windows';
1+
export type SupportedOS = 'macos' | 'windows' | 'macos-intel';
22

33
export interface ScriptConfig {
44
orgId: string;

apps/portal/src/app/api/download-agent/utils.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@ import { db } from '@db';
33
import type { SupportedOS } from './types';
44

55
/**
6-
* Detects the operating system from a User-Agent string
6+
* Detects the operating system (and for macOS, the CPU architecture) from a User-Agent string.
7+
*
8+
* Returns:
9+
* - 'windows' for Windows OS
10+
* - 'macos' for Apple Silicon (ARM-based) Macs
11+
* - 'macos-intel' for Intel-based Macs
712
*
813
* Examples of User-Agent strings:
914
* - Windows: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
10-
* - macOS: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36"
15+
* - macOS (Intel): "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36"
16+
* - macOS (Apple Silicon): "Mozilla/5.0 (Macintosh; ARM Mac OS X 11_2_3) AppleWebKit/537.36"
1117
*/
1218
export function detectOSFromUserAgent(userAgent: string | null): SupportedOS | null {
1319
if (!userAgent) return null;
@@ -19,8 +25,17 @@ export function detectOSFromUserAgent(userAgent: string | null): SupportedOS | n
1925
return 'windows';
2026
}
2127

22-
// Check for macOS (must check before iOS since iOS UA contains "mac")
28+
// Check for macOS (and further distinguish Apple Silicon vs Intel)
2329
if (ua.includes('macintosh') || (ua.includes('mac os') && !ua.includes('like mac'))) {
30+
// User-Agent containing 'arm' or 'apple' usually means Apple Silicon
31+
if (ua.includes('arm') || ua.includes('apple')) {
32+
return 'macos';
33+
}
34+
// 'intel' in UA indicates Intel-based mac
35+
if (ua.includes('intel')) {
36+
return 'macos-intel';
37+
}
38+
// Fallback for when arch info is missing, treat as Apple Silicon (modern default)
2439
return 'macos';
2540
}
2641

apps/portal/src/utils/s3.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { SupportedOS } from '@/app/api/download-agent/types';
12
import { GetObjectCommand, PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
23
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
34

@@ -113,7 +114,7 @@ export function extractS3KeyFromUrl(url: string): string {
113114
return key;
114115
}
115116

116-
export async function getFleetAgent({ os }: { os: 'macos' | 'windows' }) {
117+
export async function getFleetAgent({ os }: { os: SupportedOS }) {
117118
const fleetBucketName = process.env.FLEET_AGENT_BUCKET_NAME;
118119

119120
if (!fleetBucketName) {

0 commit comments

Comments
 (0)