index.ts
1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { createLaunchAgent, launchAgentInstruction, type LaunchAgentResult } from '../../../agents/launch-agent';
export interface LaunchConfig {
/**
* Skip dependency installation (pnpm i).
* Set to true for iterations 2+ where dependencies haven't changed.
*/
skipDependencyInstall?: boolean;
}
export interface LaunchResult {
success: boolean;
message?: string;
error?: string;
// Server metadata from LaunchTool
serverKey?: string;
url?: string;
port?: number;
}
export const launch = async (appPath: string, config?: LaunchConfig): Promise<LaunchResult> => {
if (!appPath) {
throw new Error('appPath is required');
}
try {
// Agent.run() returns the parsed LaunchAgentResult via postProcessor
const agentResult = (await createLaunchAgent().run(
launchAgentInstruction({
appPath,
skipDependencyInstall: config?.skipDependencyInstall,
})
)) as LaunchAgentResult;
// If agent explicitly failed, return the error
if (agentResult.success === false) {
return {
success: false,
error: agentResult.error ?? 'Launch agent failed without error message',
};
}
// postProcessor already validates serverKey, url, port are present when success=true
// So we can safely return them here
return {
success: true,
message: agentResult.message ?? 'Launch and quality assurance completed',
serverKey: agentResult.serverKey,
url: agentResult.url,
port: agentResult.port,
};
} catch (error) {
return {
success: false,
error: error instanceof Error ? error.message : String(error),
};
}
};