Repository navigation
Expand file tree
/
Copy pathfactory.ts
More file actions
65 lines (59 loc) · 1.83 KB
/
Copy pathfactory.ts
File metadata and controls
65 lines (59 loc) · 1.83 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
59
60
61
62
63
64
65
/**
* CLI Factory
*
* Factory pattern to create CLI adapters.
* Makes it easy to swap between amp, Cursor, and other CLIs in the future.
*/
import { CLIAdapter } from './base';
import { AmpAdapter } from './amp';
import { MockCLIAdapter } from './mock';
import { CursorAdapter } from './cursor';
export type CLIProvider = 'amp' | 'mock' | 'cursor';
export class CLIFactory {
/**
* Create a CLI adapter instance based on the provider type
*/
static create(provider: CLIProvider): CLIAdapter {
switch (provider) {
case 'amp':
return new AmpAdapter();
case 'mock':
return new MockCLIAdapter();
case 'cursor':
return new CursorAdapter();
default:
throw new Error(`Unknown CLI provider: ${provider}`);
}
}
/**
* Get available providers (order: Cursor first, Amp second, Mock last)
*/
static getAvailableProviders(): CLIProvider[] {
return ['cursor', 'amp', 'mock'];
}
/**
* Check if a provider is available
*
* Note: Returns true if provider is recognized, actual availability
* (CLI installed, authenticated) is checked via preflight during execution
*/
static isProviderAvailable(provider: string): provider is CLIProvider {
// All known providers are considered "available"
// Actual runtime checks (binary exists, auth OK) happen in preflight
return ['amp', 'mock', 'cursor'].includes(provider as CLIProvider);
}
/**
* Get available adapters with their metadata
* Used for displaying CLI options in UI
*/
static getAvailableAdapters(): Array<{ name: string; displayName: string }> {
const providers = this.getAvailableProviders();
return providers.map((provider) => {
const adapter = this.create(provider);
return {
name: adapter.name,
displayName: adapter.displayName,
};
});
}
}