| 58 | } |
| 59 | |
| 60 | export function createCodexBridgeRuntime({ |
| 61 | platformPlugins = [], |
| 62 | providerPlugins = [], |
| 63 | providerProfiles = [], |
| 64 | defaultProviderProfileId = null, |
| 65 | defaultCwd = null, |
| 66 | locale = null, |
| 67 | repositories = {}, |
| 68 | assistantAttachmentRoot = null, |
| 69 | restartBridge = null, |
| 70 | codexAuthManager = null, |
| 71 | codexInstructionsManager = null, |
| 72 | codexExperimentalFeaturesManager = null, |
| 73 | codexGoalManager = null, |
| 74 | codexNativeSideTaskRouter = null, |
| 75 | weiboHotSearch = null, |
| 76 | }: CreateCodexBridgeRuntimeOptions = {}) { |
| 77 | const registry = new PluginRegistry({ |
| 78 | locale, |
| 79 | }); |
| 80 | for (const platformPlugin of platformPlugins) { |
| 81 | registry.registerPlatform(platformPlugin); |
| 82 | } |
| 83 | for (const providerPlugin of providerPlugins) { |
| 84 | registry.registerProvider(providerPlugin); |
| 85 | } |
| 86 | |
| 87 | const providerProfilesRepository = repositories.providerProfiles ?? new InMemoryProviderProfileRepository(); |
| 88 | const bridgeSessionsRepository = repositories.bridgeSessions ?? new InMemoryBridgeSessionRepository(); |
| 89 | const platformBindingsRepository = repositories.platformBindings ?? new InMemoryPlatformBindingRepository(); |
| 90 | const pluginAliasesRepository = repositories.pluginAliases ?? new InMemoryPluginAliasRepository(); |
| 91 | const sessionSettingsRepository = repositories.sessionSettings ?? new InMemorySessionSettingsRepository(); |
| 92 | const threadMetadataRepository = repositories.threadMetadata ?? new InMemoryThreadMetadataRepository(); |
| 93 | const automationJobsRepository = repositories.automationJobs ?? new InMemoryAutomationJobRepository(); |
| 94 | const agentJobsRepository = repositories.agentJobs ?? new InMemoryAgentJobRepository(); |
| 95 | const assistantRecordsRepository = repositories.assistantRecords ?? new InMemoryAssistantRecordRepository(); |
| 96 | const missionControlRepository = repositories.missionControl ?? new InMemoryMissionRepository(); |
| 97 | |
| 98 | if (providerProfiles.length > 0) { |
| 99 | const configuredProviderProfileIds = new Set(providerProfiles.map((profile) => profile.id)); |
| 100 | for (const existingProviderProfile of providerProfilesRepository.list()) { |
| 101 | if (!configuredProviderProfileIds.has(existingProviderProfile.id)) { |
| 102 | providerProfilesRepository.delete(existingProviderProfile.id); |
| 103 | } |
| 104 | } |
| 105 | for (const providerProfile of providerProfiles) { |
| 106 | providerProfilesRepository.save(providerProfile); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | const sessionRouter = new SessionRouter({ |
| 111 | platformBindings: platformBindingsRepository, |
| 112 | bridgeSessions: bridgeSessionsRepository, |
| 113 | locale, |
| 114 | }); |
| 115 | |
| 116 | const bridgeSessions = new BridgeSessionService({ |
| 117 | providerProfiles: providerProfilesRepository, |