Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

1.4 KB
Raw Blame
import type { PullRequestProvider } from 'librechat-data-provider';
import type { PullRequestFetch } from './shared';
import type { PullRequestSource } from './types';
import { createBitbucketPullRequestSource } from './bitbucket';
import { createGitHubPullRequestSource } from './github';
import { createGitLabPullRequestSource } from './gitlab';
import { PullRequestSourceError } from './types';

/**
 * One source per provider behind the single interface the lookup uses, so the lookup and its cache
 * stay unaware of providers. A provider this server has no source for cannot be served, which is
 * reported as not configured rather than answered as "no pull request".
 */
export function routePullRequestSources(
  sources: Partial<Record<PullRequestProvider, PullRequestSource>>,
): PullRequestSource {
  return {
    find(input) {
      const source = sources[input.provider ?? 'github'];
      if (source == null) return Promise.reject(new PullRequestSourceError('NOT_CONFIGURED'));
      return source.find(input);
    },
  };
}

/** Every provider this server can look up, all through the deployment's HTTP client. */
export function createPullRequestSource({
  fetchFn,
}: {
  fetchFn: PullRequestFetch;
}): PullRequestSource {
  return routePullRequestSources({
    github: createGitHubPullRequestSource({ fetchFn }),
    gitlab: createGitLabPullRequestSource({ fetchFn }),
    bitbucket: createBitbucketPullRequestSource({ fetchFn }),
  });
}