(options: CreateAIRuntimeOptions = {})
| 21 | } |
| 22 | |
| 23 | export async function createAIRuntime(options: CreateAIRuntimeOptions = {}): Promise<AIRuntime> { |
| 24 | const cwd = options.cwd ?? process.cwd(); |
| 25 | const registry = new ProviderRegistry(); |
| 26 | const sessionManager = new SessionManager(); |
| 27 | const modelDiscovery: Promise<void>[] = []; |
| 28 | |
| 29 | try { |
| 30 | await import("@plannotator/ai/providers/claude-agent-sdk"); |
| 31 | const claudePath = Bun.which("claude"); |
| 32 | const provider = await createProvider({ |
| 33 | type: "claude-agent-sdk", |
| 34 | cwd, |
| 35 | ...(claudePath && { claudeExecutablePath: claudePath }), |
| 36 | }); |
| 37 | registry.register(provider); |
| 38 | } catch { |
| 39 | // Claude SDK not available. |
| 40 | } |
| 41 | |
| 42 | try { |
| 43 | await import("@plannotator/ai/providers/codex-app-server"); |
| 44 | const codexPath = Bun.which("codex"); |
| 45 | if (codexPath) { |
| 46 | const provider = await createProvider({ |
| 47 | type: "codex-sdk", |
| 48 | cwd, |
| 49 | ...(codexPath ? { codexExecutablePath: codexPath } : {}), |
| 50 | }); |
| 51 | registry.register(provider); |
| 52 | if ("fetchModels" in provider) { |
| 53 | modelDiscovery.push( |
| 54 | (provider as { fetchModels: () => Promise<void> }).fetchModels().catch(() => {}), |
| 55 | ); |
| 56 | } |
| 57 | } |
| 58 | } catch { |
| 59 | // Codex not available. |
| 60 | } |
| 61 | |
| 62 | try { |
| 63 | const { PiSDKProvider } = await import("@plannotator/ai/providers/pi-sdk"); |
| 64 | const rawPiPath = Bun.which("pi"); |
| 65 | if (rawPiPath) { |
| 66 | const piPath = resolveWindowsCommandShim(rawPiPath); |
| 67 | const provider = await createProvider({ |
| 68 | type: "pi-sdk", |
| 69 | cwd, |
| 70 | piExecutablePath: piPath, |
| 71 | } as PiSDKConfig); |
| 72 | if (provider instanceof PiSDKProvider) { |
| 73 | modelDiscovery.push(provider.fetchModels().catch(() => {})); |
| 74 | } |
| 75 | registry.register(provider); |
| 76 | } |
| 77 | } catch { |
| 78 | // Pi not available. |
| 79 | } |
| 80 |
no test coverage detected