-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathindex.ts
More file actions
70 lines (66 loc) · 2.21 KB
/
Copy pathindex.ts
File metadata and controls
70 lines (66 loc) · 2.21 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
66
67
68
69
70
import type { BotConfigBase } from '../config.js';
import type { Logger } from '../utils/logger.js';
import type { Engine, EngineName } from './types.js';
import { ClaudeEngine } from './claude/index.js';
import { KimiEngine } from './kimi/index.js';
import { CodexEngine } from './codex/index.js';
import { OpenCodeEngine } from './opencode/index.js';
/**
* Create an Engine for the given bot config.
*
* Engine selection:
* 1. `config.engine` field (explicit)
* 2. `METABOT_ENGINE` env var (global default)
* 3. `'claude'` (fallback)
*/
export function createEngine(
config: BotConfigBase,
logger: Logger,
override?: EngineName,
): Engine {
const name = override ?? resolveEngineName(config);
switch (name) {
case 'claude':
return new ClaudeEngine(config, logger);
case 'kimi':
return new KimiEngine(config, logger);
case 'codex':
return new CodexEngine(config, logger);
case 'opencode':
return new OpenCodeEngine(config, logger);
default: {
const _exhaustive: never = name;
throw new Error(`Unknown engine: ${_exhaustive}`);
}
}
}
/** Resolve the default engine for a bot config (no session override). */
export function resolveEngineName(config: BotConfigBase): EngineName {
const explicit = config.engine;
if (explicit) return explicit;
const envDefault = process.env.METABOT_ENGINE as EngineName | undefined;
if (envDefault === 'claude' || envDefault === 'kimi' || envDefault === 'codex' || envDefault === 'opencode') return envDefault;
return 'claude';
}
export type { Engine, EngineName, Executor } from './types.js';
export { ClaudeEngine } from './claude/index.js';
export { KimiEngine } from './kimi/index.js';
export { CodexEngine } from './codex/index.js';
export { OpenCodeEngine } from './opencode/index.js';
// Re-export shared types and classes currently used by the bridge and web/api layers.
// Moving these behind the engine boundary lets consumers import from a single place.
export {
ClaudeExecutor,
StreamProcessor,
SessionManager,
extractImagePaths,
} from './claude/index.js';
export type {
UserSession,
SDKMessage,
ExecutionHandle,
ExecutorOptions,
ApiContext,
DetectedTool,
TeamEvent,
} from './claude/index.js';